feat(lsp): completion opts support custom item conversion (#30060)

Problem: Some items of completion results include function signatures that can
cause the pum to be very long when a function has many params, because pum
scales with the longest word/abbr.

Solution: add custom covert function that can customise abbr to remove params.
This commit is contained in:
glepnir
2024-08-23 03:42:27 +08:00
committed by GitHub
parent e48179f31e
commit 1f5bcc7c4e
4 changed files with 38 additions and 6 deletions

View File

@@ -495,7 +495,9 @@ describe('vim.lsp.completion: protocol', function()
bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_buf(0, bufnr)
return vim.lsp.start({ name = 'dummy', cmd = server.cmd, on_attach = function(client, bufnr)
vim.lsp.completion.enable(true, client.id, bufnr)
vim.lsp.completion.enable(true, client.id, bufnr, { convert = function(item)
return { abbr = item.label:gsub('%b()', '')}
end})
end})
]],
completion_result
@@ -700,4 +702,21 @@ describe('vim.lsp.completion: protocol', function()
eq(true, exec_lua('return _G.called'))
end)
end)
it('custom word/abbar format', function()
create_server({
isIncomplete = false,
items = {
{
label = 'foo(bar)',
},
},
})
feed('ifo')
trigger_at_pos({ 1, 1 })
assert_matches(function(matches)
eq('foo', matches[1].abbr)
end)
end)
end)