Skip to content

fix: use a completion item unresolved when its resolve fails - #1814

Merged
angelozerr merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/completion-resolve-error
Nov 2, 2026
Merged

angelozerr merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/completion-resolve-error

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

When a language server answers completionItem/resolve with an error, such as typescript-language-server's "Cannot read properties of undefined (reading 'file')" in #784, selecting the completion item inserts nothing: the typed prefix stays as it is, and IntelliJ reports the ResponseErrorException as an IDE error. The expensive renderer of the selected item, which is where #784's stack trace comes from, and the item's documentation fail with the same exception.

LSPCompletionProposal.getResolvedCompletionItem() waits for the request with awaitWithCheckCanceled, which rethrows a failed request wrapped in a RuntimeException, and it catches only cancellations. Before 0.20.2 the wait caught the ExecutionException and logged it as an error, which is the IDE error in #784, and the item was then inserted unresolved. 15aa49ae ("perf: Use ProgressIndicatorUtils.awaitWithCheckCanceled", in 0.20.2) removed that catch, so the error now escapes handleInsert before anything is inserted. The request was also sent without a CancellationSupport, so the server's Error reporting setting didn't apply to it, as it does to other LSP requests.

Fixes #784.

Changes

  • LSPCompletionProposal.getResolvedCompletionItemFuture(): the completionItem/resolve request now goes through a CancellationSupport with its language server, like codeLens/resolve, inlayHint/resolve and documentLink/resolve. A ResponseErrorException is reported as the server's Error reporting setting says (a notification by default, the log, or nothing), and the request completes with null. Every caller already takes null as "not resolved", so the item is inserted, rendered and documented as textDocument/completion gave it. A RequestCancelled or ContentModified error is ignored, as for other requests.
  • LSPRequestConstants.COMPLETION_ITEM_RESOLVE.

A resolve which succeeds works as before. An error which isn't a ResponseErrorException, a cancellation or a MessageIssueException still propagates, as it does for the other resolve requests.

Tests

CompletionItemResolveFailureTest has 3 tests, each with a server whose completionItem/resolve fails with an InternalError response:

  • selecting an item inserts it unresolved, after one resolve request;
  • the error is reported in a notification, with completionItem/resolve as its subtitle and the server's message as its content;
  • the expensive renderer of the selected item renders it unresolved, its detail isn't resolved again, and it has no documentation.

Without the change in LSPCompletionProposal, all 3 fail: the first two with the ResponseErrorException out of handleInsert, while the editor still has only the typed f, and the last with it out of the renderer. The other completion tests (com.redhat.devtools.lsp4ij.features.completion.*, 105 tests with the new ones) pass.

Locally, the full suite passes (1,006 tests, 3 skipped) except the 7 known macOS failures ("File accessed outside allowed roots"), which fail on main too. Not checked in a running IDE.

When a language server answers 'completionItem/resolve' with an error,
LSPCompletionProposal.getResolvedCompletionItem() lets it escape:
awaitWithCheckCanceled rethrows the failed request, and only
cancellations are caught. Selecting the item then inserts nothing and
IntelliJ reports an IDE error; the expensive renderer and the
documentation of the item fail the same way. Since 15aa49a (0.20.2)
the ExecutionException is no longer caught, and before that it was
logged as an error.

The request now goes through a CancellationSupport with its language
server, like the other resolve requests. A ResponseErrorException is
reported as the server's error reporting setting says, the request
completes with null, and the callers use the item unresolved.

CompletionItemResolveFailureTest: a failed resolve still inserts the
item, is reported in a notification, and the expensive renderer renders
the item unresolved. All 3 fail without the change in
LSPCompletionProposal; com.redhat.devtools.lsp4ij.features.completion.*
passes (105 tests).

Fixes redhat-developer#784
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 614971d2-b545-40f5-bea6-9d7a2be54d7b
Commits

Reviewing files that changed from the base of the PR and between c24cb36 and 9c37943.

Files selected for processing: 1
  • src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionProposal.java
Summary

Summary by CodeRabbit

  • Bug Fixes
    • Completion suggestions can still be inserted when resolving additional item details fails.
    • Failed resolution is reported through an error notification, and the suggestion remains available without resolved details or documentation.
    • Completion-item resolution now supports cancellation, helping prevent unnecessary work when a request is no longer needed.

The completion proposal now submits item-resolution requests through cancellation support. New tests cover insertion, error notification, and unresolved rendering when a resolve request fails.

Changes: Completion item resolution

Layer / File(s) Summary
Route resolve requests
src/main/java/com/redhat/devtools/lsp4ij/LSPRequestConstants.java, src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionProposal.java
Adds the completionItem/resolve request constant and uses it when submitting item resolution through cancellation support.
Cover failed resolve behavior
src/test/java/com/redhat/devtools/lsp4ij/features/completion/CompletionItemResolveFailureTest.java
Adds tests for insertion after failed resolution, error notification, and rendering without resolved detail or documentation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: halflifefan

Merge Risk: Minimal · previous review c24cb

The change adds reporting and unresolved-item fallback for completion resolution errors. The remaining reporting concern predates this change and does not establish a merge blocker.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.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 says the change makes a completion item stay unresolved when its resolve fails. The raw summary and description confirm this: LSPCompletionProposal now routes completionItem/resolve through …
Description check Passed The description explains the cause (awaitWithCheckCanceled rethrowing a failed request after commit 15aa49a removed the catch), the fix (CancellationSupport for completionItem/resolve, null result on…
Linked Issues check Passed Issue #784 requires handling errors from completionItem/resolve with the TypeScript language server. The PR routes this request through CancellationSupport, reports ResponseErrorException accord…
Out of Scope Changes check Passed The changed request constant supports the new completionItem/resolve request path. The LSPCompletionProposal change implements issue #784. The three new tests verify the failure behavior. No unrel…
Full details: Title check

Explanation

The title says the change makes a completion item stay unresolved when its resolve fails. The raw summary and description confirm this: LSPCompletionProposal now routes completionItem/resolve through CancellationSupport, reports ResponseErrorException per the error-reporting setting, and completes with null so the item is inserted unresolved. The title is specific and matches the main change. The "fix:" prefix is conventional and does not hurt clarity.

Full details: Description check

Explanation

The description explains the cause (awaitWithCheckCanceled rethrowing a failed request after commit 15aa49a removed the catch), the fix (CancellationSupport for completionItem/resolve, null result on ResponseErrorException), the new constant, the three added tests, and the test results. It relates directly to the changeset and references issue #784.

Full details: Linked Issues check

Explanation

Issue #784 requires handling errors from completionItem/resolve with the TypeScript language server. The PR routes this request through CancellationSupport, reports ResponseErrorException according to the server setting, and completes the resolve with null. The existing completion item is then used unresolved. CompletionItemResolveFailureTest verifies insertion after one failed resolve, error notification content, and unresolved rendering without repeated detail resolution.

Full details: Out of Scope Changes check

Explanation

The changed request constant supports the new completionItem/resolve request path. The LSPCompletionProposal change implements issue #784. The three new tests verify the failure behavior. No unrelated change is identified in the supplied change summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.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 2 functions across 3 files.

Resolution

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

@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/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionProposal.java-533-535: 1

533-535: Minor · Potential issue · Low value

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

The new CancellationSupport route classifies a ResponseErrorException only when it is the immediate exception. A resolve future completed exceptionally with a CompletionException wrapping that error may therefore bypass the configured language-server error report.

The item can fall back to unresolved insertion without the notification or log entry configured for its server error.

This can occur when: The text-document service supplies a resolve future whose failure is a CompletionException caused by a ResponseErrorException.


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: 78eac73f-4b45-4bdc-945d-6735866baeac
Commits

Reviewing files that changed from the base of the PR and between cec834e and c24cb36.

Files selected for processing: 3
  • src/main/java/com/redhat/devtools/lsp4ij/LSPRequestConstants.java
  • src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionProposal.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/completion/CompletionItemResolveFailureTest.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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

On CodeRabbit's unverified finding (a ResponseErrorException wrapped in a CompletionException skipping the error report): not changed. getTextDocumentService().resolveCompletionItem(item) returns LSP4J's request future, which LSP4J's RemoteEndpoint completes exceptionally with the ResponseErrorException itself; handle() on that future receives it unwrapped. A CompletionException would only wrap it in a dependent stage, and CancellationSupport is applied to the request future directly, as for every other LSP request. testAFailedResolveIsReportedLikeOtherLanguageServerErrors checks it: the server's error reaches the notification.

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.63%. Comparing base (cec834e) to head (9c37943).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1814   +/-   ##
=======================================
  Coverage   37.62%   37.63%           
=======================================
  Files         786      786           
  Lines       30019    30019           
  Branches     4546     4546           
=======================================
+ Hits        11296    11299    +3     
+ Misses      16772    16760   -12     
- Partials     1951     1960    +9     

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

@angelozerr
angelozerr merged commit e5b76a8 into redhat-developer:main Nov 2, 2026
9 checks passed
@angelozerr

Copy link
Copy Markdown
Contributor

Thanks so much @lagergren !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error while consuming LSP 'completionItem/resolve' request

2 participants