…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 |
What
DAPExecutionEpochTest.aRefusalDoesNotWaitWhileARequestOfAnEpochIsWritten(#2201) failed twice, on the Linux 2025.3 CI jobs of #2221 and #2220:resumeRefusedtakes no lock that the test holds: it synchronizes only on its own set, which no other thread of the test holds. ButwaitUntilBlockedOrEndedreturned as soon as the thread wasBLOCKED. A thread is also blocked for a moment on other locks of the JVM, such as a lock of the coverage agent, or of a class that another thread of the test's application loads../gradlew checkruns the whole suite in one JVM with the IDE's threads, which is why it fails on CI and not when the class runs alone. The same helper could also letaResumeWaitsUntilTheRequestOfTheEpochIsWrittenseeBLOCKEDtoo early.Change
Test only. The helper is now
waitUntilBlockedByOrEnded(thread, owner). It counts a thread as blocked only when the lock it waits for is held by the owner (ThreadInfo.getLockOwnerId). The owner is the thread that writes its request with the epoch's lock held. A lock of the JVM held by another thread no longer counts, and no timing is involved.Tests
resumeRefusedchanged to synchronize on the epoch's lock, the test fails (BLOCKED), so it still guards that the reader thread never waits on the lock.DAPExecutionEpochTest(13 tests) passes headless on IC 2024.2, 2025.3 and IU 2026.3. Thedap.*tests pass on 2025.3, headless: 545 tests, 0 failures.