-
Notifications
You must be signed in to change notification settings - Fork 305
Semantic Tokens Support #1275
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
Semantic Tokens Support #1275
Conversation
Servers seem to have differing behaviour when |
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.
Thanks for taking up the semantic tokens support. Added few comments.
I think this should be ready for merging, though f0b147d needs a look.
|
Can you let me know the repository/lang server you are using to test this feature? I'm not getting much when using clangd.
Clangd version:
repository: |
Strange, I'm also primarilly using clangd 13.0.1. I'm on linux so could it maybe be an OS thing? The |
Doesn't seem to work quite yet when using dwm-win32 on windows. If you have an open source repository that works either on win/mac/linux let me know and I can give it a try. [
[
"--->",
2,
"clangd",
{
"method": "textDocument/semanticTokens/full/delta",
"on_notification": "---funcref---",
"params": {
"previousResultId": 0,
"textDocument": {
"uri": "file:///d:/tmp/github/dwm-win32/src/mods/dwm.h"
}
}
}
],
[
"<---",
2,
"clangd",
{
"response": {
"id": 4,
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "failed to decode textDocument/semanticTokens/full/delta request: expected string at (root).previousResultId"
}
},
"request": {
"id": 4,
"jsonrpc": "2.0",
"method": "textDocument/semanticTokens/full/delta",
"params": {
"previousResultId": 0,
"textDocument": {
"uri": "file:///d:/tmp/github/dwm-win32/src/mods/dwm.h"
}
}
}
}
],
[
"Skipping semantic highlight: response is invalid"
],
[
"<---(stderr)",
2,
"clangd",
"I[09:51:21.323] <-- textDocument/semanticTokens/full/delta(4)\r\nE[09:51:21.323] Failed to decode textDocument/semanticTokens/full/delta request: expected string at (root).previousResultId\r\nI[09:51:21.323] --> reply:textDocument/semanticTokens/full/delta(4) 0 ms, error: -32602: failed to decode textDocument/semanticTokens/full/delta request: expected string at (root).previousResultId\r\n"
]
] We also don't seem to run the highlighting when buffer get loaded hence i wasn't seeing any changes. Seems like you need to listen to |
Yes, looks to me like your error is resulting from the initial b12fe4d uses Adding a system where delta requests are not sent unless a full request has already been processed is not as easy as it should be unfortunately - the different lifetimes of textprops and bufvars throws a bit of a spanner in the works there. It could be implemented by introducing a buffer-local autocommand for every buffer which clears the relevant bufvars, but that's a bit of a hack-job. |
Seems like there is a merge conflict due to #1298. Can you make sure to add the priorities too and merge/rebase with latest master? I was able to get it working with rust. At one point I did get the following error but have not been able to constantly repro it. [
"<---",
1,
"rust-analyzer",
{
"response": {
"id": 9,
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Failed to deserialize textDocument/semanticTokens/full/delta: invalid type: integer `0`, expected a string; {\"previousResultId\":0,\"textDocument\":{\"uri\":\"file:///home/prabirshrestha/code/tmp/helloworld/src/main.rs\"}}"
}
},
"request": {
"id": 9,
"jsonrpc": "2.0",
"method": "textDocument/semanticTokens/full/delta",
"params": {
"previousResultId": 0,
"textDocument": {
"uri": "file:///home/prabirshrestha/code/tmp/helloworld/src/main.rs"
}
}
}
}
] Probably some race conditions somewhere? When it works the [
"<---",
1,
"rust-analyzer",
{
"response": {
"id": 9,
"jsonrpc": "2.0",
"result": {
"edits": [
{
"data": [
2,
0,
1,
26,
0
],
"deleteCount": 5,
"start": 115
}
],
"resultId": "2"
}
},
"request": {
"id": 9,
"jsonrpc": "2.0",
"method": "textDocument/semanticTokens/full/delta",
"params": {
"previousResultId": "1",
"textDocument": {
"uri": "file:///home/prabirshrestha/code/tmp/helloworld/src/main.rs"
}
}
}
}
] Spec does say it needs to be a string.
|
Hey, just wanted to chime in and say that I tried this branch out but I'm struggling to get it to work. First I couldn't find any docs indicating that
Note that the server I'm trying to use doesn't yet support deltas. |
Oh and I think token modifiers (at least a handful of them) should be a higher priority. Off the top of my head, the |
@afranchuk does 9b2f5cd fix your error? What LSP server are you using - I haven't been able to find any which support
|
Hey look at that, it works! Awesome, thank you. This is an internal LSP server so it is not publicly accessible for you to test. But your blind changes did the trick :) |
BTW another common highlight you might want to add by default is |
Another highlighting suggestion (as I'm noticing this in both C++ and Rust codebases with clangd/rust-analyzer): the default highlight links for |
3ea6894 adds support for modifiers. Right now this has been done as suggested by prepending the token type with each of the names of the modifers. The fact that any subset of the modifiers can be applied leads to some quirks:
Any ideas regarding this would be much appreciated, I can't see any easy solutions. The first point could be remedied by sorting the modifiers alphabetically, but that has ramifications for the second point. I've had to change the system for initialising and clearing the highlight groups to do it dynamically, the consequence of which is the highlight groups have to begin with a unique prefix @afranchuk the |
Thanks for the modifier support; with it I was able to get to parity with the prior CoC support in my extension. |
b3535bf sorts the modifiers alphabetically to eliminate one of the two issues outlined above. It's still difficult to change the highlighting of a token based on its modifiers. I think the best solution to this would be to provide the user with some kind of custom highlight function with a weight argument to manage modifer precedence. This could then be taken into account when the highlight groups are first created. I think for the time being though it's best to just merge this PR as-is, provided there are no issues. |
@frankplow I will be using this branch for the next few days and hopefully by end of week will be able to merge. Appreciate the effort you have put into this. Thanks! |
Merged. Thanks for the large contribution as well as your patience. |
I’m the next few weeks I’m more than happy to make it enabled by defaults if there aren’t issues or bug reports. |
README.md should probably be updated, neglected that sorry |
This PR implements semantic tokens from LSP 3.16. This will resolve #1239.
This is still very much WIP, some features which should be added before merging are:
Support for theDone in f0b147ddelta
request type. This does the job the caching used to do, but on the server rather than the client. With this, I suspect semantic tokens may be faster than the old system.There is a standardised set of token types and so some sensible defaults could be provided for theDone in 7a53e6e.semantic_highlight
server option.Token modifiers are also not yet supported. I don't think these are a priority however as the standard set of token types provides a good level of coverage and supporting modifiers isn't trivial.Done in 3ea6894.Some feedback on how/when to make semanticTokens requests would be appreciated. This is how I'm doing it currently.