This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Support textDocument/semanticTokens/edits
ClosedPublic

Authored by sammccall on Apr 1 2020, 9:04 AM.

Details

Summary

This returns incremental highlights as a set of edits against the
previous highlights.

Server-side, we compute the full set of highlights, this just saves
wire-format size.

For now, the diff used is trivial: everything from the first change to
the last change is sent as a single edit.

The wire format is grungy - the replacement offset/length refer to
positions in the encoded array instead of the logical list of tokens.
We use token-oriented structs and translating to LSP forms when serializing.
This departs from LSP (but is consistent with semanticTokens today).

Tested in VSCode insiders (with a patched client to enable experimental
features).

Diff Detail

Event Timeline

sammccall created this revision.Apr 1 2020, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2020, 9:04 AM
hokein accepted this revision.Apr 2 2020, 2:15 AM

this is neat, and the new semantic highlighting protocol is much nicer than the old one.

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

nit: add assert(C >= '0' && C <= '9').

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

nit: assert Old and New are sorted.

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
734

should be <=?

This revision is now accepted and ready to land.Apr 2 2020, 2:15 AM
This revision was automatically updated to reflect the committed changes.
nridge added a subscriber: nridge.Apr 5 2020, 11:24 PM

Tested in VSCode insiders (with a patched client to enable experimental features).

In case it's useful to others: the required change to the client to opt into this appears to be calling registerProposedFeatures() on the LanguageClient object.