autoload/lsp/completion.vim | 11 +++++++++++ test/unit_tests.vim | 1 + diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 1e55bbadf56c1633db3499ad51fcc50409128f75..ef16da42e0abfd08baaafc9ccc5007e474a3a4fa 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -85,6 +85,11 @@ else 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> = [] for item in items var d: dict = {} @@ -99,6 +104,12 @@ if item->get('insertTextFormat', 1) == 2 # 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 diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 6971783884d4cf19393b31a21a216d22801b1358..0f898815f7b2bfebc0556fdc6ddfbbf499512eba 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -236,6 +236,7 @@ # buffer as not modified. setlocal nomodified cursor(10, 6) :LspPeekReferences + sleep 10m var ids = popup_list() assert_equal(2, ids->len()) var filePopupAttrs = ids[0]->popup_getoptions()