This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Support new semanticTokens request from LSP 3.16.
ClosedPublic

Authored by sammccall on Mar 23 2020, 6:25 PM.

Details

Summary

This is a simpler request/response protocol.

Reference: https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.semanticTokens.proposed.ts

No attempt to support incremental formatting (yet).

Diff Detail

Event Timeline

sammccall created this revision.Mar 23 2020, 6:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2020, 6:25 PM
sammccall updated this revision to Diff 252676.Mar 25 2020, 2:35 PM

Update SemanticHighlighting comment

For some context here, I was doing some digging as Heyward Fann is looking at hooking up our existing syntax highlighting to coc.nvim, and he and Jack Guo (of jackguo380/vim-lsp-cxx-highlight) were asking about the protocol.

The new LSP protocol looks really solid, including better incremental highlight support than the Theia proposal, though this patch doesn't implement incremental yet. (In particular, no sending thousands of re-highlights when inserting a new line). It's also request-response rather than notification-based, which is easier to implement on the server side. Also the VSCode client-side of our highlighting feels like significant technical debt we could be rid of.

So I think we should try to support the new LSP and drop the older Theia one ASAP (clangd 12?), even if semantic highlighting isn't a really high priority for us.

For some context here, I was doing some digging as Heyward Fann is looking at hooking up our existing syntax highlighting to coc.nvim, and he and Jack Guo (of jackguo380/vim-lsp-cxx-highlight) were asking about the protocol.

The new LSP protocol looks really solid, including better incremental highlight support than the Theia proposal, though this patch doesn't implement incremental yet. (In particular, no sending thousands of re-highlights when inserting a new line). It's also request-response rather than notification-based, which is easier to implement on the server side. Also the VSCode client-side of our highlighting feels like significant technical debt we could be rid of.

So I think we should try to support the new LSP and drop the older Theia one ASAP (clangd 12?), even if semantic highlighting isn't a really high priority for us.

Thanks for the summary, sounds a good plan.

The patch is mostly good, just a few nits. I will try to play it with VSCode.

clang-tools-extra/clangd/ClangdLSPServer.cpp
582

nit: shall we explicitly set the rangeProvider to false as we don't support the semantic token range request now.

clang-tools-extra/clangd/Protocol.h
1417

nit: FStatus => Tokens.

clang-tools-extra/clangd/SemanticHighlighting.cpp
449

nit: assert the Tokens is sorted?

452

note that we don't calculate the column offset for InactiveCode token ({(line, 0), (line, 0)}), I think we probably calculate the range with the new implementation, maybe add a FIXME.

489

It seems ok now, but I think for static method, we should set the modifier to static, maybe add a FIXME to support token modifiers

sammccall marked 6 inline comments as done.

Address review comments.

clang-tools-extra/clangd/SemanticHighlighting.cpp
452

Right, yes. Just skipping over them for now, with a fixme.

nridge added a subscriber: nridge.Mar 26 2020, 4:17 PM
hokein accepted this revision.Mar 31 2020, 3:29 AM

Thanks!

This revision is now accepted and ready to land.Mar 31 2020, 3:29 AM
This revision was automatically updated to reflect the committed changes.