]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Remove the completion matches that doesn't start with the keyword prefix before cursor
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 15 Mar 2023 03:43:24 +0000 (20:43 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 15 Mar 2023 03:43:24 +0000 (20:43 -0700)
autoload/lsp/completion.vim
test/unit_tests.vim

index 1e55bbadf56c1633db3499ad51fcc50409128f75..ef16da42e0abfd08baaafc9ccc5007e474a3a4fa 100644 (file)
@@ -85,6 +85,11 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
     items = cItems.items
   endif
 
+  # Get the keyword prefix before the current cursor column.
+  var col = charcol('.')
+  var starttext = getline('.')[ : col - 1]
+  var prefix = matchstr(starttext, '\k*$')
+
   var completeItems: list<dict<any>> = []
   for item in items
     var d: dict<any> = {}
@@ -99,6 +104,12 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
       # snippet completion.  Needs a snippet plugin to expand the snippet.
       # Remove all the snippet placeholders
       d.word = MakeValidWord(d.word)
+    else
+      # plain text completion.  If the completion item text doesn't start with
+      # the current keyword prefix, skip it.
+      if prefix != '' && stridx(d.word, prefix) != 0
+       continue
+      endif
     endif
     d.abbr = item.label
     d.dup = 1
index 6971783884d4cf19393b31a21a216d22801b1358..0f898815f7b2bfebc0556fdc6ddfbbf499512eba 100644 (file)
@@ -236,6 +236,7 @@ def Test_LspShowReferences()
   setlocal nomodified
   cursor(10, 6)
   :LspPeekReferences
+  sleep 10m
   var ids = popup_list()
   assert_equal(2, ids->len())
   var filePopupAttrs = ids[0]->popup_getoptions()