Closed kristijanhusak closed 3 years ago
I think it is impossible to maintain consistent values for each source, so I've decided to remove the feature.
If the user want to show the source names for v:complete_item.menu
. I think it should be the following config.
cmp.setup {
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[LSP]',
buffer = '[Buf]',
path = '[Path]',
})[entry.source.name]
end
}
}
Why do you need that value to be consistent? Is some logic depending on it? To me that's just like an additional info that could be basically set to anything that user wants.
For example, the user might want to show CompletionItem.detail
to menu field.
cmp.setup {
formatting = {
format = function(entry, vim_item)
vim_item.menu = entry:get_completion_item().detail
return vim_item
end
}
}
I can think of a lot of wants for menu appearance so I thought it shouldn't set the default value. What do you think about it?
I'm ok for user having an option to override it, but I think there should be a way to set some default on source level. I have two custom sources for cmp (orgmode and vim-dadbod-completion), and I'm not able to let user know that completion is coming from these sources. Is there maybe some other way to provide custom menu value, through other property maybe?
Actually, the menu field is already in use, Sorry... 🥲
https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/entry.lua#L219
It is an introduced by LSP. I will annotate auto-import
like information.
The spec included by next version of LSP spec. Currently, no. But I think it is potential breaking change.
I guess adding this to the item adds some more information to it:
labelDetails = {
type = item.menu,
},
which for db completion it returns Text [DB]
by default. That's also fine by me, if you don't plan to change these labelDetails
.
Sorry... it might be already changed. TT
/**
* Additional details for a completion item label.
*
* @since 3.17.0 - proposed state
*/
export interface CompletionItemLabelDetails {
/**
* An optional string which is rendered less prominently directly after
* {@link CompletionItemLabel.label label}, without any spacing. Should be
* used for function signatures or type annotations.
*/
detail?: string;
/**
* An optional string which is rendered less prominently after
* {@link CompletionItemLabel.detail}. Should be used for fully qualified
* names or file path.
*/
description?: string;
}
Ok, I'll update it accordingly once that's set up. For now I'm using labelDetails.type
for my sources.
@kristijanhusak I will update to the latest spec as soon as possible. Please wait!
Ok, thanks. Let me know when it's done.
@kristijanhusak done. Thank you for your work!
That was fast, thanks!
I trust you will keep up with changes in LSP specifications. However, if possible, it may be better to avoid using undecided specifications.
I will write this note in the README.md.
(google translated)
Hopefully it will not change so much. Even if it does, i don't think anything will break, it will just stop showing additional data.
Yeah. I think so too and pray it.
In
nvim-compe
, I could usually differentiate from where the completion item is coming bymenu
value on thecomplete-item
(Buffer, Tag, Lsp, etc). Here it seems that values are always used from lsp configuration, and defaults toText
. Could these non-lsp sources somehow have their ownmenu
option?