]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
added requested changes
authorOleksiy Hryshchenko <greeschenko@gmail.com>
Sun, 23 Apr 2023 14:06:03 +0000 (17:06 +0300)
committerOleksiy Hryshchenko <greeschenko@gmail.com>
Sun, 23 Apr 2023 14:06:03 +0000 (17:06 +0300)
autoload/lsp/completion.vim
doc/lsp.txt

index 607d78d52e69fdcfc3155f3daa3330f05cd24357..83885862d84072c1d2c5256bd7c60e3f790214c2 100644 (file)
@@ -137,6 +137,26 @@ def CompletionUltiSnips(prefix: string, items: list<dict<any>>)
   endfor
 enddef
 
+# add completion from current buf
+def CompletionFromBuffer(items: list<dict<any>>)
+    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<any>, cItems: any)
@@ -173,22 +193,7 @@ export def CompletionReply(lspserver: dict<any>, 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<dict<any>> = []
index ef60be1226c974b53e1fb20e442de7826826bb9a..7ce342a0a60210b4d96c845355ef86b8681d0a7a 100644 (file)
@@ -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