-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: Improve lsp semantic token and treesitter support #14
fix: Improve lsp semantic token and treesitter support #14
Conversation
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.
This is great! I love the refactoring of the syntax groups to syntax.lua
. Made a few comments about the rest of the changes
Neovim throws error when creating autocmd with undefined event. Support all Neovim versions by checking for existence of event.
This seems to be a bad practice. Both LSP and TS have defaults linking to syntax group names. Use and carefully craft those syntax group names when possible.
Generically supports various language servers with good results.
change to orange, the color used in the One Dark Pro theme
UpdateIt has become clear that we should not alter the default highlight groups from highlight sources (Treesitter, LSP) that link back to syntax groups, unless perhaps through exceptional cases. By focusing on the highlights of the syntax groups, and not overriding the defaults of highlight sources (Treesitter, LSP), we get much better behavior. When these highlight sources create highlight groups that do not link back to a syntax group by default, we should do our best to find a suitable syntax group to link to. The current changes reflect these learnings and strategy. Below are a few examples of various languages depicting the highlighting behavior with LSP tokens either on or off. Prior, highlights with LSP tokens on varied drastically from those with LSP tokens off. The current changes improve this and are probably a lot closer to what you would/should expect. With that said, I'm sure there are still things to iron out. LuaTypeScriptRust |
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.
This looks amazing! Thanks so much for doing this!
* feat(highlights): organize syntax groups into single file * feat(highlights): add remaining default syntax groups * feat(highlights)!: change `Identifier` group color to `C.red` * feat(highlights)!: change `Function` group color to `C.blue` * fix(highlights): link LSP tokens to Treesitter groups * fix(highlights): handle edge case priorities of LSP token/TS groups * feat(highlights): add TypeScript filetype groups for LSP tokens * docs: add Neovim-0.9-LSP-Semantic-Tokens.md * chore(docs): remove Neovim-0.9-LSP-Semantic-Tokens.md * chore(highlights): keep Treesitter groups together * chore: remove unnecessary `set_contains` util * fix: handle undefined event in autocmd Neovim throws error when creating autocmd with undefined event. Support all Neovim versions by checking for existence of event. * fix(lsp): do not link LSP hl groups to TS hl groups This seems to be a bad practice. Both LSP and TS have defaults linking to syntax group names. Use and carefully craft those syntax group names when possible. * feat(lsp): set LSP semantic hl groups not linked by default Generically supports various language servers with good results. * feat(highlight): change `Macro` highlight color change to orange, the color used in the One Dark Pro theme * chore: remove autocmds * chore(highlight): use `link` where possible * feat(highlight): keep Treesitter default hl group for `@operator` * feat(highlight): change color of `Operator` to white * feat(lsp): link additional semantic token hl groups
Neovim 0.9 - LSP Semantic Tokens
Theme or plugin authors will be required to handle these changes.
Seamless transition might not be possible in all cases, as new LSP-provided highlight groups will override those defined by Treesitter when using an LSP.
A sensible strategy must be defined for the best transition, which requires understanding of Syntax Group Names, Treesitter Highlight Groups and LSP Semantic Tokens.
Table of Contents
Syntax Group Names
:help group-name
Neovim specifies default syntax group names. A syntax group name is used for syntax items that
match the same kind of thing. These are then linked to a highlight group that specifies the
color. A syntax group name doesn't specify any color or attributes itself.
Treesitter Highlight Groups
:help treesitter-highlight-groups
Treesitter defines the following default highlight groups, most of which are linked to standard syntax group names:
LSP Semantic Tokens
:help lsp-semantic-highlight
LSP Semantic Tokens introduce new highlight groups when using an LSP,
classified by types and modifiers.
Neovim links some (not all) of the Semantic Token types (not yet modifiers) back to syntax group names.
⚠️ It is these links that introduce breaking changes with Treesitter's highlight groups,
since the LSP highlight groups are prioritized over any other default highlight group.
The following LSP highlight groups are linked by default to syntax group names:
Types and Modifiers
The follow is a list of all semantic token types included in the LSP protocol:
The following is a list of all semantic token modifiers included in the LSP protocol:
Strategy
Plugin developers have limited control over the priority of highlight groups between sources. (Treesitter vs. LSP).
By default, highlight groups set by LSP sources are prioritized over Treesitter sources.
...TBD, Evolving...
Helpers
:so $VIMRUNTIME/syntax/hitest.vim
- Open a new window containing all currently active highlight group names,displayed in their own color.
:Inspect
- Show all highlight sources and groups at a given buffer position.vim.inspect_pos()
- Get all highlight sources and groups at a given buffer position.nvim_buf_set_extmark()
- Set a highlight group at any position with a chosen priority.vim.lsp.semantic_tokens.highlight_token()
- Set a highlight group on a semantic token with a chosen priority.