-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat(lsp): add support for semantic tokens #15723
Conversation
7e902c7
to
daef6a9
Compare
daef6a9
to
c8b1ea9
Compare
c8b1ea9
to
e069aa5
Compare
e069aa5
to
f3a4f9a
Compare
60b997a
to
41e17b5
Compare
911df2a
to
f14ac82
Compare
632d812
to
1a194af
Compare
Co-authored-by: Stephan Seitz <[email protected]> Co-authored-by: smolck <[email protected]>
b0c482f
to
0946958
Compare
For me the two issues that should to be addressed before this would be good to merge are: a) A concept to handle multiple LSP clients. Either the API needs to support client filters (like vim.lsp.buf.format, or rename) or there would need to be some kind of aggregate logic. I'm not sure which variant makes more sense for semantic tokens. That's also missing from other parts like codelens, but we learned that retrofitting this can be a bit painful (e.g. due to breaking changes). It's better to consider this from the start then trying to shoehorn it on top later. b) Showcase how multiple plugins would consume the tokens. (and probably improve the API for that, because I think each pluggin wrapping a function isn't ideal - it should probably be possible for one consumer to stop consuming / de-register itself - e.g. autocmds could be a solution as already mentioned) Given that both of these are influencing the public API I'd rather see this addressed before merging, not after. But if another core maintainer disagrees and wants to push this forward I won't object. |
#19931 could also be a possibility for mapping semantic token highlights in future
|
LSP 3.17 added |
I was trying out branch, and I am running into some issues, sadly. Nothing seems to be highlighted by default. So I scrolled through this PR and found out that you'd need to call the given function as follows to refresh highlighting. - But calling
Also, terminating vim takes about 2 seconds on a really strong desktop machine, and I wonder what might hold it back. Some timeout maybe? Regardless of the slow program-exit, I'd really like to give this branch a try because I need a way to test semantic tokens from the server side and would prefer to stick with (neo)vim for that. What am I maybe missing? p.s.: Would you mind doing a |
This PR doesn't implement buffer highlighting, it simply adds support for semantic tokens in the LSP client. You will need to implement the buffer highlighting yourself by providing a callback for
My guess is that you are running a debug build which defines |
@lewis6991 Is it possible yet to highlight individual/contextualized tokens from this callback? Or would it essentially be still a sequence of |
You wouldn't use |
I suggest checking out nvim-semantic-tokens. Been using it daily without issues. |
It seems this PR has stalled out again :( @theHamsta - it looks like you gave up a bit ago on actually pushing this through. Totally understandable, maybe I could open a continuation PR to keep going. @clason @lewis6991 @mfussenegger - To address @mfussenegger 's #15723 (comment), I think we need to hone in on exactly what form semantic tokens takes. Your (a) bullet contains two possibilities - we should decide on one. (b) is already sorta done-- @theHamsta and I both have different plugins that can consume the tokens. If we think the API for that should be improved, we should hammer that out. If this is better suited to a matrix discussion in neovim-dev, I'd be happy to hop on and discuss at some point. At this point, I think it's time we close this PR and open a new one that attempts to address whatever remaining things you guys want to see before we can get this in. Semantic tokens is a pretty major feature of LSP that the native client still doesn't support and it would be great if we could get some support for it (even if rudimentary) in before 0.9.0. |
@jdrouhard I absolutely feel with you. Last time I tried native LSP, the lag of semantic tokens was THE reason for me to switch back to coc.nvim. Since then I didn't even care about moving forward again, as no semantic highlighting is in fact a deal breaker for me. I can't complain too much here, as I can't contribute to it either. Lua isn't just my thing, so I'm happy for anyone to just finish this work such that others (not just me) could eventually start using the native LSP (again). Meanwhile I keep watching, all the best, p.s.: one important note to drop. I was actively working on an LSP server myself, and the thing I've learned from it, is that users ARE actualy willing to take non-finished products gladly now rather than waiting a year or more until it is 100% complete. There's no such thing as perfect anyways. Release often and early they say. Use that as an advantage to re-iterate often, get early feedback, and improve while you go. ... and again, all the best to you guys. Cheres ;) |
I haven't seen yours, but afaik the one from theHamsta uses something like Since my last comment autocmds gained support for a
Yes, matrix may be the better place to hash out the API Regarding other comments: Please refrain from adding more comments that add no more additional information. We have already concluded that semantic tokens would be good to have in core. What's missing is someone who does the work and resolves the remaining issues. |
Superseeded by #21100 |
Another take on #14122 . I updated @smolck PR to the new LSP handler signatures and added some basic highlighting.
vim.treesitter.highlight
(e.g. default link of thinks likecppLspComment
)LspComment
,cppLspComment
automatically linked toLspComment
LspDeprecated
,cppLspDeprecated
LspFunctionDeprecated
? or should be just provide a overwritable function that does the mappingft x token x modifiers
->hl
handle refreshing-> proper implementation in follow-up with partial refreshing, for now just full request on autocmd)implement partial refreshes of semantic tokens-> follow-up PRFixes nvim-treesitter/nvim-treesitter#1632 @cryptomilk I think this would fit your use case. When your run
autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.buf.semantic_tokens_full()
with clangd andLspComment
linked toComment
.semantic_tokens.mp4
Open question should the default semantic token handler handle highlighting? Should this be opt in?