feat: allow more completion highlight control#1972
Merged
Conversation
|
That’s much simpler in cmp side👍 |
Owner
|
thank you! |
nizamiza
pushed a commit
to nizamiza/nvim-cmp
that referenced
this pull request
Feb 28, 2025
* feat(view): allow hl_group to be a table * feat: improve table field naming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_groupvalues to be of typetablewith 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)functionaddManyAtfn (self: *Self, index: usize, count: usize) Allocator.Error![]T(index: usize, count: usize)Allocator.Error![]Tfind_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!