-
-
Notifications
You must be signed in to change notification settings - Fork 1.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(cmp): enable the user to easily add new completion sources #3975
base: master
Are you sure you want to change the base?
feat(cmp): enable the user to easily add new completion sources #3975
Conversation
…tion sources * Consolidate lvim.builtin.cmp.formatting.source_names and lvim.builtin.cmp.formatting.duplicates into a new lvim.builtin.cmp.formatting.source_settings table * Update lvim.builtin.cmp.formatting.format function to use source_settings table to determie the menu name, icon, highlight group, and duplicate flag * Add menu names for crates, and lab.quick_data * These changes make it easy for users to add new completion sources by adding a new entry to the lvim.builtin.cmp.formatting.source_settings table
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.
I'm not sure what the overall benefit here is, since you can already adjust/add/delete sources directly by accessing lvim.builtin.cmp.sources
.
I suggest:
- consolidating
source_settings
to thesources
table instead, and avoid adding new options - deprecating any redundant and incompatible options that we already have (be sure not to break backwards compatibility)
Hey @kylo252 thank you for taking a quick look. While you are correct that users can add new sources via the This change replaces the source specific logic with more generic logic that retrieves all the completion menu settings from the If you take a look at the testing example in the PR it might help demonstrate what this PR enables. As for backwards compatibility I did not find either of the deleted tables in any documentation so I believe they are internal. Please let me know if this is incorrect and they are considered part of the public API and I would be happy to deprecate the tables rather than remove them. Thank you again. I'm looking forward to your response. |
@kylo252 I wanted to check back in before I make additional changes. I had some questions above and your guidance would be greatly appreciated.
|
is there no additional API that we can use from cmp's side? cc: @abzcoding, @LostNeophyte |
Great question @kylo252 that I had not considered. The cmp way to control menu formatting is via the Looking through cmp.lua the So this function There is an available workaround for this use case if the team choses not to accept the PR. LunarVim users can wrap and override the formatting function. To satisfy my particular use case the following code in config works: -- codeium setup
table.insert(lvim.builtin.cmp.sources, { name = "codeium" })
lvim.builtin.cmp.formatting.source_names.codeium = "(Codeium)"
local default_format = lvim.builtin.cmp.formatting.format
lvim.builtin.cmp.formatting.format = function(entry, vim_item)
vim_item = default_format(entry, vim_item)
if entry.source.name == "codeium" then
vim_item.kind = ""
vim_item.kind_hl_group = "CmpItemKindTabnine"
end
return vim_item
end That being said I still believe the table approach in this PR is an improvement. Besides enabling new completion sources with dev icons it simplifies the |
Hey @kylo252 just wanted to followup here. To succinctly reiterate my earlier responses & questions:
If accepted, as a followup to this PR I would also like to contribute updates to the documentation on how to add new cmp sources with proper menu formatting. |
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.
Sorry for the delay!
path = 1, | ||
nvim_lsp = 0, | ||
luasnip = 1, | ||
source_settings = { |
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.
I'm not sure about the naming here, and I'm still wondering if we're better off merging these into the original sources list, maybe under cmp.sources[foo].options
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.
@kylo252 I actually really like because there are already a few source settings sprinkled into the sources list, see copilot for an example:
sources = {
{
name = "copilot",
-- keyword_length = 0,
max_item_count = 3,
trigger_characters =
-- etc.
So consolidating the rest of the settings in there make sense. However, as you can see, the sources object is a list so we can't index in as you suggested cmp.sources[foo].options
. We could change it to that format i.e.
sources = {
copilot = {
-- options for copilot
}
other_source = {
-- other options
}
This would give us a single place to add sources and configure them in a way that I thinks makes sense, of course we would need to update everything that access the sources list to handle the new format.
Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
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.
Hey @kylo252 I've accepted all your suggestions, thank you, and I responded to your consolidation comment with some additional questions. Let me know what you think.
path = 1, | ||
nvim_lsp = 0, | ||
luasnip = 1, | ||
source_settings = { |
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.
@kylo252 I actually really like because there are already a few source settings sprinkled into the sources list, see copilot for an example:
sources = {
{
name = "copilot",
-- keyword_length = 0,
max_item_count = 3,
trigger_characters =
-- etc.
So consolidating the rest of the settings in there make sense. However, as you can see, the sources object is a list so we can't index in as you suggested cmp.sources[foo].options
. We could change it to that format i.e.
sources = {
copilot = {
-- options for copilot
}
other_source = {
-- other options
}
This would give us a single place to add sources and configure them in a way that I thinks makes sense, of course we would need to update everything that access the sources list to handle the new format.
Description
summary of the change
How Has This Been Tested?
Manual testing in config.lua