Repository navigation
feat: the first highlighting of a file shows the semantic tokens of its visible range while those of the whole file are computed - #2380
Conversation
…ts visible range while those of the whole file are computed When the semantic tokens of the whole file haven't come after 100 ms, the first highlighting of a file that is not visible whole asks the language servers that have both full and range requests for the semantic tokens of its visible range, as VS Code does, shows them if they come first, and restarts once those of the whole file come. Fixes redhat-developer#2240
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2380 +/- ##
==========================================
+ Coverage 59.77% 59.80% +0.03%
==========================================
Files 858 858
Lines 37428 37495 +67
Branches 5883 7776 +1893
==========================================
+ Hits 22373 22425 +52
- Misses 11991 11997 +6
- Partials 3064 3073 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
Action performed
|
|
@coderabbitai About the inconclusive "Linked Issues" check: the two other parts of #2240 are already on
|
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
Both cited tests are also present. I inspected them but did not run them. This resolves the two unknowns behind the saved inconclusive assessment. I did not rerun the check, so this reply does not update its saved result. You are interacting with an AI system. |
Fixes #2240.
When a large file opens, its semantic colors wait for the language server's first
textDocument/semanticTokens/fullanswer, which takes a while on a large file. VS Code asks for the visible part of the file meanwhile, withtextDocument/semanticTokens/range. LSP4IJ now does the same.#2338 already handles #2240's other case: a language server with semantic tokens for a range only gets the range of the whole file.
What changes
fullandrangeare asked, and only when every language server with semantic tokens for the file has both. The answer comes from the same language server as for the whole file: the first one, in the order of the mappings, that answers with tokens.AnnotationSession.getPriorityRange(), which is public and not deprecated from 2024.2 to 2026.3.restartDaemonCodeAnalyzerForSemanticTokensRefresh, so they replace them;docs/LSPSupport.mdanddocs/UserGuide.md. The User Guide's "not supported yet" now names the one thing missing: asking again when the editor scrolls before the whole file has come.Behaviour changes
rangetoo, when the whole file takes more than 100 msfulland arange, when thefullone takes more than 100 ms and the file isn't visible wholeLive check
Decoding. Range tokens decoded from the start of the file were compared with the full tokens of the same lines:
Timing. rust-analyzer on a 12,000-line Rust file, right after an edit, with both requests sent at once:
rangefor the first 40 lines: 67 ms, 356 tokens;full: 446 ms, 105,026 tokens.With the 100 ms wait, the visible lines get their colors about 250 ms sooner.
Tests
SemanticTokensVisibleRangeTest, with the mock language server and an editor that shows 5 of the file's 40 lines (EditorTestUtil.setEditorVisibleSize):fullanswer: the visible range shows first. Its request covers the visible lines only. While the daemon runs, the whole file's tokens replace it without an edit;rangeis asked for the whole file only;The existing semantic tokens tests pass unchanged, since their language servers answer within 100 ms.
mainwith feat: semantic tokens ask a language server that has delta for the edits since its last answer #2377 squashed in, the semantic tokens tests pass again, 107 tests.