]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
add words from current buffer to completion list
authorOleksiy Hryshchenko <greeschenko@gmail.com>
Fri, 21 Apr 2023 19:30:52 +0000 (22:30 +0300)
committerOleksiy Hryshchenko <greeschenko@gmail.com>
Fri, 21 Apr 2023 19:30:52 +0000 (22:30 +0300)
autoload/lsp/completion.vim
doc/lsp.txt

index 4286a55203a6f3b2d74f29da04d97bf03bab8641..77e24867f3644f9d5505d5fa0b22728624072cde 100644 (file)
@@ -35,7 +35,8 @@ var defaultKinds: dict<string> = {
   '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<any>, 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<dict<any>> = []
   for item in items
     var d: dict<any> = {}
index 0e9f3fdd3aa75b6f50833616faaa9a996e1e4bf9..5edad1cee1fd701a2989c049ba101fbf1d926250 100644 (file)
@@ -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()": >