Skip to content

fix: give a file opened while its language server starts the editor behavior of that language server - #2159

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/semantic-token-hover-of-two-servers
Nov 23, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/semantic-token-hover-of-two-servers

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2157

What

LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers failed on CI now and then:

The Ctrl+hover hint was null. It's a product bug, not a test bug. A file opened while its language server starts can keep the editor-behavior flags of a file that no started language server serves. Its semantic tokens-based file view provider then stays disabled, so Ctrl+hover shows no hint.

Cause

EditorBehaviorFeature cached its flags in a CachedValue whose dependencies are the language servers' modification trackers.

A CachedValue reads its dependencies' counts after computing the value (CachedValueBase.computeData). A language server that started during the computation changed the counts first, so the flag kept false until the next change of a language server. In the test:

  • the highlighting stored no semantic token in the view provider;
  • adding the second server enabled the provider again, but with no token;
  • the whole-file stub token then gave isIdentifier UNSURE, and no hint.

The race is in 0.30.1 too; the caching code is unchanged since March 2025.

Change

EditorBehaviorFeature keeps each flag with the tracker counts read before the flag was computed, and computes it again once any of them has changed. This is the same pattern as 7fa1794, which reads the modification counts before a feature's requests are sent. Files outside the VFS are still computed each time.

Behaviour change

Before After
A file opened while its language server started could keep, until the next change of a language server, the editor behavior of a file without a language server: no Ctrl+hover hint or semantic-token navigation in TextMate, plain text and abstract file types, and none of the string literal, statement terminator, Enter between braces or TextMate nested braces improvements The flags follow the language server that started

Test

  • New test: EditorBehaviorFeatureTest.testAFlagThatChangesWhileItIsComputedIsComputedAgain fails without the change and passes with it.
  • Probe: pausing the computation for 500 ms makes 12 of the test class's 15 tests fail on main (13 of 15 on 0.30.1), and none with the change.
  • Under load: the class failed 10 times in 5,600 runs without the change on 2024.2. With it, 0 failures in 4,800 runs on macOS and 2,000 on Linux.
  • Packages: client.features, features.semanticTokens and features.documentation pass on IC 2024.2, IC 2025.3 and IU 2026.3 (55 tests, 0 failures, each).
  • Full suite: 2,075 tests on 2024.2, 0 failures, 7 skipped, as before.

#2141 reports the same failure on 2026.3, with a different suspected cause.

…ehavior of that language server

The flags of EditorBehaviorFeature, as the one that enables the semantic
tokens-based file view provider of Ctrl+hover, were cached for each file
in a CachedValue, with the modification trackers of the language servers
of the file as its dependencies. A CachedValue reads the counts of its
dependencies after it has computed the value. A language server that
started while a flag was computed, as for a file opened while it starts,
changed those counts before they were read: the flag kept the value of
a file that no started language server serves until the next change of
a language server.

The semantic tokens-based file view provider of such a file then stayed
disabled: the highlighting stored no semantic token in it, so Ctrl+hover
showed no hint. LSPSemanticTokenDocumentationProviderTest failed on CI
this way: once its second language server was added, the view provider
was enabled again, without any token.

A flag now keeps the counts read before it is computed, and is computed
again once one of them has changed.
@lagergren lagergren added this to the 0.30.2 milestone Nov 23, 2026
@lagergren lagergren added bug Something isn't working hover semantic tokens labels 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
    • Editor behavior settings now refresh correctly when language-server capabilities change during a check, helping ensure the editor uses the latest available features.
    • Files without a valid editor document no longer incorrectly report these features as enabled.

Editor behavior flags now use language-server modification counts to validate cached results. A regression test checks that a flag is computed again when a server’s modification count changes during computation.

Changes: Editor behavior flag caching

Layer / File(s) Summary
Count-aware flag caching and regression test
src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java, src/test/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeatureTest.java
The feature records language-server modification counts before checking servers and reuses cached values only while those counts remain unchanged. Files without a VirtualFileWithId are computed without caching; invalid PSI results are not cached. The test checks that a count change during computation leads to a subsequent computation that enables the flag.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: scwells72, angelozerr

Merge Risk: Minimal · up to 6f06f

The change makes editor-behavior flags recompute when a language server starts during their computation. This fixes the stale-false race that could disable semantic-token and editor improvements for a file. The change is narrow and covered by a regression test, and no actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a file opened while its language server starts gets that server's editor behavior. The raw summary shows EditorBehaviorFeature now recomputes flags when language-serve…
Description check Passed The description explains the bug (CI failures in LSPSemanticTokenDocumentationProviderTest), its cause (CachedValue reading dependency counts after computation), the fix (reading counts before computi…
Linked Issues check Passed Issue #2157 requires that editor-behavior flags be recomputed when a language server starts during their computation. At head, EditorBehaviorFeature.compute() reads the TrackerCount values (via langua…
Out of Scope Changes check Passed The change set, as listed in the raw summary, touches only src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java (+70/-23) and the new src/test/java/com/redhat/devtools/l…
Full details: Title check

Explanation

The title names the main change: a file opened while its language server starts gets that server's editor behavior. The raw summary shows EditorBehaviorFeature now recomputes flags when language-server modification counts change, which addresses this race. The title uses the 'fix:' prefix and is specific. It is somewhat long (100 characters) but remains clear.

Full details: Description check

Explanation

The description explains the bug (CI failures in LSPSemanticTokenDocumentationProviderTest), its cause (CachedValue reading dependency counts after computation), the fix (reading counts before computing and recomputing on change), the behaviour change, and the tests added. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #2157 requires that editor-behavior flags be recomputed when a language server starts during their computation. At head, EditorBehaviorFeature.compute() reads the TrackerCount values (via languageServiceAccessor.getModificationTrackers(file)) before calling languageServiceAccessor.hasAny(...). FlagValue.isUpToDate() returns false when any recorded count changed, so the next isEnabled() call recomputes the flag. This covers the requirement that a flag computed while a server starts is not kept as false. The flags covered include isEnableSemanticTokensFileViewProvider, isEnableStringLiteralImprovements, isEnableStatementTerminatorImprovements, isEnableEnterBetweenBracesFix and isEnableTextMateNestedBracesImprovements, all served by the same isEnabled path. Files without a VirtualFileWithId are computed on every call, as the issue does not require caching for them. The new test EditorBehaviorFeatureTest.testAFlagThatChangesWhileItIsComputedIsComputedAgain simulates a tracker change during the first computation and asserts that the second call recomputes and returns true. Its assertion would fail under the former CachedValue behavior, where counts were read after computation. The issue's narrow race is not reproduced in this environment, so the CI reproduction is not re-run here. The code and test evidence still support the fix.

Full details: Out of Scope Changes check

Explanation

The change set, as listed in the raw summary, touches only src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java (+70/-23) and the new src/test/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeatureTest.java (+84). Both files are directly tied to the race described in #2157: the first replaces the CachedValue caching with count-before-compute caching, and the second tests that behavior. The public method signatures in EditorBehaviorFeature are unchanged according to the summary. No unrelated change was identified. The file list was taken from the raw summary; a complete file-level diff against the merge base was not inspected, so this conclusion depends on that summary being complete.

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: 98e01818-5e8a-410b-8020-ed0885a89c79
Commits

Reviewing files that changed from the base of the PR and between 53fd2f9 and 6f06fd4.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java
  • src/test/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeatureTest.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 80.76923% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.23%. Comparing base (11be81a) to head (6f06fd4).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../lsp4ij/client/features/EditorBehaviorFeature.java 80.76% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2159      +/-   ##
==========================================
+ Coverage   53.22%   53.23%   +0.01%     
==========================================
  Files         826      826              
  Lines       34717    34744      +27     
  Branches     7143     7151       +8     
==========================================
+ Hits        18477    18495      +18     
- Misses      13468    13479      +11     
+ Partials     2772     2770       -2     

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

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

Labels

bug Something isn't working hover semantic tokens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A file opened while its language server starts can keep the editor behavior of a file that no language server serves (no Ctrl+hover on semantic tokens)

1 participant