Skip to content

fix: a hover is asked again once a language server of the project was added, removed, started or stopped, instead of keeping the hovers of the earlier language servers - #2208

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/hover-cache-language-server-changes
Nov 24, 2026

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2207

What

LSPHoverSupport keeps the future of a file's last hover, and gives it again for a hover at the same offset while the file and the project's PSI are unchanged. Whether a language server was added, started or stopped since didn't count. So a hover answered before a second language server of the file was ready kept being given without that server's hover, until the file changed or the caret hovered elsewhere. That applies to Ctrl+hover on a semantic token and to Quick Documentation. The caches are dropped when a language server stops or the file closes, but not when one is added or starts.

It also made LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers fail at times on CI. It failed on #2198's Linux 2025.3 job, right after testTheHoverOfALanguageServerWhenTheOtherOneCannotStart, with only the first server's hover. A probe that hovers, adds a second language server and hovers again at the same offset missed the second hover 9 times out of 10. With the hover cache cleared before the second hover, it missed 0 times.

Change

  • LSPHoverSupport records the modification count of the project's language servers when it loads a hover. LanguageServiceAccessor advances that count when a definition is added or removed, and when a language server changes its status. A hover loaded at another count isn't given again.
  • The count is read before the requests are sent, as the modification stamps are. A language server that starts for this hover makes the next hover ask again, and then ask that server too.
  • LanguageServiceAccessor.getModificationCount() is new and @ApiStatus.Internal.

Only hover changes. The other document features keep their caches as before, since they're refreshed when a language server starts.

Tests

New LSPSemanticTokenDocumentationProviderTest.testTheHoverAtTheSameOffsetAfterALanguageServerIsAddedHasItsHoverToo: it hovers, adds a second language server, and hovers at the same offset again. The second hover has both servers' hovers.

  • Red-green: without the fix, the test fails every time with only the first hover. With it, it passes.
  • The documentation, semantic tokens and hover tests pass headless on IC 2024.2, 2025.3 and IU 2026.3: 58 tests each.
  • All features.* tests pass headless on 2024.2: 734 tests, 0 failures, 3 skipped as before.

Behaviour change

Before After
A hover at the same place, in an unchanged file, gives the hovers of the language servers that answered the first time, even after another language server of the file was added or started It asks the language servers again once one of the project was added, removed, started or stopped, so the new one's hover shows too

… added, removed, started or stopped, instead of keeping the hovers of the earlier language servers

LSPHoverSupport kept the future of the last hover of a file, and gave it
again for a hover at the same offset while the file and the PSI of the
project were unchanged. A language server added, started or stopped since
didn't count: a hover answered before a second language server of the
file was ready kept being given without that server's hover, until the
file changed or the caret hovered elsewhere. The caches are dropped when
a language server stops, or the file closes, but not when a language
server is added or starts.

LSPHoverSupport now keeps the modification count of the project's
language servers when it loads a hover, which LanguageServiceAccessor
advances when a definition is added or removed, and when a language
server changes its status. A hover loaded at another count isn't given
again. LanguageServiceAccessor.getModificationCount() is new, internal.

This also made LSPSemanticTokenDocumentationProviderTest's
testPlainTextOfTwoLanguageServers fail at times on CI, after a test whose
second language server couldn't start.

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

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Hover documentation now refreshes when language servers are added, removed, or change status, so results reflect the current set of active servers.

The change exposes the project-level language-server modification count and uses it to validate cached hover data. A regression test checks hover results before and after adding a second language server at the same file offset.

Changes: Hover cache invalidation

Layer / File(s) Summary
Expose the language-server modification count
src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
Adds getModificationCount(), which returns the project-level modification tracker count.
Invalidate cached hover data after server changes
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPHoverSupport.java, src/test/java/com/redhat/devtools/lsp4ij/features/semanticTokens/viewProvider/LSPSemanticTokenDocumentationProviderTest.java
LSPHoverSupport records the count when it loads hover data and checks that the count has not changed during cache validation. The regression test checks that a hover after adding a second language server includes both servers’ text.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr, d-biehl

Merge Risk: Minimal · up to 6f423

Hover results at the same offset now refresh after a language server is added, removed, started or stopped. No concrete merge-blocking risk was found, and the change is small and easy to revert.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #2207 requires that a hover cached before a project language server is added, removed, started or stopped is not given again. At the reviewed head, LSPHoverSupport.java meets the hover-side part… Provide the body of LanguageServiceAccessor.getModificationCount() and the call sites that advance the modification tracker when a language server starts or stops, for example in LanguageServerWrapper status transitions. Also provide the bo…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title describes the main change: hover results are recomputed when a project language server is added, removed, started, or stopped, instead of reusing hovers from earlier servers. This matches th…
Description check Passed The description is related to the changeset. It explains the hover cache problem in LSPHoverSupport, the new modification count in LanguageServiceAccessor, the new test, and the behaviour change. It i…
Out of Scope Changes check Passed The PR changes three areas: LSPHoverSupport.java (the hover cache check), the new @ApiStatus.Internal getModificationCount() method in LanguageServiceAccessor.java, and a new test in LSPSemanticTokenD…
Full details: Title check

Explanation

The title describes the main change: hover results are recomputed when a project language server is added, removed, started, or stopped, instead of reusing hovers from earlier servers. This matches the LSPHoverSupport cache invalidation via the LanguageServiceAccessor modification count and the added test.

Full details: Description check

Explanation

The description is related to the changeset. It explains the hover cache problem in LSPHoverSupport, the new modification count in LanguageServiceAccessor, the new test, and the behaviour change. It is detailed and on-topic.

Full details: Out of Scope Changes check

Explanation

The PR changes three areas: LSPHoverSupport.java (the hover cache check), the new @ApiStatus.Internal getModificationCount() method in LanguageServiceAccessor.java, and a new test in LSPSemanticTokenDocumentationProviderTest.java. The hover cache change directly implements #2207. The accessor method is the count source that the hover cache requires, so it is connected to the objective. The test verifies the objective. The PR states that other document-feature caches are unchanged, and the readable LSPHoverSupport code shows only hover-specific changes. No unrelated change was found in the readable evidence. Unread hunks, including the accessor's status-change code, were not checked for scope.

Full details: Linked Issues check

Explanation

Issue #2207 requires that a hover cached before a project language server is added, removed, started or stopped is not given again. At the reviewed head, LSPHoverSupport.java meets the hover-side part of this requirement. It reads the count from LanguageServiceAccessor.getModificationCount() before super.load(params) sends the requests, stores that value after load, and adds a count comparison to checkValid(). This matches the stated ordering, so a server that starts during a hover is asked again on the next hover. The required test is named in the PR (testTheHoverAtTheSameOffsetAfterALanguageServerIsAddedHasItsHoverToo). Its body was not read. Two points are not verified. First, the body of getModificationCount() and its increments were not visible: the LanguageServiceAccessor.java read was truncated at 16000 bytes before the method. Second, the code that advances the count when a server starts or changes status was not visible. The readable part shows increments in handleAdded, handleRemoved and handleChanged only. The PR summary states that status changes also advance the count, but that claim was not confirmed in source. The issue expects the accessor's modification tracker to count added, removed, started and stopped servers. Diff reads of both files failed, so no whole-PR diff was available.

Resolution

Provide the body of LanguageServiceAccessor.getModificationCount() and the call sites that advance the modification tracker when a language server starts or stops, for example in LanguageServerWrapper status transitions. Also provide the body of the new test to confirm it hovers, adds a second server, and hovers again at the same offset. With these, the requirement can be assessed.

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: c15dbf1c-0a7c-4c39-a259-44ed8ec76108
Commits

Reviewing files that changed from the base of the PR and between d592c89 and 6f4232f.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPHoverSupport.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/semanticTokens/viewProvider/LSPSemanticTokenDocumentationProviderTest.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 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.64%. Comparing base (1b0b053) to head (6f4232f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2208      +/-   ##
==========================================
+ Coverage   54.59%   54.64%   +0.04%     
==========================================
  Files         834      834              
  Lines       35385    35393       +8     
  Branches     7300     7301       +1     
==========================================
+ Hits        19320    19340      +20     
+ Misses      13223    13210      -13     
- Partials     2842     2843       +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 24, 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 24, 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 6f3b972 into redhat-developer:main Nov 24, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
…nly for the open files of each project, not once more in every other open project (#2225)

Fixes #2224

## What

With several projects open, adding a language server definition started the server in every open project, for the open files of all open projects. When a definition is added, every project's `LanguageServiceAccessor` hears it. Its `checkCurrentlyOpenFiles` went through the open files of every open project (`ProjectManager.getOpenProjects()`), but connected them through its own project. So each file got one instance of the server per open project, and all but one of them had another project's root and workspace folders.

It also made `LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers` fail now and then on Linux CI: 3 of about 520 jobs since 2026-11-23, including #2198 (#2207) and #2222.
- In the CI JVM, the light tests' shared project stays open, so `addSecondServer` started the second server twice.
- Both starts connected to the definition's one `MockLanguageServer`, whose `addRemoteProxy` adds to plain `ArrayList`s. Two concurrent adds threw `ArrayIndexOutOfBoundsException`, and one start failed with `CannotStartServerException`.
- When that was the test project's own start, the hover had only the first server's text.

#2208 fixed a different cause of the same symptom: the hover cache across language-server changes.

## Change

- **`checkCurrentlyOpenFiles`** starts the added definitions only for the open files of the accessor's own project. Each open project's accessor does the same for its own files, as `handleChanged` and `handleRemoved` already only touch their own project's servers.
- **Disposed and default projects** are skipped.

A project whose accessor doesn't exist yet doesn't connect its open files when a definition is added. Before, another project connected them, to a server of that other project. They connect as usual once a feature or an editor of the project uses LSP4IJ.

## Tests

New `ServerAddedWithSeveralOpenProjectsTest` (2 tests). It opens a second project and adds a server while a file is open in one of the two projects. Then it checks two things:
- The file gets its own project's server, with a bounded wait.
- Once the async tasks are done, the other project started none.

Red-green: without the fix, both tests fail every run, with the wrapper that the other project started (`expected:<[]> but was:<[LanguageServerWrapper@…]>`). With the fix, both pass.

Reproduction of the CI failure, with the light project opened first:

| Condition | Runs | Failures | A duplicate server started |
|---|---|---|---|
| Before the fix | 1,000 | 1, the exact CI message | every run |
| After the fix | 1,000 | 0 | never |
| A CI-like Linux suite (the 238 classes that precede it on CI), before the fix | 800 | 0 | 800 of 800 |
| The same, after the fix | 800 | 0 | 0 |

The new class, `features.documentation.*`, `features.semanticTokens.*` and `*Hover*` pass headless on IC 2024.2, 2025.3 and IU 2026.3: 60 tests each. The full suite passes on 2024.2: 2,416 tests, 0 failures, with the 7 skipped tests that were already disabled. Rebased on main at 57bae55, the new class and the hover class pass headless on all three platforms.

Not in this PR: `MockLanguageServer` and `MockTextDocumentService.addRemoteProxy` still aren't thread-safe. A test that starts two connections to one mock at once could still hit the same exception.

## Behaviour change

| Before | After |
|---|---|
| A language server added while several projects are open starts in each open project for the open files of all of them, so each file gets one instance per open project, most of them with another project's root | It starts in each project for that project's own open files only: one instance per file, of the file's own project |
lagergren added a commit that referenced this pull request Nov 27, 2026
…erver has started

testHoverIsAskedForAgainWhenAnotherFileChanges failed on main's Windows job twice
(runs 45990024944 and 45993688265): the second hover, which nothing had changed
for, asked the language server again and got its new answer.

The language server starts in the background when the first file opens. On a
slow runner it was still starting when the first hover was asked for. Since
#2208, LSPHoverSupport records the modification count of the project's language
servers when it sends a hover, and asks again once a server has started or
stopped since. The end of that start therefore made the second hover ask again,
as designed. The project's PSI modification count did not change.

The test now waits for the language server to start before the first hover. The
other tests of the class are not affected: the definition support does not use
the language servers' count, and a start does not change the PSI count.
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.

Hover: a hover cached before a language server was added or started is given again without that server's hover

1 participant