From f2c8255cd0bb7a3be344b8341256f36f88f757dc Mon Sep 17 00:00:00 2001 From: Oleksiy Hryshchenko Date: Fri, 21 Apr 2023 23:29:02 +0300 Subject: [PATCH] add useBufferCompletion option --- autoload/lsp/completion.vim | 34 ++++++++++++++++++---------------- autoload/lsp/options.vim | 2 ++ doc/lsp.txt | 4 ++++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 77e2486..607d78d 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -172,22 +172,24 @@ export def CompletionReply(lspserver: dict, cItems: any) CompletionUltiSnips(prefix, items) endif - # 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 + 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 + endif var completeItems: list> = [] for item in items diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index ef708ee..8e29c79 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -67,6 +67,8 @@ export var lspOptions: dict = { usePopupInCodeAction: false, # ShowReferences in a quickfix list instead of a location list` useQuickfixForLocations: false, + # add to autocomplition list current buffer words + useBufferCompletion: false, # Enable support for custom completion kinds customCompletionKinds: false, # A dictionary with all completion kinds that you want to customize diff --git a/doc/lsp.txt b/doc/lsp.txt index 5edad1c..ef60be1 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -498,6 +498,10 @@ usePopupInCodeAction |Boolean| option. When using the |:LspCodeAction| 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. + By default this is set to false. For example, to disable the automatic placement of signs for the LSP diagnostic messages, you can add the following line to your .vimrc file: > -- 2.48.1