Skip to content

fix: a restart of a file's highlighting is no longer lost when the daemon applies a pass that it cancels - #2357

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/restart-on-the-edt
Nov 30, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/restart-on-the-edt

Conversation

@lagergren

@lagergren lagergren commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2356, fixes #2363, for 0.30.3. Two fix: commits, to be rebase-merged.

The bug

A restart of a file's highlighting that LSP4IJ asks for, as for workspace/semanticTokens/refresh, workspace/inlayHint/refresh or workspace/codeLens/refresh, could be lost. The file then kept its old highlighting until the next edit.

LSPFileSupport called DaemonCodeAnalyzer.restart(file) in a non-blocking read action, so on a background thread. The daemon applies a pass on the EDT once it has checked that the pass isn't cancelled, so the restart could come between the check and the apply. The pass it cancelled was then applied anyway. When it was the EmptyPass of a pass that had nothing to do, it marked the file as highlighted again, which erased the restart's dirty mark.

It turned up in the macOS job of #2338, whose new SemanticTokensRefreshTest waits for a refresh while the daemon runs by its timer. #2356 has that test's log, in which the EmptyPass of the general highlighting pass is applied after the restart cancelled it.

The fix

restart now runs on the EDT, in the finishOnUiThread of the same non-blocking read action, which keeps its debounce and coalescing. It doesn't restart a file that is no longer valid by then.

A @TestOnly hook, setRestartHook, runs right after the restart, as setRestartDebounce lets a test set the debounce.

The second fix (#2363)

action.inSmartMode(project) discarded the copy that it returns, as each method of NonBlockingReadAction returns a new action, so a restart that came while the project was indexed ran at once, since 0.13.0. It now waits for the end of indexing, as the code meant: action = action.inSmartMode(project). Little changes for the user: during indexing, the daemon runs only the dumb-aware passes, and it restarts the highlighting of every file once indexing ends. A @TestOnly getter, getLastRestart, gives a test the restart that the debounce submitted.

Checked

  • New test: LSPFileSupportRestartThreadTest checks that the restart runs on the EDT. With the restart in the background read action, as before, it fails with "The highlighting must restart on the EDT".
  • New test for The restart of a file's highlighting doesn't wait for the end of indexing, as it means to: inSmartMode's result is dropped #2363: LSPFileSupportRestartWhileIndexingTest requests a restart in dumb mode. Once a non-blocking action submitted after it has run, the restart must still be pending, and it must run once indexing ends, in smart mode. Without the fix, it failed 3 times out of 3 with "The restart must wait for the end of indexing". With it, it passes on IC 2024.2, IC 2025.3 and IU 2026.3, with LSPFileSupportRestartThreadTest.
  • Headless, as the Linux CI jobs run, with the counts from the JUnit XMLs:
Platform Run Result
IC 2024.2 (default) the whole test suite, as every restart of the highlighting now runs on the EDT 2,654 tests, 0 failed, 7 skipped
IC 2025.3 LSPFileSupportRestartThreadTest, CodeActionsOnTheEdtTest 5 tests, 0 failed
IU 2026.3 the same two 5 tests, 0 failed

…emon applies a pass that it cancels

LSPFileSupport restarted the daemon for a file in a non-blocking read
action, so on a background thread. The daemon applies a pass on the EDT
once it has checked that the pass isn't cancelled, so a restart could come
in between: the pass it cancelled was applied anyway, and when it had
nothing to do, its EmptyPass marked the file as highlighted again, which
erased the restart's dirty mark. The file then kept its old highlighting,
as the semantic tokens of a workspace/semanticTokens/refresh, until the
next edit.

The restart now runs on the EDT, in the finishOnUiThread of the same
non-blocking read action, which keeps its debounce and coalescing.

Fixes redhat-developer#2356
@lagergren lagergren added this to the 0.30.3 milestone Nov 28, 2026
@lagergren lagergren added the bug Something isn't working label Nov 28, 2026
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Highlighting refreshes now wait until indexing is complete, then run when the file is still valid and the refresh is needed. Rapid repeat requests are combined, helping avoid redundant refreshes. Refreshes are also completed on the UI thread without blocking it, improving consistency and responsiveness during editing and project indexing.

The debounced highlighting restart now runs on the UI thread after its cancellation check. In dumb mode, it waits for smart mode. New tests check EDT execution and restart behavior during indexing.

Changes: Debounced highlighting restart

Layer / File(s) Summary
UI-thread restart and smart-mode gating
src/main/java/com/redhat/devtools/lsp4ij/LSPFileSupport.java
The restart runs on the UI thread only when the cancellation check succeeds and the file is valid. In dumb mode, the action is reassigned to the smart-mode action before submission. A hook and promise accessor expose restart state for tests.
Thread and indexing behavior tests
src/test/java/com/redhat/devtools/lsp4ij/LSPFileSupportRestartThreadTest.java, src/test/java/com/redhat/devtools/lsp4ij/LSPFileSupportRestartWhileIndexingTest.java
Tests check that the restart hook runs on the EDT and that a restart requested during indexing runs after smart mode resumes.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 5c20c

This change fixes lost highlighting restarts and makes restarts wait for indexing to finish. Tests cover both behaviors. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a file's highlighting restart is no longer lost when the daemon cancels and then applies a pass. The changeset moves the restart to the EDT in finishOnUiThread, which …
Description check Passed The description explains the lost-restart bug, the fix (restart moved to the EDT in finishOnUiThread, with a @TestOnly setRestartHook), the second fix for the dropped inSmartMode action (#2363), the n…
Linked Issues check Passed [#2356] The change moves the highlighting restart out of the background read action into finishOnUiThread of the same non-blocking read action, so DaemonCodeAnalyzer.restart(file) runs on the EDT. The…
Out of Scope Changes check Passed All changes relate to #2356 or #2363. The change in LSPFileSupport.java covers the EDT restart and the inSmartMode fix. The @TestOnly members setRestartHook, getLastRestart and the restart-debounce se…
Full details: Title check

Explanation

The title names the main change: a file's highlighting restart is no longer lost when the daemon cancels and then applies a pass. The changeset moves the restart to the EDT in finishOnUiThread, which addresses this bug. The title is specific and accurate. It is long (104 characters), but it does not fail the check.

Full details: Description check

Explanation

The description explains the lost-restart bug, the fix (restart moved to the EDT in finishOnUiThread, with a @TestOnly setRestartHook), the second fix for the dropped inSmartMode action (#2363), the new tests, and the test results. It matches the changeset and the linked issues.

Full details: Linked Issues check

Explanation

[#2356] The change moves the highlighting restart out of the background read action into finishOnUiThread of the same non-blocking read action, so DaemonCodeAnalyzer.restart(file) runs on the EDT. The debounce and per-file coalescing are kept. The restart is skipped when the file is no longer valid. This matches the requested fix. The new LSPFileSupportRestartThreadTest asserts that the restart hook runs on the EDT. The PR reports that it fails when the restart stays in the background read action.

[#2363] When the project is in dumb mode, the change applies the smart-mode requirement with action = action.inSmartMode(project), so the submitted action keeps the smart-mode condition. This matches the requested fix. The new LSPFileSupportRestartWhileIndexingTest checks that a restart requested in dumb mode stays pending until indexing ends and then runs in smart mode. The PR reports that it failed 3 of 3 times without the fix.

Limit: the LSPFileSupport.java blob at head was readable, but the restart method lies past the 16000-byte read limit. The diff read was unavailable. The verdict relies on the PR summary and the test descriptions, which are specific and consistent with the issue text. The test results are reported by the author and were not re-run.

Full details: Out of Scope Changes check

Explanation

All changes relate to #2356 or #2363. The change in LSPFileSupport.java covers the EDT restart and the inSmartMode fix. The @TestOnly members setRestartHook, getLastRestart and the restart-debounce setter are test hooks that the new tests need to observe the restart. The two new test classes cover the two issues. No unrelated production behavior change appears in the summary. The PR description and the summary do not list changes outside LSPFileSupport.java and the two new tests. The limit noted in the linked-issue assessment also applies here: the full diff was not readable at the restart method, so this verdict relies on the summary.

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: f99bedfd-d49f-4088-96ec-b049f34ece6e
Commits

Reviewing files that changed from the base of the PR and between 0665956 and 5c20caf.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/LSPFileSupport.java
  • src/test/java/com/redhat/devtools/lsp4ij/LSPFileSupportRestartThreadTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/LSPFileSupportRestartWhileIndexingTest.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 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.85%. Comparing base (0665956) to head (5c20caf).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...ava/com/redhat/devtools/lsp4ij/LSPFileSupport.java 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2357      +/-   ##
==========================================
+ Coverage   58.63%   58.85%   +0.22%     
==========================================
  Files         849      849              
  Lines       36719    36727       +8     
  Branches     7609     7610       +1     
==========================================
+ Hits        21530    21616      +86     
+ Misses      12187    12099      -88     
- Partials     3002     3012      +10     

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

…is indexed waits for the end of indexing

LSPFileSupport.restartDaemonCodeAnalyzerWithDebounce meant the restart to wait for smart mode, but called
action.inSmartMode(project) without keeping its result: each method of NonBlockingReadAction returns a new action, so the
restart ran during indexing too, as it did since 0.13.0. It now waits. The daemon runs only the dumb-aware passes during
indexing, and restarts the highlighting of every file once indexing ends, so the restart during indexing was work for
nothing.

Fixes redhat-developer#2363
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 30, 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 a470eb9 into redhat-developer:main Nov 30, 2026
13 checks passed
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

1 participant