-
-
Notifications
You must be signed in to change notification settings - Fork 913
Support semantic tokens protocol #1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
clangd returns tokenModifiers = [], so I'll need another language server to test this against. There's a new defcustom to enable/disable modifier highlighting that defaults to disabled for the time being
I guess rust analyzer might support it, @flodiebold? You have several unused variables which cause CI failure: https://travis-ci.org/github/emacs-lsp/lsp-mode/jobs/690604604#L1473 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I would propose merging the PR as it is with semantics disabled. Once it gets
enough testing I propose having it enabled by default and deleting the rest of
the highlighting related code which apparently won't go into the spec.
Up to now the following servers support semantic highlighting.
- Rust Analyzer - latest version
- clangd - latest version build from master branch
- Dart (?) cc @ericdallo
I propose also adding some visual indication that the syntax highlighting is
about to be applied when we are waiting for the server to respond otherwise it
looks a bit broken. If we agree on that, this could be addressed in a separate PR.
PS: AFAICS Rust Analyzer supports range provider
|-[-] semanticTokensProvider: | |-[X] rangeProvider: t
lsp-mode.el
Outdated
(defvar-local lsp--semantic-tokens-teardown nil) | ||
|
||
(defun lsp--semantic-tokens-initialize-buffer () | ||
(message "semantic-tokens-initialize-buffer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
Would you mind adding instructions to the README.md on how to select the different modes? Thanks. |
Currently, Dart SDK doesn't have support for semantic tokens protocol yet, but since last year they are migrating for their own server protocol to LSP, I hope they implement this soon, so I opened an issue asking for that support. |
would it be enough to mention there's a (documented) option called |
the sooner we can get rid of the old highlighting code, the better. Though I'd wait at least until clangd 11 is released, as clangd 10 only supports the Theia protocol
good idea. I think with clangd the delay is short enough to render this unnecessary, but other language servers may not be as quick
nice. I'll clone something written in Rust then and try to set up rust-analyzer |
No worries. |
From what I saw with rust analyzer initially it may take a lot of time because even that I was using a hello world application to test the delay was visible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note about a twice defined defface
.
"Face used for types." | ||
:group 'lsp-faces) | ||
|
||
(defface lsp-face-semhl-type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it intentional to define this defface twice, identical to to one just above it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, wasn't intentional, thanks for the pointer. I assume this doesn't break anything (or does it?), so I'll just fix this as part of the incremental highlighting PR (have rust-analyzer up and running and incremental highlighting seems to work, but it currently doesn't update correctly under all circumstances; plan to work on it on Sunday evening or Monday)
Have you tried using the |
no, so far I haven't. Didn't even know about it, so thanks for the hint! As far as I understand, I could just apply |
Yup. You can follow
I suppose it is true. On the other hand, you only need to clear existing highlighting when you receive the response from the server. So this approach can work without blinking, or similar visual aggravations.
Multiple non-standard ones? I don't know (though there are some things you could try). But your current approach doesn't offer any solutions for that either, does it? OTOH, the suggested approach is very compatible with |
thank you, I'll have a look at it. Will put this point (
yes, I'm just a bit worried about the runtime cost though I haven't done any fontification benchmarks. Should do that, then we can decide whether fontifying twice incurs a relevant performance penalty or not
currently, I'm calling
does the current implementation of semantic highlighting interfere with |
I suppose that could be some concern. Though you probably mean double redisplay. Off the top of my head, I'm not sure which option is going to be faster, but suspect that mine will.
The former -- probably yes. The latter - I don't know. It's hard to predict the effect of such layering of fontification functions.
I don't know. |
interesting. Not sure why it would be faster, but if it is, I'll gladly make the change. Will set up some benchmarks on the weekend |
this PR adds support for the semantic tokens protocol as defined by LSP 3.16, see #1482.
I've been using commit 9c03646... for about 4 weeks with a trunk build of clangd 11. Today's commits have only received superficial testing but should be relatively unlikely to break things.
The following points have not been addressed yet:
:semantic-tokens
option is used) but instead suspends regular font-locking, waits for semantic tokens to arrive from the language server, afterwards applies regular font locking and then applies semantic tokens on top of that. If the server is slow to respond, this will delay initial fontification, so if people think this is annoying the first fontification run could be performed immediately. Also, if semantic highlighting faces overlap with regular font-locking, semantic highlighting will take precedence; this could be changed to a true layering approach by replacingput-text-property
withadd-text-properties
. Finally, some language servers might provide sufficiently rich highlighting data to completely replace the font-locking mechanism provided by the underlying major mode. If so, I could add an option to do that.