cmd/govim: add support for semantic token highlighting #1093
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In LSP there is a concept of "semantic tokens" that gopls can provide
us. It allows us to do a more granular syntax highlighting than vim
provides default for Go.
This is a first take of how it might work, used to try out to what
extent it makes sense to govim to provide syntax highlighting.
The highlight groups are currently defined as a part of the syntax
highlighting so to try it out you currently have to have syntax
enabled/on when loading vim. Semantic tokens will replace the native
syntax. Turn off syntax (":syntax off") after startup to see semantic
tokens only.
Enable by adding to your .vimrc:
This change aims to keep track of all visible lines in vim, and only
request semantic tokens for those ranges. Each time one of the
autocommands CursorHold, CursorHoldI or CursorMoved fires visible
lines are re-evaluated. Since highlighting is very sensitive to
latency (and CursorMoved triggers A LOT) the delta calculation is
done on the vim side. That way govim only sees changes.
In govim we also debounce multiple updates, and keep track of
which lines we placed tokens on, to be able to remove non-visible
tokens. Since a buffer might be visible in several windows we also
ensure that we do not remove tokens visible in other windows.