Skip to content

fix: skip a failed LSP request instead of reporting an IDE error - #1832

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/await-failed-request
Nov 3, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/await-failed-request

Conversation

@lagergren

@lagergren lagergren commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

When a language server cannot start, for instance because its command is wrong ("Cannot run program"), LSP4IJ shows its "Cannot start server" notification, and IntelliJ also reports "IDE error occurred" for a feature that was waiting for the server, such as the colors of the file:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.redhat.devtools.lsp4ij.server.CannotStartProcessException: ...
	at com.redhat.devtools.lsp4ij.internal.CompletableFutures.awaitWithCheckCanceled(CompletableFutures.java:132)
	at com.redhat.devtools.lsp4ij.features.color.LSPColorProvider.doCollect(LSPColorProvider.java:96)
	at com.redhat.devtools.lsp4ij.features.AbstractLSPInlayHintsProvider$1.collect(AbstractLSPInlayHintsProvider.java:74)

About 40 features wait for their request with CompletableFutures.awaitWithCheckCanceled, catch only cancellations, and then skip a request which isn't done normally (isDoneNormally). But the wait calls IntelliJ's ProgressIndicatorUtils.awaitWithCheckCanceled, which rethrows a failed future, in a RuntimeException around its ExecutionException, so the failure escapes before that check. 15aa49ae ("perf: Use ProgressIndicatorUtils.awaitWithCheckCanceled", in 0.20.2) made it the wait. Before, CompletableFutures.waitUntilDone turned a failed server start, a LanguageServerException, into a ProcessCanceledException, and threw any other failure as an ExecutionException, which the callers caught. #784 is the same regression for completionItem/resolve, which #1814 fixed for that request.

Fixes #1830.

Related to #1600: its trace is also a CannotStartProcessException reported by IntelliJ, but through another path: it was reported against 0.20.0, before 15aa49ae, and it is a CompletionException, made by a stage of the failed initialization (the thenApply of getInitializedServer()), which reaches the EDT, so some code there joins that stage. This wait throws a RuntimeException instead, so #1600 is not addressed here.

Changes

  • CompletableFutures.awaitWithCheckCanceled returns when the future fails, instead of throwing the failure, so the callers skip it as a request which isn't done normally. A cancellation is thrown as before: a CancellationException for a cancelled future, and a ProcessCanceledException for a canceled progress or a future cancelled in a previous stage.
  • The failure is logged. A LanguageServerException, a server which could not start or which stopped, is logged at debug level: LSP4IJ has already reported it, in its notification and the LSP console, and each highlighting pass which waits for the server would repeat it. Any other failure is logged as a warning, since it is unexpected: an LSP error response doesn't reach the wait, as CancellationSupport reports it, as the server's Error reporting setting says, and completes the request with null. What's left is a bug in a client's feature code or in LSP4IJ, or a request which doesn't go through CancellationSupport, such as a DAP request. A warning keeps it in the log without an IDE error.
  • CancellationSupport.awaitWithCheckCanceled, LSP4IJ's own copy of IntelliJ's wait, which Go to Symbol and Go to Class use, returns null for a failed future in the same way. It threw the failure before 0.20.2 too.
  • The callers which read the future after the wait without checking isDoneNormally, since getNow() and join() rethrow a failure:
    • LSPUsageSearcher checked only isDone(), so the failure reached its LOGGER.error. It now checks isDoneNormally.
    • DAPSmartStepIntoHandler now checks isDoneNormally before getNow().
    • DAPDebugProcess needs the failure thrown: it prints it in the debug console and stops the session. It now waits with ProgressIndicatorUtils.awaitWithCheckCanceled, which still throws it, so it works as before.
    • LSPFormattingSupport lets join() and getNow() throw the failure into its catch (Exception), which reports a formatting error, as before. The message of that error is now the failure's own, rather than the ExecutionException's.
  • LSPInlineCompletionProvider called ProgressIndicatorUtils.awaitWithCheckCanceled itself, and caught an ExecutionException, which that wait never throws. It now waits with CompletableFutures.awaitWithCheckCanceled, and checks isDoneNormally as before, so a failed request gives no suggestion.

The other callers check isDoneNormally before they read the future, or hand it to code which does (AbstractLSPGoToAction, and fillChildren of the call and type hierarchies). LSPCodeLensProvider goes on with the code lenses whose codeLens/resolve didn't fail. AbstractLSPFileListener and CompletableFutures.waitUntilDoneAsync call IntelliJ's wait themselves and catch any exception, so they don't change. LSPCompletionProposal isn't changed here.

Tests

  • AwaitWithCheckCanceledTest has 7 tests:
    • a future whose server cannot start, and a future which fails while it is awaited, return from CompletableFutures.awaitWithCheckCanceled without their failure;
    • a cancelled future throws its CancellationException, and a future cancelled in a previous stage, or a canceled progress, throws a ProcessCanceledException, as before;
    • CancellationSupport.awaitWithCheckCanceled returns null for a failed future, and the result of a completed one, and throws a ProcessCanceledException for a cancelled future, as before.
  • ServerStartFailureTest has 2 tests, with a server whose start fails with "Cannot run program": the color provider, collecting through getCollectorFor(...).collect(...) as in the trace above, adds nothing, and LSPFoldingRangeBuilder.getFoldingRanges returns no folding range. Both check that the server failed to start.

Without the change in src/main, 5 of the 9 tests fail with the RuntimeException above: the 2 tests of ServerStartFailureTest, the 2 failed futures of CompletableFutures.awaitWithCheckCanceled, and the failed future of CancellationSupport.awaitWithCheckCanceled. The 4 tests of the cancellations pass with and without it.

com.redhat.devtools.lsp4ij.features.*, usages.*, dap.*, internal.*, server.* and the language server lifecycle tests (LanguageServer*, ConnectDuringStopTest, DocumentLifecycleTest, RequestAfterChangeTest, LSPIJEditorUtilsTest) pass: 784 tests, with the 3 existing skips.

Locally, the full suite passes (1,019 tests, 3 skipped) except the 7 known macOS failures ("File accessed outside allowed roots"), which fail on main too. The IDE error was seen in a running IDE, with a LemMinX server whose command was wrong; the fix was not checked there.

When a language server cannot start, for instance because its command is
wrong, LSP4IJ shows its "Cannot start server" notification, and IntelliJ
also reports an IDE error for a feature that was waiting for the server:

  java.lang.RuntimeException: java.util.concurrent.ExecutionException:
      com.redhat.devtools.lsp4ij.server.CannotStartProcessException: ...
    at ...internal.CompletableFutures.awaitWithCheckCanceled(CompletableFutures.java:132)
    at ...features.color.LSPColorProvider.doCollect(LSPColorProvider.java:96)

The callers of CompletableFutures.awaitWithCheckCanceled catch only
cancellations, and then skip a future which isn't done normally. But
since 15aa49a (0.20.2) the wait is IntelliJ's
ProgressIndicatorUtils.awaitWithCheckCanceled, which rethrows a failed
future, in a RuntimeException around its ExecutionException, before
that check. The wait now returns when the future fails, and logs the
failure: at debug level for a LanguageServerException, which LSP4IJ has
already reported, and as a warning for anything else, which is
unexpected, since CancellationSupport reports an LSP error response and
completes the request with null. A cancellation is thrown as before.

CancellationSupport.awaitWithCheckCanceled, which Go to Symbol and Go to
Class use, returns null for a failed future the same way.
LSPUsageSearcher and DAPSmartStepIntoHandler now check isDoneNormally
before getNow, which would rethrow the failure.
LSPInlineCompletionProvider waits with CompletableFutures instead of
IntelliJ's wait. DAPDebugProcess, which prints a failure to start the
debug adapter in the console and stops, now waits with IntelliJ's wait,
which still throws it. The other callers already check isDoneNormally.

AwaitWithCheckCanceledTest and ServerStartFailureTest: without the
change in src/main, 5 of their 9 tests fail with the RuntimeException
above, and the 4 which pin the cancellations pass with and without it.
./gradlew test on features.*, usages.*, dap.*, internal.*, server.* and
the language server lifecycle tests: 784 tests, 0 failures, the 3
existing skips.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

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: 6710f6fb-63e2-4807-ade6-fa22a69becde
Commits

Reviewing files that changed from the base of the PR and between e96dee9 and 8330926.

Files selected for processing: 8
  • src/main/java/com/redhat/devtools/lsp4ij/dap/DAPDebugProcess.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/stepping/DAPSmartStepIntoHandler.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/CancellationSupport.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/CompletableFutures.java
  • src/main/java/com/redhat/devtools/lsp4ij/usages/LSPUsageSearcher.java
  • src/main/kotlin/com/redhat/devtools/lsp4ij/features/inlineCompletion/LSPInlineCompletionProvider.kt
  • src/test/java/com/redhat/devtools/lsp4ij/features/ServerStartFailureTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/internal/AwaitWithCheckCanceledTest.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.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Language server failures are handled more gracefully: affected features no longer attempt to display incomplete results, such as usage results, smart-step options, colors, or folding ranges.
    • Waiting for language server responses remains responsive to cancellation, while failed requests no longer interrupt the surrounding workflow with unexpected errors.

Future wait helpers now log and suppress execution failures while preserving cancellation behavior. Related call sites check for normal completion before reading results, and tests cover failed requests and server startup failures.

Changes: Future Failure Handling

Layer / File(s) Summary
Future wait failure and cancellation handling
src/main/java/com/redhat/devtools/lsp4ij/internal/CompletableFutures.java, src/main/java/com/redhat/devtools/lsp4ij/internal/CancellationSupport.java, src/test/java/com/redhat/devtools/lsp4ij/internal/AwaitWithCheckCanceledTest.java, src/test/java/com/redhat/devtools/lsp4ij/features/ServerStartFailureTest.java
CompletableFutures.awaitWithCheckCanceled logs and suppresses execution failures while rethrowing cancellation. CancellationSupport.awaitWithCheckCanceled returns null for failed futures. Tests cover failure, cancellation, and collection behavior when a server cannot start.
Wait and result handling at call sites
src/main/java/com/redhat/devtools/lsp4ij/dap/DAPDebugProcess.java, src/main/java/com/redhat/devtools/lsp4ij/dap/stepping/DAPSmartStepIntoHandler.java, src/main/java/com/redhat/devtools/lsp4ij/usages/LSPUsageSearcher.java, src/main/kotlin/com/redhat/devtools/lsp4ij/features/inlineCompletion/LSPInlineCompletionProvider.kt
DAP waits now use ProgressIndicatorUtils, while inline completion uses CompletableFutures. Smart-step and usage results are processed only after normal future completion.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 83309

Failed language-server requests are skipped without changing cancellation handling. No concrete merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: failed LSP requests are skipped instead of producing IDE errors.
Description check Passed The description directly explains the failure-handling changes, affected callers, cancellation behavior, logging, tests, and scope.
Linked Issues check Passed The PR addresses the coding requirements in #1830. CompletableFutures.awaitWithCheckCanceled suppresses failed futures after logging them, while it still propagates cancellation. `CancellationSuppor…
Out of Scope Changes check Passed The changed production code supports #1830 by preventing failed waits from reaching IntelliJ as IDE errors and by preserving caller-specific cancellation or failure behavior. The caller updates preven…
Full details: Linked Issues check

Explanation

The PR addresses the coding requirements in #1830. CompletableFutures.awaitWithCheckCanceled suppresses failed futures after logging them, while it still propagates cancellation. CancellationSupport.awaitWithCheckCanceled returns null for failed futures. The affected callers check isDoneNormally or retain required failure handling, including DAPDebugProcess. AwaitWithCheckCanceledTest covers failed futures and cancellation. ServerStartFailureTest covers color and folding feature waits for a server that cannot start. The PR correctly leaves the separate #1600 EDT path out of scope.

Full details: Out of Scope Changes check

Explanation

The changed production code supports #1830 by preventing failed waits from reaching IntelliJ as IDE errors and by preserving caller-specific cancellation or failure behavior. The caller updates prevent getNow() and similar reads from rethrowing suppressed failures. The added tests verify the changed wait behavior and affected feature behavior. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 8 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.69%. Comparing base (e96dee9) to head (8330926).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...t/devtools/lsp4ij/internal/CompletableFutures.java 46.15% 6 Missing and 1 partial ⚠️
...s/lsp4ij/dap/stepping/DAPSmartStepIntoHandler.java 0.00% 1 Missing ⚠️
.../devtools/lsp4ij/internal/CancellationSupport.java 66.66% 0 Missing and 1 partial ⚠️
...edhat/devtools/lsp4ij/usages/LSPUsageSearcher.java 0.00% 1 Missing ⚠️
...es/inlineCompletion/LSPInlineCompletionProvider.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1832      +/-   ##
==========================================
+ Coverage   37.65%   37.69%   +0.03%     
==========================================
  Files         786      786              
  Lines       30019    30034      +15     
  Branches     6001     6005       +4     
==========================================
+ Hits        11305    11321      +16     
+ Misses      16756    16754       -2     
- Partials     1958     1959       +1     

☔ 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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 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.

@angelozerr angelozerr added the bug Something isn't working label Nov 3, 2026
@angelozerr angelozerr added this to the 0.30.0 milestone Nov 3, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Nov 3, 2026
@angelozerr
angelozerr merged commit 2f4cea3 into redhat-developer:main Nov 3, 2026
10 checks passed
@angelozerr

Copy link
Copy Markdown
Contributor

Thanks @lagergren !

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Nov 3, 2026
angelozerr pushed a commit that referenced this pull request Nov 7, 2026
… editor scrolls (#1883)

* fix: don't throw a failed code lens request on the UI thread when the editor scrolls

LSPCodeLensEditorFactoryListener's visible area listener, which runs on the
UI thread on every scroll or resize of an editor, read the code lens future
with getNow() once it was done. A request whose language server cannot
start, as when its command is wrong, is done exceptionally: getNow() then
rethrew its CompletionException(CannotStartProcessException), which IntelliJ
reports as an IDE error with no LSP4IJ frame on the UI thread, as in #1600.
LSP4IJ already reports a server that cannot start with a "Cannot start
server" notification. The listener now reads the future only if it is done
normally (CompletableFutures.isDoneNormally), and a failed or cancelled
request has no code lenses to resolve.

#1832 (#1830) changed the wait of the highlighting passes, not this read,
so it didn't fix #1600.

Validation:
- ServerStartFailureTest.testAScrollOfAnEditorWhoseCodeLensesFailedDoesNotThrow
  calls the listener that editorCreated attaches with a failed code lens
  request. On main it fails with "CompletionException:
  CannotStartProcessException: Cannot run program "missing"", thrown at
  LanguageServerWrapper.java:659, as in the issue; with this change it
  passes.
- The full suite: 1,292 tests, 3 skipped; the 7 failures are the known
  macOS ones ("File accessed outside allowed roots") in
  LSPIJUtils_applyWorkspaceEdit_*Test and CommandExecutorTest, which fail
  on main too.

Fixes #1600.

* fix: keep a code lens viewport up to date while its editor has no code lenses

LSPCodeLensProvider resolves the code lenses of a new result in the
viewport kept by the editor's UnresolvedCodeLensViewportContext. The scroll
listener updated that viewport only when the code lens request had ended
normally, so a scroll while the request ran, or after it failed as when the
language server cannot start, left it where it was. A later result then
resolved the code lenses of the old viewport, and those shown stayed
unresolved until the next scroll.

The listener now updates the viewport on every scroll, and only the refresh
of the code visions waits for a result.

Validation: ServerStartFailureTest's new
testAScrollOfAnEditorWhoseCodeLensesFailedUpdatesItsViewport scrolls an
editor whose request failed from line 0 to line 50; without the change the
viewport stays at line 0 ("expected:<50> but was:<0>"). ServerStartFailureTest
and EditorRefreshBatchTest: 9 tests, 0 failures, 0 skipped (JUnit XML).

* fix: read a code lens result once its editor's viewport is updated

The scroll listener read the code lens result when the editor scrolled, and
updated the viewport later when it had no read access, in a read action on
the UI thread. A request that ended in between resolved the code lenses of
the previous viewport, and the deferred update, which still held no result,
didn't refresh the code visions: the code lenses of the new viewport stayed
unresolved until another scroll.

updateViewportLinesAndRefreshCodeVision now reads the result itself, once
it has updated the viewport, on both paths.

Validation: ServerStartFailureTest and EditorRefreshBatchTest, 9 tests, 0
failures, 0 skipped (JUnit XML). The deferred path runs only without read
access on the UI thread, which a 2024.2 test doesn't have, so no test
drives it.
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

Status: Done

Development

Successfully merging this pull request may close these issues.

Since 0.20.2, a failed request or a language server which can't start raises an IDE error

2 participants