From: Yegappan Lakshmanan Date: Wed, 15 Mar 2023 03:43:24 +0000 (-0700) Subject: Remove the completion matches that doesn't start with the keyword prefix before cursor X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=eb5ad92bf4b808c8295a1626c3ba9a74cfbf195c;p=vim-lsp.git Remove the completion matches that doesn't start with the keyword prefix before cursor --- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 1e55bba..ef16da4 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -85,6 +85,11 @@ export def CompletionReply(lspserver: dict, 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> = [] for item in items var d: dict = {} @@ -99,6 +104,12 @@ export def CompletionReply(lspserver: dict, 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 diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 6971783..0f89881 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -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()