autoload/lsp/completion.vim | 37 +++++++++++++++++++++---------------- doc/lsp.txt | 6 ++++-- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 607d78d52e69fdcfc3155f3daa3330f05cd24357..83885862d84072c1d2c5256bd7c60e3f790214c2 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -137,6 +137,26 @@ }) 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 @@ CompletionUltiSnips(prefix, items) 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 ef60be1226c974b53e1fb20e442de7826826bb9a..7ce342a0a60210b4d96c845355ef86b8681d0a7a 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -499,8 +499,10 @@ command to display the code action for the current 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