Repository navigation
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 intoNov 24, 2026
Conversation
… 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
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
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 |
This was referenced Nov 25, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2207
What
LSPHoverSupportkeeps 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.testPlainTextOfTwoLanguageServersfail at times on CI. It failed on #2198's Linux 2025.3 job, right aftertestTheHoverOfALanguageServerWhenTheOtherOneCannotStart, 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
LSPHoverSupportrecords the modification count of the project's language servers when it loads a hover.LanguageServiceAccessoradvances 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.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.features.*tests pass headless on 2024.2: 734 tests, 0 failures, 3 skipped as before.Behaviour change