lsp 2025-10-18

Hi. This start of the a file seems to throw the semantic tokens off. This is in Calva, so may be some VS Code specific goings-on.

Yeah sounds like outdated analysis, if you change the file I suppose it fix it?

This is a freshly created file where I tried to minimize the repro.

The tokens are completely off in the rest of a larger file too, if it starts like this.

But changing anything (re-analyzing) doesnt fix?

If not, then seems to be a bigger issue and probably a vscode one, try that to understand what's the behavior

Re-analyzing doesn’t fix. The only fix is to remove one of the comment lines above the ignored expression.

Interesting, seems to work for me in emacs

trying on calva

ah I can repro on calva

AFAIC tell its a vscode issue, debugging clojure-lsp tokens look correct from response

We probably should submit an issue to VS Code. However, I understand too little about the subject to formulate a usable issue. 😃

I believe vscode has a way to debug the current face/semantic tokens of a text, maybe that would help

The inspector says that it finds namespace tokens in the line comments.

the point is that I looks like client is not asking for semantic-tokens again, so it uses outdated ones. You can debug that checking when clojure-lsp return semantic tokens client<->server logs

When I adit the file, a request for tokens is sent and a response received:

[Trace - 5:19:31 PM] Sending request 'textDocument/semanticTokens/full - (1888)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/pez/.config/joyride/src/foo.cljs"
    }
}


[Trace - 5:19:31 PM] Received response 'textDocument/semanticTokens/full - (1888)' in 1ms.
Result: {
    "data": [
        3,
        0,
        4,
        10,
        0,
        2,
        4,
        3,
        0,
        0
    ]
}

The file content after edit:

;
;
; 0123456789
#_()
;
(ns foo)

so that data can be interpreted as:

3, 0, 4, 10, 0 - go 3 lines down, 0 chars right, paint 4 chars with color 10/0 (which https://github.com/clojure-lsp/clojure-lsp/blob/79483567a4ff3ca52ddf52d55e58b7d1810f5aa5/lib/src/clojure_lsp/feature/semantic_tokens.clj#L24 color in clojure-lsp), then 2, 4, 3, 0, 0 - go 2 more lines down, 4 chars right, paint 3 chars with color 0/0 (namespace color)

I may be wrong off by one or something, but looks correct from clojure-lsp perspective

does that makes sense to you?

Yes. makes sense. I now think the bug is in Calva. We remove comment tokens, since they undo Calva’s dimming of ignored forms. But here we must not be getting the deltas right. Is there a way the clojure-lsp client can exclude a token type from the semantic tokens? That would allow me to remove this filter from Calva.

hum, not really

we would need to add a bunch of ifs

why calva is ignoring comments?

well, you can open the clojure-lsp issue and I will think how to have a config to exclude specific token-types

Because the comment tokens undoes Calva’s dimming of ignored forms. In Calva, ignored forms are not rendered as comments:

Now this issue is fixed in Calva, so at least there is no hurry to filter token types on the clojure-lsp side.

👍 1