feat: allow more completion highlight control #1972
Merged
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.
Related: #1887
This PR allows more highlight control by allowing
vim.CompletedItem.{field}_hl_group
values to be of typetable
with the following structure:Examples
Simple
A simple use case of this is having different highlights for function parameters:
Code
Treesitter-based
You can also have more complex highlights by using treesitter for example:
Code (borrowed from @xzbdmw)
Notes
LSP doesn't specify exactly how to use the label fields of a
CompletionItem
, as a result the usage of these values differ a lot between LSP implementations (see table below). This makes getting syntactically correct function signatures inconsistent across different LSP implementations.require(modname)
function
addManyAt
fn (self: *Self, index: usize, count: usize) Allocator.Error![]T
(index: usize, count: usize)
Allocator.Error![]T
find_map(…)
fn(&mut self, F) -> Option<B>
(as Iterator)
fn(&mut self, F) -> Option<B>
I don't think nvim-cmp should be responsible for properly formatting/highlighting the function signatures. Instead, that logic should be configurable by the user, or delegated to some other plugin in similar style of lspkind-nvim.
Suggestions are very welcome!