]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
omni completion results in an error message after a opening parenthesis
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 26 Feb 2024 16:07:36 +0000 (08:07 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 26 Feb 2024 16:07:36 +0000 (08:07 -0800)
autoload/lsp/completion.vim
test/clangd_tests.vim

index 9e78adb6bf5dc20441732cae114b333e02c9ac5c..71984d82a3b6a897ff966ed77a4375d32a999d30 100644 (file)
@@ -477,7 +477,9 @@ def g:LspOmniFunc(findstart: number, base: string): any
 
     var [triggerKind, triggerChar] = GetTriggerAttributes(lspserver)
     if triggerKind < 0
-      return -1
+      # previous character is not a keyword character or a trigger character,
+      # so cancel omni completion.
+      return -2
     endif
 
     # 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
       return v:none
     endif
 
-    var res: list<dict<any>> = lspserver->get('completeItems', [])
+    var res: list<dict<any>> = lspserver.completeItems
     var prefix = lspserver.omniCompleteKeyword
 
     # Don't attempt to filter on the items, when "isIncomplete" is set
index 1da68c0062443bd441990e4586338af45e3addc9..fe2a16ca20a691be67358878638365f316d3b9bd 100644 (file)
@@ -1471,7 +1471,7 @@ def g:Test_OmniComplete_FirstColumn()
   :%bw!
 enddef
 
-# Test for doing omni completion from the first column
+# Test for doing omni completion with a multibyte character
 def g:Test_OmniComplete_Multibyte()
   :silent! edit XOmniCompleteMultibyte.c
   sleep 200m
@@ -1493,7 +1493,7 @@ def g:Test_OmniComplete_Multibyte()
   :%bw!
 enddef
 
-# Test for doing omni completion from the first column
+# Test for doing omni completion for a struct field
 def g:Test_OmniComplete_Struct()
   :silent! edit XOmniCompleteStruct.c
   sleep 200m
@@ -1524,6 +1524,28 @@ def g:Test_OmniComplete_Struct()
   :%bw!
 enddef
 
+# Test for doing omni completion after an opening parenthesis.
+# This used to result in an error message.
+def g:Test_OmniComplete_AfterParen()
+  :silent! edit XOmniCompleteAfterParen.c
+  sleep 200m
+  var lines: list<string> =<< trim END
+    #include <stdio.h>
+    void Fn(void)
+    {
+      printf(
+    }
+  END
+  setline(1, lines)
+  g:WaitForServerFileLoad(2)
+  redraw!
+
+  cursor(4, 1)
+  feedkeys("A\<C-X>\<C-O>\<C-Y>", 'xt')
+  assert_equal('  printf(', getline('.'))
+  :%bw!
+enddef
+
 # Test for inlay hints
 def g:Test_InlayHints()
   :silent! edit XinlayHints.c