Skip to content

Commit 0b9bba0

Browse files
committed
omni completion results in an error message after a opening parenthesis
1 parent 0f774f9 commit 0b9bba0

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

autoload/lsp/completion.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ def g:LspOmniFunc(findstart: number, base: string): any
477477

478478
var [triggerKind, triggerChar] = GetTriggerAttributes(lspserver)
479479
if triggerKind < 0
480-
return -1
480+
# previous character is not a keyword character or a trigger character,
481+
# so cancel omni completion.
482+
return -2
481483
endif
482484

483485
# first send all the changes in the current buffer to the LSP server
@@ -509,7 +511,7 @@ def g:LspOmniFunc(findstart: number, base: string): any
509511
return v:none
510512
endif
511513

512-
var res: list<dict<any>> = lspserver->get('completeItems', [])
514+
var res: list<dict<any>> = lspserver.completeItems
513515
var prefix = lspserver.omniCompleteKeyword
514516

515517
# Don't attempt to filter on the items, when "isIncomplete" is set

test/clangd_tests.vim

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def g:Test_OmniComplete_FirstColumn()
14711471
:%bw!
14721472
enddef
14731473

1474-
# Test for doing omni completion from the first column
1474+
# Test for doing omni completion with a multibyte character
14751475
def g:Test_OmniComplete_Multibyte()
14761476
:silent! edit XOmniCompleteMultibyte.c
14771477
sleep 200m
@@ -1493,7 +1493,7 @@ def g:Test_OmniComplete_Multibyte()
14931493
:%bw!
14941494
enddef
14951495

1496-
# Test for doing omni completion from the first column
1496+
# Test for doing omni completion for a struct field
14971497
def g:Test_OmniComplete_Struct()
14981498
:silent! edit XOmniCompleteStruct.c
14991499
sleep 200m
@@ -1524,6 +1524,28 @@ def g:Test_OmniComplete_Struct()
15241524
:%bw!
15251525
enddef
15261526

1527+
# Test for doing omni completion after an opening parenthesis.
1528+
# This used to result in an error message.
1529+
def g:Test_OmniComplete_AfterParen()
1530+
:silent! edit XOmniCompleteAfterParen.c
1531+
sleep 200m
1532+
var lines: list<string> =<< trim END
1533+
#include <stdio.h>
1534+
void Fn(void)
1535+
{
1536+
printf(
1537+
}
1538+
END
1539+
setline(1, lines)
1540+
g:WaitForServerFileLoad(2)
1541+
redraw!
1542+
1543+
cursor(4, 1)
1544+
feedkeys("A\<C-X>\<C-O>\<C-Y>", 'xt')
1545+
assert_equal(' printf(', getline('.'))
1546+
:%bw!
1547+
enddef
1548+
15271549
# Test for inlay hints
15281550
def g:Test_InlayHints()
15291551
:silent! edit XinlayHints.c

0 commit comments

Comments
 (0)