From: Oleksiy Hryshchenko Date: Fri, 21 Apr 2023 19:30:52 +0000 (+0300) Subject: add words from current buffer to completion list X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8f3249cd5db971ef25db19dd54b904a13be940d7;p=vim-lsp.git add words from current buffer to completion list --- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 4286a55..77e2486 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -35,7 +35,8 @@ var defaultKinds: dict = { 'Struct': 's', 'Event': 'E', 'Operator': 'o', - 'TypeParameter': 'T' + 'TypeParameter': 'T', + 'Buffer': 'B', } # Returns true if omni-completion is enabled for filetype 'ftype'. @@ -77,10 +78,11 @@ def LspCompleteItemKindChar(kind: number): string 'Struct', 'Event', 'Operator', - 'TypeParameter' + 'TypeParameter', + 'Buffer' ] - if kind > 25 + if kind > 26 return '' endif @@ -170,6 +172,23 @@ 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 + var completeItems: list> = [] for item in items var d: dict = {} diff --git a/doc/lsp.txt b/doc/lsp.txt index 0e9f3fd..5edad1c 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -1362,6 +1362,7 @@ option |lsp-opt-completionKinds| . There is a table with all default LSP kinds: Event | E Operator | o TypeParameter | T + Buffer | B For example, if you want to change the "Method" kind to the kind "method()": >