From b48c94b90e9da99d6fa271f0eba8400cb5d11d48 Mon Sep 17 00:00:00 2001 From: Oleksiy Hryshchenko Date: Sun, 23 Apr 2023 17:06:03 +0300 Subject: [PATCH] added requested changes --- autoload/lsp/completion.vim | 37 +++++++++++++++++++++---------------- doc/lsp.txt | 6 ++++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 607d78d..8388586 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -137,6 +137,26 @@ def CompletionUltiSnips(prefix: string, items: list>) endfor enddef +# add completion from current buf +def CompletionFromBuffer(items: list>) + var words = {} + for line in getline(1, '$') + for word in line->split('\W\+') + if !has_key(words, word) && len(word) > 1 + words[word] = 1 + items->add({ + label: word, + data: { + entryNames: [word], + }, + kind: 26, + documentation: "", + }) + endif + endfor + endfor +enddef + # process the 'textDocument/completion' reply from the LSP server # Result: CompletionItem[] | CompletionList | null export def CompletionReply(lspserver: dict, cItems: any) @@ -173,22 +193,7 @@ export def CompletionReply(lspserver: dict, cItems: any) endif if opt.lspOptions.useBufferCompletion - # add completion from current buf - var words = {} - var text = join(getline(1, '$'), "\n") - for word in split(text, '\W\+') - if !has_key(words, word) && len(word) > 1 - words[word] = 1 - items->add({ - label: word, - data: { - entryNames: [word], - }, - kind: 26, - documentation: "", - }) - endif - endfor + CompletionFromBuffer(items) endif var completeItems: list> = [] diff --git a/doc/lsp.txt b/doc/lsp.txt index ef60be1..7ce342a 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -499,8 +499,10 @@ usePopupInCodeAction |Boolean| option. When using the |:LspCodeAction| line, use a popup menu instead of echoing. By default this is set to false. *lsp-opt-useBufferCompletion* -useBufferCompletion |Boolean| option. If enable adds current buffer words - to autocompletion list. Мay degrade vim performance. +useBufferCompletion |Boolean| option. If enabled, the words from the current + buffer are added to the auto completion list. This may degrade Vim performance + as the current buffer contents are processed every time the completion + menu is displayed. By default this is set to false. For example, to disable the automatic placement of signs for the LSP -- 2.48.1