Skip to content

fix: a document matcher whose async match fails no longer takes away the other language servers of the file - #2164

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/failing-async-matcher-keeps-other-servers
Nov 23, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/failing-async-matcher-keeps-other-servers

Conversation

@lagergren

@lagergren lagergren commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Please merge with "Rebase and merge", not "Squash and merge". There are 2 commits, one per issue, so that each reaches the release notes.

Fixes #2161
Fixes #2163

What

A language server definition can match a file asynchronously, through a DocumentMatcher whose matchAsync returns a CompletableFuture<Boolean>. LanguageServiceAccessor.getMatchedLanguageServerDefinitions waited for every such matcher of a file in one CompletableFuture.allOf(...), with no error handling.

So one matcher whose future failed, or whose matchAsync threw, failed the whole match, and with it the request for the file's language servers.

  • The file got none of its language servers, not even those that matched it synchronously or through other asynchronous matchers. A bug in one plugin's matcher took away the language servers of every other plugin, and every user-defined one, for that file.
  • isFileMappedToServer failed too, even for a definition with another mapping that matches the file. The move of an open document and the workspace diagnostics ask it.

The synchronous counterpart (#2163): getMatchedLanguageServerDefinitions asked each synchronous DocumentMatcher.match of the file's mappings with no error handling. A matcher that threw made the match of the file throw, and with it the request for the file's language servers and isFileMappedToServer. The file got none of its language servers, not even those that other mappings matched.

Change

Each asynchronous mapping of the file is matched on its own:

  • A failure: a matcher whose future fails, or whose matchAsync throws, counts as no match for its definition. Its failure is logged as a warning, with the definition's name and the file's URL, since nothing else reports it.
  • A cancellation still cancels the request, without a log, as before. An AbstractDocumentMatcher cancels its earlier matches of a file when it's asked again, as when several features ask at once while the file opens during indexing. A feature whose request is cancelled asks again; with no match instead, it would keep a result without that language server until the file changes.
  • A cancellation thrown by matchAsync, and an Error, still propagate.

Both users of the asynchronous match get this, as the combined match no longer fails for one failing matcher: the request for a file's language servers, and isFileMappedToServer.

Second commit (#2163):

  • A throwing matcher: a synchronous DocumentMatcher.match that throws an exception counts as no match for its definition. It's logged as a warning with the definition's name and the file's URL, with the same message as an asynchronous failure.
  • Read access: the exception is caught inside the read action that asks the matcher, so a caller without read access, for which runCancellableReadAction asks the matcher in a read action of its own, gets the same answer as a caller with read access.
  • Cancellations and errors: a ProcessCanceledException, another cancellation, and an Error still propagate.
  • One log line per failure: a synchronous file-name-pattern mapping that doesn't match the file is asked once per match of the file, instead of twice, so that a matcher's exception is logged once. Such a mapping is found for the language of the file and again for its file type.

Behaviour change

Situation Before After
An asynchronous matcher fails or throws, in a request for the file's language servers The request fails: the file gets no language server The definition doesn't match. The other definitions serve the file, and one warning is logged
An asynchronous match is cancelled The request is cancelled The request is cancelled, as before
isFileMappedToServer for a definition whose matcher fails The future fails false, or true when another mapping of the definition matches
Workspace diagnostics of a closed file whose matcher fails The report is dropped, earlier diagnostics are kept, and "Unable to match workspace diagnostic file" is logged Handled as a file that doesn't match: the report is dropped, and the provider's earlier workspace diagnostics of the file are cleared
Move of an open document whose matcher fails Not connected again, with a "Cannot match moved document" warning Not connected again, with the warning from LanguageServiceAccessor
The banner that suggests templates matches a file whose async matcher fails The failure is dropped silently It's logged as a warning too, once per match
A synchronous matcher throws, in a request for the file's language servers The request throws: the file gets no language server The definition doesn't match. The other mappings serve the file, and one warning is logged
isFileMappedToServer for a definition whose synchronous matcher throws Throws false, or true when another mapping of the definition matches
Workspace diagnostics of a closed file whose synchronous matcher throws The report is dropped, earlier diagnostics are kept, and "Unable to match workspace diagnostic file" is logged Handled as a file that doesn't match: the report is dropped, and the provider's earlier workspace diagnostics of the file are cleared
A synchronous matcher throws a ProcessCanceledException Propagates Propagates, as before
A synchronous file-name-pattern mapping that doesn't match the file Asked twice per match of the file Asked once

Backward compatibility

  • No public API change: DocumentMatcher, LanguageServerFileAssociation and LanguageServiceAccessor keep their signatures; only private helpers are added.
  • isFileMappedToServer no longer completes exceptionally for a failing matcher.
  • Cancellations and errors: a cancelled match cancels the request and isFileMappedToServer, as before. A cancellation thrown by matchAsync, or an Error, propagates as before.
  • The second commit changes no public API either. isFileMappedToServer no longer throws for a synchronous matcher that throws.

Test

New tests in AsynchronousMatcherTest:

  • a definition matched synchronously keeps serving the file when another definition's asynchronous matcher fails;
  • of two asynchronous matchers, the one that answers still matches when the other fails;
  • the failure is logged once, as a warning, with the definition's name and the file's URL;
  • a matchAsync that throws matches nothing, and is logged;
  • isFileMappedToServer is true through another mapping of the definition, and false for a definition whose only matcher fails;
  • a cancelled match still cancels the request, and isFileMappedToServer, without a log.

The five failure tests fail without the change. The two cancellation tests pass without it, and fail if a cancelled match counts as no match.

New tests for a synchronous matcher that throws (#2163), in AsynchronousMatcherTest:

  • the other mappings of the file keep serving it;
  • the exception is logged once, as a warning, with the definition's name and the file's URL, and the matcher is asked once;
  • the answer is the same with and without read access;
  • isFileMappedToServer is true through another mapping of the definition, and false for a definition whose only matcher throws;
  • a ProcessCanceledException still propagates.

The first four fail without the second commit. The last pins the earlier behaviour, and fails if the fix catches cancellations too.

  • Affected classes: AsynchronousMatcherTest, WorkspaceDiagnosticsTest, FileDocumentMoveTest and LanguageServerInstancesTest (144 tests) pass on IC 2024.2, IC 2025.3 and IU 2026.3.
  • Full suite on IC 2024.2: 2,169 tests, 0 failures, 7 skipped, as before.

…the other language servers of the file

A language server definition can match a file asynchronously, through a
DocumentMatcher whose matchAsync returns a future. A request for the language
servers of a file waited for every such matcher of the file in one
CompletableFuture.allOf(), without handling a failure. A matcher whose future
failed, or whose matchAsync threw, failed the match of the file, and with it the
request: the file then got none of its language servers, not even those that
matched it synchronously, nor those whose own matchers answered. A bug in the
matcher of one plugin took away the language servers of every other plugin, and
every user-defined one, for that file. LanguageServiceAccessor.isFileMappedToServer,
which the move of an open document and the workspace diagnostics ask, failed
too, even for a definition with another mapping that matches the file.

A matcher that fails, or whose matchAsync throws, now counts as no match for its
definition, and the other definitions, matched synchronously or not, still serve
the file. Nothing else reports the failure, so it is logged as a warning, with
the name of the definition and the URL of the file.

A cancelled match still cancels the request, without a log, as before. An
AbstractDocumentMatcher cancels its earlier matches of a file when it is asked
again, as when several features ask at once as the file opens while the IDE
indexes: a feature whose request is cancelled asks again, while it would keep a
result without the language server of the matcher until the file changes. A
cancellation that matchAsync throws, and an Error, still propagate too.

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

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • A failing synchronous or asynchronous file matcher no longer prevents other matching language services from being selected.
    • Matcher failures are recorded as warnings with the affected file and language service definition.
    • Failed synchronous matches are not retried during content-type matching.
    • Cancellation continues to stop matching and related requests without being treated as a matcher failure.

Synchronous and asynchronous matcher failures are logged and treated as non-matches. Other mappings can still match. Cancellation and Error retain their specified propagation behavior.

Changes: Matcher Failure Handling

Layer / File(s) Summary
Matcher failure handling and mapping traversal
src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
Synchronous and asynchronous matcher failures are handled per mapping. Ordinary exceptions are logged with the file and server definition and treated as non-matches. Synchronous non-matches are recorded to avoid reevaluation during content-type traversal.
Failure and cancellation tests
src/test/java/com/redhat/devtools/lsp4ij/AsynchronousMatcherTest.java
Tests cover retained matches when a matcher fails, warning details, failures thrown during matcher invocation, and cancellation behavior for synchronous and asynchronous matching.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 965ba

A failing language-server matcher no longer blocks other mappings for a file; the failure is logged as a warning. Cancellation behavior is unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: a document matcher whose async match fails no longer removes the other language servers of the file. It matches the changeset, which handles failing asynchronous matc…
Description check Passed The description explains the problem, the change, the behavior differences, backward compatibility, and tests. It covers the asynchronous matcher fix and the synchronous matcher follow-up (#2163) that…
Linked Issues check Passed [#2161, #2163] Both issues require that a failing matcher counts as no match for its definition, that its failure is logged with the definition name, that other definitions still match, and that cance…
Out of Scope Changes check Passed The changes stay within the matching path of LanguageServiceAccessor: the synchronous match helper, the asynchronous matchAsync and noMatch handling, and the combined async match that serves getMatche…
Full details: Title check

Explanation

The title states the main change: a document matcher whose async match fails no longer removes the other language servers of the file. It matches the changeset, which handles failing asynchronous matchers in LanguageServiceAccessor. It is long at 107 characters, but it remains specific and accurate. The title also uses the conventional fix: prefix.

Full details: Description check

Explanation

The description explains the problem, the change, the behavior differences, backward compatibility, and tests. It covers the asynchronous matcher fix and the synchronous matcher follow-up (#2163) that the changeset implements. The description is related to the changeset.

Full details: Linked Issues check

Explanation

[#2161, #2163] Both issues require that a failing matcher counts as no match for its definition, that its failure is logged with the definition name, that other definitions still match, and that cancellation propagates. At the reviewed head, LanguageServiceAccessor has a private match(VirtualFile, Project, LanguageServerFileAssociation) helper. It runs matchInReadAction in a read action when the caller lacks read access, using runCancellableReadAction. matchInReadAction returns mapping.match(...) and rethrows ProcessCanceledException and CancellationException. It catches other Exception types, logs a warning through logMatchFailure with file.getUrl() and mapping.getServerDefinition().getDisplayName(), and returns false. An Error is not caught, so it propagates. This covers the synchronous requirement of #2163. For #2161, a private matchAsync helper converts a synchronous throw from mapping.matchAsync into CompletableFuture.failedFuture(e). Its noMatch and per-mapping handling follow the same pattern, as described in the previous assessment and the raw summary. The raw summary reports AsynchronousMatcherTest cases for failing and throwing matchers, for synchronous exceptions, and for cancellation. Limits: the diff was unavailable (changed blobs missing from the checkout), and the file read was truncated at 16000 bytes. The call sites in getMatchedLanguageServerDefinitions and isFileMappedToServer that route synchronous matches through match(...) were not read directly. Their routing rests on the raw summary and the PR description. The cancellation wording in #2161 ('ignored') differs from the PR behaviour ('still cancels the request'). The PR description states the intended behaviour, and the code keeps the cancellation propagating, as the objectives section records.

Full details: Out of Scope Changes check

Explanation

The changes stay within the matching path of LanguageServiceAccessor: the synchronous match helper, the asynchronous matchAsync and noMatch handling, and the combined async match that serves getMatchedLanguageServerDefinitions and isFileMappedToServer. The PR description ties the consumers of these paths (workspace diagnostics, move of an open document, the template banner) to the same behaviour change. The reported test changes are confined to AsynchronousMatcherTest, which tests the behaviour above. The raw summary lists no other changed source files in the reviewed evidence. Limits: the full changed-file list and the diff were not readable, and the call sites in the truncated part of LanguageServiceAccessor were not read. This verdict relies on the raw summary, the PR description, and the read helper code.

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: 4a74a576-fea0-419e-a2e8-4fff42018c41
Commits

Reviewing files that changed from the base of the PR and between c047ad5 and 965ba39.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
  • src/test/java/com/redhat/devtools/lsp4ij/AsynchronousMatcherTest.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.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.77%. Comparing base (52bcd11) to head (965ba39).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...edhat/devtools/lsp4ij/LanguageServiceAccessor.java 50.00% 11 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2164      +/-   ##
==========================================
- Coverage   53.79%   53.77%   -0.02%     
==========================================
  Files         828      828              
  Lines       34993    35037      +44     
  Branches     5481     5489       +8     
==========================================
+ Hits        18825    18842      +17     
- Misses      13373    13390      +17     
- Partials     2795     2805      +10     

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

…s away the other language servers of the file

LanguageServiceAccessor.getMatchedLanguageServerDefinitions asked each
synchronous DocumentMatcher of the file's mappings in a loop, with no error
handling. A matcher whose match threw an exception made the match of the file
throw, and with it the request for the language servers of the file: the file
then got none of its language servers, not even those that other mappings
matched. LanguageServiceAccessor.isFileMappedToServer threw too, even for a
definition with another mapping that matches the file.

A matcher that throws an exception now counts as no match for its definition,
and the other mappings still match the file. Nothing else reports the
exception, so it is logged as a warning, with the name of the definition and the
URL of the file, as for an asynchronous matcher that fails. The exception is
caught in the read action that asks the matcher, so a caller without read
access, for which the matcher is asked in a read action of its own, gets the
same answer as a caller with read access. A ProcessCanceledException, or
another cancellation, and an Error still propagate, as before.

A file name pattern mapping is found for the language of the file and again for
its file type. A synchronous mapping that doesn't match the file is now asked
once per match of the file instead of twice, so that the exception of a matcher
is logged once.

Fixes redhat-developer#2163
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 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 23, 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 d6f12e3 into redhat-developer:main Nov 23, 2026
10 checks passed
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

1 participant