From eb5ad92bf4b808c8295a1626c3ba9a74cfbf195c Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 14 Mar 2023 20:43:24 -0700 Subject: [PATCH] Remove the completion matches that doesn't start with the keyword prefix before cursor --- autoload/lsp/completion.vim | 11 +++++++++++ test/unit_tests.vim | 1 + 2 files changed, 12 insertions(+) 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() -- 2.48.1