Is process_items a good place to format completion item text in the popup menu? #2180
-
Contributing guidelines
Module(s)mini.completion QuestionI want to truncate long labels for completion items provided by one of my language servers. I currently do this by truncating the labels inside the process_items function. Does anyone think this the correct place to handle this? One drawback I see is that this would apply to all language servers. And according to the LSP specification, the completion item’s label property is, by default, the text that gets inserted when the completion is selected if no other suitable properties are provided. later(function()
local process_items_opts = { kind_priority = { Text = -1, Snippet = 99 } }
local process_items = function(items, base)
local res = MiniCompletion.default_process_items(items, base, process_items_opts)
for _, item in ipairs(res) do
local label = item.label
if label and #label > 25 then
item.label = label:sub(1, 24) .. "…"
end
end
return res
end
require('mini.completion').setup({
lsp_completion = {
-- other configs
process_items = process_items,
},
})
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
To answer your question: yes, the To answer your problem: Neovim>=0.12 (current Nightly) has 'pummaxwidth' option that limits the width of the popup menu. It is not 100% the same, as it truncates candidate |
Beta Was this translation helpful? Give feedback.
To answer your question: yes, the
config.lsp_completion.process_itemsis the suggested way to adjust that. Thelabelfield is usually the last fallback among candidate fields that determine which text is inserted. To work around this, make sure to set other fields that have higher precedence for inserting text. The specification allows several ways to do that, but for this purpose settinginsertTextfield should work. So adding something likeitem.insertText = item.insertText or item.labelbefore adjusting the label should do the trick.To answer your problem: Neovim>=0.12 (current Nightly) has 'pummaxwidth' option that limits the width of the popup menu. It is not 100% the same, as it tr…