mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 02:21:51 +00:00
feat(completion): completeopt=preselect, LSP CompletionItem.preselect #36613
Problem: LSP CompletionItem.preselect is not supported. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionClientCapabilities Solution: - Add "preselect" field to complete-items and "preselect" flag to 'completeopt'. - Set preselectSupport=true in LSP client capabilities.
This commit is contained in:
@@ -266,6 +266,70 @@ describe('completion', function()
|
||||
feed('i<C-r>=TestComplete()<CR><ESC>')
|
||||
eq(0, eval('&l:modified'))
|
||||
end)
|
||||
describe('"preselect"', function()
|
||||
it('"preselect" selects first item with preselect attribute', function()
|
||||
source([[
|
||||
function! TestComplete() abort
|
||||
call complete(1, [
|
||||
\ {'word': 'aaa'},
|
||||
\ {'word': 'bbb'},
|
||||
\ {'word': 'ccc', 'preselect': v:true},
|
||||
\ {'word': 'ddd'},
|
||||
\ ])
|
||||
return ''
|
||||
endfunction
|
||||
function! TestCompleteMany() abort
|
||||
let items = []
|
||||
for i in range(20)
|
||||
call add(items, {'word': 'item' .. i})
|
||||
endfor
|
||||
let items[15].preselect = v:true
|
||||
call complete(1, items)
|
||||
return ''
|
||||
endfunction
|
||||
]])
|
||||
|
||||
command('set completeopt=menuone,preselect')
|
||||
feed('i<C-r>=TestComplete()<CR>')
|
||||
screen:expect([[
|
||||
ccc^ |
|
||||
{4:aaa }{1: }|
|
||||
{4:bbb }{1: }|
|
||||
{12:ccc }{1: }|
|
||||
{4:ddd }{1: }|
|
||||
{1:~ }|*2
|
||||
{5:-- INSERT --} |
|
||||
]])
|
||||
|
||||
-- scrolls pum when preselect item is far down
|
||||
feed('<Esc>S')
|
||||
command('set pumheight=5')
|
||||
feed('<C-r>=TestCompleteMany()<CR>')
|
||||
screen:expect([[
|
||||
item15^ |
|
||||
{4:item13 }{12: }{1: }|
|
||||
{4:item14 }{12: }{1: }|
|
||||
{12:item15 }{1: }|
|
||||
{4:item16 }{101: }{1: }|
|
||||
{4:item17 }{12: }{1: }|
|
||||
{1:~ }|
|
||||
{5:-- INSERT --} |
|
||||
]])
|
||||
|
||||
feed('<Esc>S')
|
||||
command('set completeopt=menuone,noselect,preselect pumheight=0')
|
||||
feed('<C-r>=TestComplete()<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
{4:aaa }{1: }|
|
||||
{4:bbb }{1: }|
|
||||
{12:ccc }{1: }|
|
||||
{4:ddd }{1: }|
|
||||
{1:~ }|*2
|
||||
{5:-- INSERT --} |
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('completeopt+=noinsert does not add blank undo items', function()
|
||||
|
||||
Reference in New Issue
Block a user