Full semantic highlighting

I’m currently trying to implement a LSP client and have been using clangd as the server. One thing I noticed while debugging was that clangd responds to semanticToken requests with only tokens for variables, classes, etc. but not for keywords, comments, and strings. I’ve been using the latest clangd 11.0, and I haven’t found an option to enable it anywhere (in extensions and configuration), and I’ve also tried adding all token types and modifiers when sending the initialize request, but the returned tokens do not seem to change. Since LSP does have token types for these, it would be nice to have the option at least to have clangd return all tokens. Moreover, since clangd already have the full AST, adding that information should not cause much additional cost aside from transferring the additional tokens.

The general practice with LSP seems to be that highlightings which don’t require a semantic model of the code (I call these “lexical highlightings”, as they require only lexer-level processing of the code) are done on the client side, and this is what clangd does as well.

That said, I think clangd would likely accept a patch to return lexical highlightings behind a non-default option.

Thanks for the reply. It does seem a bit redundant to have two different highlighters, but it makes sense since LSP is usually much slower.

I have one more (unrelated) question though: is there a way for me to test if I’ve handled text synchronization correctly? I don’t see an option to retrieve the full document back from LSP, but at the same time, it’s hard to know if the deltas I sent to the server are correct.

I’m not sure. You may want to start a new thread to give that question more visibility, or ask in the #clangd Discord channel.

Thanks, I’ll try that.