mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 20:18:32 +00:00
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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user