]> Sergey Matveev's repositories - vim-lsp.git/blobdiff - autoload/lsp/completion.vim
Move snippet related code to a separate file
[vim-lsp.git] / autoload / lsp / completion.vim
index 711f198b1b0fcd70e4d5b6877c49884b7308985e..66ea9c5d6d23ec9b74289171a576965915153aeb 100644 (file)
@@ -6,6 +6,7 @@ import './util.vim'
 import './buffer.vim' as buf
 import './options.vim' as opt
 import './textedit.vim'
+import './snippet.vim'
 
 # per-filetype omni-completion enabled/disabled table
 var ftypeOmniCtrlMap: dict<bool> = {}
@@ -111,83 +112,6 @@ def MakeValidWord(str_arg: string): string
   return valid
 enddef
 
-# Integration with the UltiSnips plugin
-def CompletionUltiSnips(prefix: string, items: list<dict<any>>)
-  call UltiSnips#SnippetsInCurrentScope(1)
-  for key in matchfuzzy(g:current_ulti_dict_info->keys(), prefix)
-    var item = g:current_ulti_dict_info[key]
-    var parts = split(item.location, ':')
-    var txt = parts[0]->readfile()[parts[1]->str2nr() : parts[1]->str2nr() + 20]
-    var restxt = item.description .. "\n\n"
-    for line in txt
-      if line->empty() || line[0 : 6] == "snippet"
-       break
-      else
-       restxt = restxt .. line .. "\n"
-      endif
-    endfor
-    items->add({
-      label: key,
-      data: {
-       entryNames: [key],
-      },
-      kind: 15,
-      documentation: restxt,
-    })
-  endfor
-enddef
-
-# Integration with the vim-vsnip plugin
-def CompletionVsnip(items: list<dict<any>>)
-  def Pattern(abbr: string): string
-    var chars = escape(abbr, '\/?')->split('\zs')
-    var chars_pattern = '\%(\V' .. chars->join('\m\|\V') .. '\m\)'
-    var separator = chars[0] =~ '\a' ? '\<' : ''
-    return $'{separator}\V{chars[0]}\m{chars_pattern}*$'
-  enddef
-
-  if charcol('.') == 1
-    return
-  endif
-  var starttext = getline('.')->slice(0, charcol('.') - 1)
-  for item in vsnip#get_complete_items(bufnr('%'))
-    var match = starttext->matchstrpos(Pattern(item.abbr))
-    if match[0] != ''
-      var user_data = item.user_data->json_decode()
-      var documentation = []
-      for line in vsnip#to_string(user_data.vsnip.snippet)->split("\n")
-       documentation->add(line)
-      endfor
-      items->add({
-       label: item.abbr,
-       filterText: item.word,
-       insertTextFormat: 2,
-       textEdit: {
-         newText: user_data.vsnip.snippet->join("\n"),
-         range: {
-           start: {
-             line: line('.'),
-             character: match[1],
-           },
-           ['end']: {
-             line: line('.'),
-             character: match[2],
-           },
-         },
-       },
-       data: {
-         entryNames: [item.word],
-       },
-       kind: 15,
-       documentation: {
-         kind: 'markdown',
-         value: documentation->join("\n"),
-       },
-      })
-    endif
-  endfor
-enddef
-
 # add completion from current buf
 def CompletionFromBuffer(items: list<dict<any>>)
     var words = {}
@@ -240,9 +164,9 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
   var start_col = start_idx + 1
 
   if opt.lspOptions.ultisnipsSupport
-    CompletionUltiSnips(prefix, items)
+    snippet.CompletionUltiSnips(prefix, items)
   elseif opt.lspOptions.vsnipSupport
-    CompletionVsnip(items)
+    snippet.CompletionVsnip(items)
   endif
 
   if opt.lspOptions.useBufferCompletion