Skip to content

LSP features return nothing while LSP4IJ's indexing flags lag behind the platform (seen as a flaky LSPSemanticTokenDocumentationProviderTest) #2141

Done

Description

@muescha

Summary

LSP4IJ asks the platform whether a project is indexing through two flags of its own (scanning, dumbIndexing in ProjectIndexingManager). A listener on the internal ProjectIndexingActivityHistoryListener sets them, and its events can come after the platform has finished indexing. In that window, LSP4IJ still counts the project as indexing, and each LSP feature behind this check returns nothing, without an error.

  • In the IDE this is rarely felt: right after indexing, a hover or a completion may come back empty once.
  • In the tests it can make a test fail that asks a feature right after it opened a file in a new project. That is most likely what happened in the failure below. It happened once; a rerun passed.

So this is not urgent. It is worth fixing because the same check is in front of 26 features, and the long-term fix (#683) would remove the window in the IDE too. The cause is inferred from the CI log, not proven: see Open points.

The failure

LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers failed once in the Test (ubuntu-latest, 2026.3) job (run, commit ab2a8ea). All other jobs of the run passed:

junit.framework.AssertionFailedError
    at ...LSPSemanticTokenDocumentationProviderTest.getHintText(LSPSemanticTokenDocumentationProviderTest.java:162)

Line 162 is assertNotNull(hintText): getQuickNavigateInfo() returned null, so there was no hint at all, not a wrong one.

A rerun of the job passed. The same commit passes locally on IntelliJ IDEA 2026.3 (IU) too: the whole class once, and the single test 10 times in a row. So it is a rare race, not a failure on every run.

What the CI log shows

The test report of the job (tests-result-Linux-2026.3) holds the IDE log of the failed test. On 2026.3 each test opens a project of its own:

Time Event
27,548 project testPlainTextOfTwoLanguageServers is opened
27,571–27,576 scanning on project open
27,580 exit dumb mode
27,608–27,619 dumb mode again ("Push on VFS changes")
27,634 fileOpened test.ts
27,644–27,658 myFixture.doHighlighting() of initialize(), the semantic tokens come in
27,662 test failed

Only 3–4 ms pass between the end of the highlighting and the failure. That is too short to ask two language servers (one of them added just before) and wait for both replies. So the hover was given up early, without a timeout and without an error. The log has no output of LSP4IJ itself.

Where null comes back that fast

LSPSemanticTokenDocumentationProvider.getDocumentation() returns null if LSPDocumentationTargetProvider.getHoverTargets() returns no targets. requestHover() sends no request at all if:

  • DumbService.isDumb(project). The log shows the project was not in dumb mode at that time.
  • ProjectIndexingManager.canExecuteLSPFeature(psiFile) != NOW. That is the case while isIndexingAll() is true, i.e. while scanning or dumbIndexing is set for any open project.

These two flags are not read from the platform. They are set by ProjectIndexingDumbAndScanningStrategy, a reflection proxy on the internal ProjectIndexingActivityHistoryListener. Its onFinishedScanning / onFinishedDumbIndexing events come with the indexing history and may arrive after the platform has ended scanning and dumb mode. The project was about 110 ms old. If one of these events had not arrived yet, the file counted as AFTER_INDEXING. Then no hover was sent, there was no hint, and assertNotNull failed.

Ruled out:

  • No semantic tokens yet. assertInstanceOf(element, LSPSemanticTokenPsiElement.class) in line 160 passed, and the highlighting had finished.
  • Only the second server was not ready. Then the text of the first server would still be there, and the test would fail at contains("Third line<br>Fourth line"), not at assertNotNull.
  • Timeout or ProcessCanceledException. That would take much longer than 3 ms.
  • The asynchronous LSPFileSupport.dispose() when a server stops (LanguageServerWrapper.disposeFileSupports), which would cancel the hover too. It affects the files of the previous test, which belong to a project that was already closed.

Does this happen elsewhere?

In the code: yes, the same gate is in front of 26 features, nearly every LSP feature: hover, completion, semantic tokens, folding, inlay hints, code lens, formatting, code actions, go-to, find usages, hierarchies, structure view and the DAP variable positions, among others. Each returns nothing, without an error, while the flags are set. grep -rn "canExecuteLSPFeature\|isIndexingAll" src/main finds them all.

All 26 checks
Feature Check
Hover / Ctrl+hover documentation LSPDocumentationTargetProvider
Completion LSPCompletionContributor
Semantic tokens LSPSemanticTokensHighlightVisitor
Folding LSPFoldingRangeBuilder
Inlay hints AbstractLSPInlayHintsProvider
Declarative inlay hints AbstractLSPDeclarativeInlayHintsProvider
Code lens LSPCodeLensProvider
Document links LSPDocumentLinkCollector
Code actions LSPLazyCodeActionIntentionAction
Intentions LSPIntentionAction
Formatting AbstractLSPFormattingService
On-type formatting (server side) LSPServerSideOnTypeFormattingHelper
On-type formatting (client side) LSPClientSideOnTypeFormattingTypedHandler
Go to declaration / implementation / type definition AbstractLSPGoToAction
Highlight usages LSPHighlightUsagesHandlerFactory
Target element (Ctrl+click) LSPTargetElementEvaluator
Find usages LSPFindUsagesHandlerFactory
Usage targets LSPUsageTargetProvider
Call / type hierarchy LSPHierarchyProviderBase
Structure view LSPDocumentSymbolStructureViewFactory
Structure view (refresh) LSPDocumentSymbolStructureViewModel
Selection range (extend selection) LSPSelectionRangeSupport
Linked editing LSPLinkedEditingRangeSynchronizer
Workspace symbols: implementations LSPWorkspaceImplementationsSearch
Workspace symbols: type declarations LSPWorkspaceTypeDeclarationProvider
DAP: positions of variables LSPDebugVariablePositionProvider

In the tests: possible in any of them. 127 test classes are based on a code insight fixture. Each test that asks one of these features right after it opened a file in a new project can lose the same race. So the fix below belongs in the shared base class, not only in this one test.

In CI: not seen so far. In the last 40 failed ci.yml runs of this repository, no other failure clearly has this cause. The other flaky tests fail on server restarts, DAP sessions, a PSI leak (testGoToDefinitionWorksInTheContentOfTheServer) or file moves. GoToActionReportTest failed on 2025.3 and 2026.3 in the same run of one branch, which points to that branch's change, not to a race. This is the first time this failure showed up.

In the IDE: small. Right after indexing, a hover or a completion may come back empty once. The next try works. The editor features that LSP4IJ refreshes once indexing ends (filesToRefresh) catch up by themselves; a hover or a completion that the user asked for does not.

Proposed fix

1. Tests: wait for LSP4IJ's own indexing state

The platform's test fixture already waits for indexing when it opens a file (IndexWaiter in the log at 27,636). It does not know LSP4IJ's flags. So the wait belongs next to it, in the fixture that LSP4IJ's tests share.

A helper that any test can call (new, e.g. src/test/java/com/redhat/devtools/lsp4ij/fixtures/LSPIndexingTestUtil.java):

public final class LSPIndexingTestUtil {

    private LSPIndexingTestUtil() {
    }

    /**
     * Waits until LSP4IJ no longer counts any project as indexing.
     * <p>
     * Its flags follow the indexing history events, which can come after the platform has left dumb mode. Until
     * then {@link ProjectIndexingManager#canExecuteLSPFeature} is not {@code NOW}, and each LSP feature returns
     * nothing. This dispatches events while it waits, so an event delivered on the EDT cannot deadlock.
     */
    public static void waitUntilLSP4IJIsNotIndexing() {
        PlatformTestUtil.waitWithEventsDispatching(
                "LSP4IJ still counts a project as indexing: " + ProjectIndexingManager.isIndexingAll(),
                () -> !ProjectIndexingManager.isIndexingAll(), 10);
    }
}

ProjectIndexingManager.waitForIndexingAll().get() is no option here: it blocks the EDT, and it polls only once a second.

Called once, where the tests open their file. The tests open their files through LSPCodeInsightTestFixtureImpl, which extends CodeInsightTestFixtureImpl, and nearly always with configureByText (156 calls). One override there is enough:

@Override
public PsiFile configureByText(@NotNull String fileName, @NotNull String text) {
    PsiFile file = super.configureByText(fileName, text);
    LSPIndexingTestUtil.waitUntilLSP4IJIsNotIndexing();
    return file;
}

One wait after the file is opened covers both windows in the log: the scanning of the new project, and the dumb mode that creating the file can start ("Push on VFS changes"). A wait in setUp() as well would add nothing. The few tests that open a file in another way (openFileInEditor, 12 calls) or that are not based on this fixture call the helper themselves.

For the failing test, the wait then happens in initialize(), right before the hover is asked.

2. Longer term: read the platform's state instead of mirroring it (#683)

The window exists because ProjectIndexingManager.isIndexing() reads two flags that a listener on the internal ProjectIndexingActivityHistoryListener sets later:

public boolean isIndexing() {
    return scanning || dumbIndexing || DumbService.isDumb(project);
}

#683 says that since 2024.3 DumbService.runWhenSmart waits for scanning too. Where the platform covers scanning that way, LSP4IJ can ask it directly and needs no flags. A sketch:

/** Since 2024.3, smart mode waits for scanning too, see #683. */
private static final boolean SMART_MODE_WAITS_FOR_SCANNING =
        ApplicationInfo.getInstance().getBuild().getBaselineVersion() >= 243;

public boolean isIndexing() {
    if (SMART_MODE_WAITS_FOR_SCANNING) {
        // The platform's own state: no listener, no lag behind it
        return DumbService.isDumb(project);
    }
    // 2024.2 (pluginSinceBuild=242): keep the flags of the history listener
    return scanning || dumbIndexing || DumbService.isDumb(project);
}

And the refresh of the files that waited for indexing (filesToRefresh, today in ProjectIndexingStrategyBase.refreshEditorsFeaturesIfNeeded) would be scheduled when a feature is deferred, not by the history events:

private static @NotNull ExecuteLSPFeatureStatus doCanExecuteLSPFeature(@Nullable VirtualFile file,
                                                                       @NotNull Project project) {
    ProjectIndexingManager manager = getInstance(project);
    if (isIndexingAll()) {
        if (manager.filesToRefresh.add(file) && SMART_MODE_WAITS_FOR_SCANNING) {
            // Refresh the editors of the waiting files once the project is smart again; refreshEditorsFeatures()
            // would be today's ProjectIndexingStrategyBase.refreshEditorsFeaturesIfNeeded(), moved here
            DumbService.getInstance(project).runWhenSmart(manager::refreshEditorsFeatures);
        }
        return ExecuteLSPFeatureStatus.AFTER_INDEXING;
    }
    return ExecuteLSPFeatureStatus.NOW;
}

isIndexingAll() and waitForIndexingAll() stay as they are; they read isIndexing(). On 2024.3+ ProjectIndexingDumbAndScanningStrategy (the reflection proxy) would no longer be needed.

To be checked before this is done: that DumbService.isDumb() on 2024.3+ is true during the whole scanning, not only runWhenSmart. The log of the failure suggests so (DumbModeWhileScanningSubscriber is one of the tasks required for smart mode, and "exit dumb mode" comes after "Scanning completed"), but it was not checked in the platform sources.

With part 2, part 1 would no longer be needed: the features would check DumbService.isDumb(), which the platform's test fixture already waits for (IndexWaiter). So part 1 is a small stopgap for the tests, worth it only if this or a similar test fails again before part 2 is done.

Open points

  • That the history events really come late on 2026.3 is inferred from the timing, not checked in the platform sources. A LOGGER.debug in requestHover() that names the reason for null (dumb, AFTER_INDEXING, no file, no document) would make the next failure clear.
  • Why only the 2026.3 job failed is open. It may be a different delivery of the history events, or just timing.

How this was checked

Found by reading the code and the CI log with Claude Code. The failure was not reproduced:

  • The CI log and the test report of the failed job, with the IDE log of the test (timestamps above).
  • The same commit locally with ./gradlew test -PplatformVersion=2026.3 -PplatformType=IU: the whole class once, and the single test 10 times with --rerun. All passed (10–17 s each).
  • gh run view --log-failed of the last 40 failed ci.yml runs of redhat-developer/lsp4ij, for the names of the failed tests.

Pair-programmed with ❤️ by @muescha and ⚙️ by 🤖 Claude Code

Activity

  1. muescha commented on Nov 23, 2026

    @muescha
    ContributorAuthor

    The CI run and its test report will expire, so here are the log lines behind the timeline in the issue, from the IDE log of the failed test (job Test (ubuntu-latest, 2026.3), commit ab2a8ea):

    IDE log of testPlainTextOfTwoLanguageServers, from project open to the failure
    05:23:27,548 INFO   .ide.impl.GlobalWorkspaceModel - Project testPlainTextOfTwoLanguageServers is added to the list of initializing and open projects 
    05:23:27,571 INFO   indexing.UnindexedFilesScanner - [testPlainTextOfTwoLanguageServersecf01f60] Started scanning for indexing of [testPlainTextOfTwoLanguageServers]. Reason: On project open 
    05:23:27,574 INFO   indexing.UnindexedFilesScanner - [testPlainTextOfTwoLanguageServersecf01f60] Scanning completed for [testPlainTextOfTwoLanguageServers]. Number of scanned files: 324; ...
    05:23:27,580 INFO   penapi.project.DumbServiceImpl - exit dumb mode [testPlainTextOfTwoLanguageServers] 
    05:23:27,603 FINE   penapi.project.DumbServiceImpl - Scheduling task com.intellij.openapi.roots.impl.PushedFilePropertiesUpdaterImpl$MyDumbModeTask@7c211b87 (reason: Push on VFS changes) 
    05:23:27,608 INFO   penapi.project.DumbServiceImpl - enter dumb mode [testPlainTextOfTwoLanguageServers] 
    05:23:27,619 INFO   penapi.project.DumbServiceImpl - exit dumb mode [testPlainTextOfTwoLanguageServers] 
    05:23:27,634 INFO   s.BeforeFileOpenLoggerListener - fileOpened test.ts 
    05:23:27,638 FINE   ij.psi.impl.source.PsiFileImpl - Loaded text for file /tmp/unitTest_plainTextOfTwoLanguageServers_3MUiB0zLpWI9hQUVlQeNajy5eGY/unitTest17522515691139876062/test.ts 
    05:23:27,658 FINE   n.impl.DaemonProgressIndicator - stop(1907211367V) 
    05:23:27,659 FINE   lighting.BackgroundHighlighter - waitForIdentifierHighlighting(EditorImpl[...test.ts]): waited null 
    05:23:27,662 SEVERE                 #TestFramework - Test failed 
    
    Failure in the test report
    junit.framework.AssertionFailedError
    	at junit.framework.Assert.assertNotNull(Assert.java:256)
    	at junit.framework.TestCase.assertNotNull(TestCase.java:391)
    	at com.redhat.devtools.lsp4ij.features.semanticTokens.viewProvider.LSPSemanticTokenDocumentationProviderTest.getHintText(LSPSemanticTokenDocumentationProviderTest.java:162)
    	at com.redhat.devtools.lsp4ij.features.semanticTokens.viewProvider.LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers(LSPSemanticTokenDocumentationProviderTest.java:138)
    

    The log has no output of LSP4IJ itself, so it shows when the platform was done, not when LSP4IJ's flags were cleared.

  2. lagergren commented on Nov 23, 2026

    @lagergren
    Collaborator

    @muescha The failure in this issue very likely has another cause, which is now proven and fixed: #2157, with the fix in #2159.

    The cause: EditorBehaviorFeature caches, for each file, the flag that turns on the semantic tokens-based file view provider. The cache was a CachedValue that reads the language servers' modification counts after computing the flag. When the file's language server starts during that computation, the flag stays false. Highlighting then keeps no semantic token in the view provider. Adding the second server turns the provider on again, but with an empty token map.

    Why it matches your failure:

    • Line 160 passes: the element at the caret is the whole-file stub token, which is an LSPSemanticTokenPsiElement.
    • Line 162 fails: isIdentifier is UNSURE, so the hint is null at once, with no timeout and no error. That fits your 3–4 ms after the highlighting.

    The evidence:

    • A 500 ms pause inside that computation makes 12 of the class's 15 tests fail on main, and none with the fix.
    • Under load on 2024.2, the class failed 10 times in 5,600 runs without the fix, and 0 times in 4,800 runs on macOS and 2,000 on Linux with it.
    • The same failure shows on CI in runs 45191503838 (2025.3) and 42039103612 (2024.2).

    What this doesn't show is whether the window of the indexing flags that you describe also happens. The fix wasn't run under load on 2026.3, where each test opens a project of its own. Whether to keep this issue open for the indexing flags is your call.

  3. lagergren commented on Nov 25, 2026

    @lagergren
    Collaborator

    Closing: the failure behind this issue is fixed by #2159 (6e6d7cb9, for 0.30.2). As explained above, EditorBehaviorFeature could keep the semantic-tokens view provider off for a file opened while its language server starts.

    The indexing-flag window described here was never shown to cause a failure. Running features during indexing is tracked in #683.

  4. added this to the 0.30.2 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions