Skip to content

fix: the Call Hierarchy computes a method's callers and callees again when a write action cancels their request, instead of showing none - #2279

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/call-hierarchy-rethrows-cancellation
Nov 26, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/call-hierarchy-rethrows-cancellation

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

The Call Hierarchy could show a method with no callers or no callees when IntelliJ ran a write action while LSP4IJ waited for textDocument/prepareCallHierarchy, callHierarchy/incomingCalls or callHierarchy/outgoingCalls. Typing, a save, a VFS refresh or IntelliJ's registry update could do it. The node stayed empty until Refresh.

Cause

IntelliJ's hierarchy tree computes a node's children in a read action that a write action cancels. It computes them again only if the computation ends with the ProcessCanceledException: HierarchyTreeStructure.getChildElements keeps whatever buildChildren returns. The three call hierarchy tree structures caught the ProcessCanceledException from awaitWithCheckCanceled, cancelled the LSP request, and went on to fillChildren with no answer. So the node kept no children.

Fix

In LSPCallHierarchyIncomingCallsTreeStructure, LSPCallHierarchyOutgoingCallsTreeStructure and LSPCallHierarchyTreeStructureBase, the catch (ProcessCanceledException) still cancels the request ($/cancelRequest), and then rethrows the exception, as the type hierarchy already does. IntelliJ then computes the children again with a new request. The CancellationException handling, for a request that LSP4IJ itself cancelled, is unchanged.

Behaviour changes

Change Commit Who sees it
The Call Hierarchy computes a method's callers, callees and prepared item again when a write action cancels their request, instead of showing none until Refresh fix: the Call Hierarchy computes a method's callers and callees again when a write action cancels their request, instead of showing none Every user of the Call Hierarchy with a language server that takes long enough to answer for a write action to come in between

Tests

CallHierarchyWriteActionTest reproduces it deterministically. The mock language server holds its answer to prepareCallHierarchy, incomingCalls and outgoingCalls until the test completes it. The test computes a node's children as the hierarchy tree does: once, on a pooled thread, in runInReadActionWithWriteActionPriority. It runs a write action while the request is pending, then asserts that:

  • the computation ends with a ProcessCanceledException;
  • the node keeps no cached children;
  • the language server got $/cancelRequest (LSP4J cancelled its pending request);
  • once the language server answers, computing the children again gives the callers, the callees or the prepared item.

Without the fix, all three tests fail with "ended normally with 0 children".

All waits are bounded futures or events, with no fixed sleeps. Headless, com.redhat.devtools.lsp4ij.features.callHierarchy.* passes on 2024.2, 2025.3 and IU 2026.3 (5 tests, 0 failures, 0 errors, 0 skipped on each).

Fixes #2278

… when a write action cancels their request, instead of showing none

IntelliJ's hierarchy tree computes the children of a node in a read action
that a write action cancels, and computes them again only when the
computation ends with the ProcessCanceledException. The call hierarchy tree
structures caught it while they waited for textDocument/prepareCallHierarchy,
callHierarchy/incomingCalls or callHierarchy/outgoingCalls, cancelled the
request and returned no children, which HierarchyTreeStructure keeps: any
write action during the wait, such as typing, a save or a VFS refresh, left
the node empty until Refresh.

They now rethrow it after cancelling the request, as the type hierarchy does,
so IntelliJ computes the children again with a new request.

Fixes redhat-developer#2278
@lagergren lagergren added this to the 0.30.2 milestone Nov 26, 2026
@lagergren lagergren added the bug Something isn't working label Nov 26, 2026
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Call hierarchy computations now stop promptly when canceled, instead of continuing with incomplete results. Pending requests are canceled, and caller, callee, and prepared-item results can be recomputed after an interruption.
  • Tests
    • Added coverage confirming that canceled computations do not retain incomplete results and that the affected call hierarchy items are correctly recomputed when a response becomes available.

Call hierarchy tree structures now rethrow ProcessCanceledException after cancelling pending requests. New tests check cancellation and recomputation for prepared items, callers, and callees.

Changes: Call hierarchy cancellation

Layer / File(s) Summary
Propagate cancellation from tree computations
src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyTreeStructureBase.java, src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyIncomingCallsTreeStructure.java, src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyOutgoingCallsTreeStructure.java
The three tree structures rethrow ProcessCanceledException after cancelling pending requests.
Test cancellation and recomputation
src/test/java/com/redhat/devtools/lsp4ij/features/callHierarchy/CallHierarchyWriteActionTest.java
Tests check that write-action cancellation leaves no cached children, cancels the pending request, and allows prepared items, callers, and callees to be computed after the server response arrives.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 2fa2c

This change makes Call Hierarchy retry its computation after a write action interrupts a pending request, instead of leaving the node empty until Refresh. The change is narrow, and the added tests cover the retry scenario. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Call Hierarchy recomputes callers and callees after a write action cancels their request, instead of showing none. The raw summary covers only the three rethrow edits …
Description check Passed The description explains the cause (IntelliJ hierarchy tree computes children in a read action that a write action cancels), the fix (cancel the LSP request, then rethrow ProcessCanceledException in t…
Linked Issues check Passed Issue #2278 requires that each of the three call hierarchy tree structures keep the LSP cancel and rethrow ProcessCanceledException, so IntelliJ recomputes the node's children. The previous review con…
Out of Scope Changes check Passed The production changes are limited to the three call hierarchy tree structures named in #2278. Each change adds only a rethrow after the existing cancel. The new test class CallHierarchyWriteActionTes…
Full details: Title check

Explanation

The title names the main change: Call Hierarchy recomputes callers and callees after a write action cancels their request, instead of showing none. The raw summary covers only the three rethrow edits and the test, and the objectives match the title. The title is long (136 characters), but it stays accurate.

Full details: Description check

Explanation

The description explains the cause (IntelliJ hierarchy tree computes children in a read action that a write action cancels), the fix (cancel the LSP request, then rethrow ProcessCanceledException in the three tree structures), the tests, and the linked issue #2278. It matches the changeset.

Full details: Linked Issues check

Explanation

Issue #2278 requires that each of the three call hierarchy tree structures keep the LSP cancel and rethrow ProcessCanceledException, so IntelliJ recomputes the node's children. The previous review confirmed this for LSPCallHierarchyIncomingCallsTreeStructure.buildChildren: the catch block calls cancel() and then rethrows, and fillChildren is not reached. The PR summary and the AI-generated change summary report the same rethrow for LSPCallHierarchyOutgoingCallsTreeStructure.buildChildren and LSPCallHierarchyTreeStructureBase.buildRoot. The CancellationException branches are unchanged, as the issue allows. The changes since the previous review (commit 2fa2c40) add a watchdog to CallHierarchyWriteActionTest. That change is test-only and does not alter the production conformance. CallHierarchyWriteActionTest covers the held-response reproduction from the issue for prepared items, callers, and callees. Limitation: the diff tool could not read the changed blobs in this checkout, so the two non-incoming production files rest on the PR summary. Test results were not independently run.

Full details: Out of Scope Changes check

Explanation

The production changes are limited to the three call hierarchy tree structures named in #2278. Each change adds only a rethrow after the existing cancel. The new test class CallHierarchyWriteActionTest exercises those code paths. The incremental change since the previous review is a test watchdog that bounds the held-response wait, which supports the test and does not add unrelated behavior. Limitation: the diff tool could not read the changed blobs in this checkout, so this verdict rests on the file list and the PR summary.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17d6ce4d-42d8-4cf5-9bd2-f8e5cd66f9b4
Commits

Reviewing files that changed from the base of the PR and between 150fe2d and 2fa2c40.

Files selected for processing: 1

  • src/test/java/com/redhat/devtools/lsp4ij/features/callHierarchy/CallHierarchyWriteActionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

src/test/java/com/redhat/devtools/lsp4ij/features/callHierarchy/CallHierarchyWriteActionTest.java-158-159: 1

158-159: Major · Stability & Availability · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Bound the write action in the cancellation test.

If the worker stops checking for cancellation while it waits for the held LSP response, WriteAction.run waits for the worker to release its read lock. The test cannot reach the timeout at Line 161 or release the response at Line 170. This can hang the test run instead of reporting the regression.

Start a watchdog on a separate thread before entering the write action. If the deadline expires, have it release the held response so the worker can exit, and fail the test explicitly. On the successful path, keep the response held until the cancellation assertions pass.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1bf189c-abaf-4638-913e-82f4be648eef
Commits

Reviewing files that changed from the base of the PR and between 5e4c130 and 150fe2d.

Files selected for processing: 4

  • src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyIncomingCallsTreeStructure.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyOutgoingCallsTreeStructure.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/callHierarchy/LSPCallHierarchyTreeStructureBase.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/callHierarchy/CallHierarchyWriteActionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.40%. Comparing base (5e4c130) to head (2fa2c40).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...hy/LSPCallHierarchyIncomingCallsTreeStructure.java 0.00% 1 Missing ⚠️
...hy/LSPCallHierarchyOutgoingCallsTreeStructure.java 0.00% 1 Missing ⚠️
...llHierarchy/LSPCallHierarchyTreeStructureBase.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2279      +/-   ##
==========================================
+ Coverage   58.10%   58.40%   +0.30%     
==========================================
  Files         846      846              
  Lines       36426    36429       +3     
  Branches     5714     7537    +1823     
==========================================
+ Hits        21164    21276     +112     
+ Misses      12275    12150     -125     
- Partials     2987     3003      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… if the computation ignores the cancel

Should the computation wait for the language server's answer instead of ending when the write action cancels it, the write action would wait for its read lock forever. A watchdog answers the held request after the test's bound, so that both end and the test fails with a message.
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai About the comment on CallHierarchyWriteActionTest.java lines 158-159 (bound the write action): fixed in 2fa2c40.

Before the write action, a watchdog is scheduled after the test's bound. If the computation hasn't ended by then because it waits for the held answer instead of ending when cancelled, the watchdog answers the held request, so the computation and the write action end. The test then fails with "the computation of the children must end when a write action cancels it, not wait for the answer of …". On success the watchdog is cancelled.

Checked by simulating that regression: the callers computation waited with a plain get() instead of awaitWithCheckCanceled. The test failed after 16 s with that message, instead of hanging.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Current revision ---'
git rev-parse HEAD
printf '%s\n' '--- Test file locations ---'
fd -t f '^CallHierarchyWriteActionTest\.java$' .
printf '%s\n' '--- Test file outline and numbered contents ---'
while IFS= read -r file; do
  ast-grep outline "$file" --items all --view expanded || true
  cat -n "$file" | sed -n '1,360p'
done < <(fd -t f '^CallHierarchyWriteActionTest\.java$' .)
printf '%s\n' '--- Cited commit summary and test diff ---'
git show --format=fuller --stat 2fa2c404 -- 2>&1 || true
git show --format= -- ':(glob)**/CallHierarchyWriteActionTest.java' 2>&1 | sed -n '1,220p' || true

Length of output: 27158


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Current revision ---'
git rev-parse HEAD
printf '%s\n' '--- Test file locations ---'
fd -t f '^CallHierarchyWriteActionTest\.java$' .
printf '%s\n' '--- Test file outline and numbered contents ---'
while IFS= read -r file; do
  ast-grep outline "$file" --items all --view expanded || true
  cat -n "$file" | sed -n '1,360p'
done < <(fd -t f '^CallHierarchyWriteActionTest\.java$' .)
printf '%s\n' '--- Cited commit summary and test diff ---'
git show --format=fuller --stat 2fa2c404 -- 2>&1 || true
git show 2fa2c404 --format= -- ':(glob)**/CallHierarchyWriteActionTest.java' 2>&1 | sed -n '1,220p' || true

Length of output: 27167


@lagergren Thanks for the fix and the regression check. I inspected commit 2fa2c404. The watchdog addresses the reported hang when the computation waits for the held response.

I did not run the test or change the review thread’s status.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit b1b270a into redhat-developer:main Nov 26, 2026
11 checks passed
@lagergren
lagergren deleted the fix/call-hierarchy-rethrows-cancellation branch November 26, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Call Hierarchy shows no callers when a write action comes while it waits for callHierarchy/incomingCalls

1 participant