fix(lsp): request semantic highlighting when a file opens (#6706)

The first semantic-tokens request waited for the 600 ms edit debounce, so a newly opened file showed only syntax colours and then changed colour. The view now requests tokens as soon as it opens; edits still refresh through the debounce.

Co-authored-by: zhzhsx <[email protected]>
Цей коміт міститься в:
zhzhsxтаzhzhsx authored and GitHub committed 2026-11-28 20:09:32 +08:00
1 джерело 8aeac949b5
коміт 99fdea5c9a
2 files changed
+9 -5

No files matched your search

+5 -3
Переглянути файл
@@ -1,8 +1,8 @@
/**
* Semantic highlighting: `lsp_semantic_tokens` → mark decorations with
* `cm-sem-*` classes (styled with the --syn-* tokens) layered over the Lezer
* highlighting. Refreshed after edits (debounced); in between, existing marks
* are mapped through the changes.
* highlighting. The view requests tokens as soon as it opens; edits refresh
* them after a debounce, and existing marks are mapped through the changes.
*
* Semantic highlighting (Color Scheme › Language Defaults, IDEA's rainbow
* identifiers): local variables and parameters additionally get
@@ -232,8 +232,10 @@ const semanticPlugin = ViewPlugin.fromClass(
queueMicrotask(() => {
if (!this.destroyed) this.decorate(this.view.state.doc, null);
});
this.refresh();
this.offReady = onLspRefresh("semanticTokens", () => this.refresh());
// Requests semantic tokens while the view opens.
// Later refreshes still use the debounced `refresh`.
void this.run();
}
update(u: ViewUpdate) {
const tree = syntaxTree(u.state);
+4 -2
Переглянути файл
@@ -35,10 +35,11 @@ describe("semantic colours while typing", () => {
});
try {
await vi.advanceTimersByTimeAsync(0);
expect(requests).toHaveLength(1);
expect(view.dom.querySelector(".cm-sem-python-builtin")).toBeNull();
view.dispatch({ changes: { from: view.state.doc.length, insert: "nt(x)" } });
await vi.advanceTimersByTimeAsync(0);
expect(requests).toHaveLength(0);
expect(requests).toHaveLength(1);
expect(view.dom.querySelector(".cm-sem-python-builtin")?.textContent).toBe("print");
expect(view.dom.querySelectorAll(".cm-sem-parameter")).toHaveLength(2);
} finally {
@@ -57,7 +58,8 @@ describe("semantic colours while typing", () => {
}),
});
try {
await vi.advanceTimersByTimeAsync(600);
await vi.advanceTimersByTimeAsync(0);
expect(requests).toHaveLength(1);
requests.shift()!({
tokenTypes: ["function", "parameter"],
tokenModifiers: ["defaultLibrary"],