]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
refactoring
authorOleksiy Hryshchenko <greeschenko@gmail.com>
Tue, 11 Apr 2023 06:29:10 +0000 (09:29 +0300)
committerOleksiy Hryshchenko <greeschenko@gmail.com>
Tue, 11 Apr 2023 06:29:10 +0000 (09:29 +0300)
autoload/lsp/completion.vim

index b30f7c8d36811755fc5616846dc41311abf14064..d07cda9291d35d89df305e7e30610c80bbf06ab1 100644 (file)
@@ -249,7 +249,7 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
 enddef
 
 # process the completion documentation without LSP server request
-def ShowCompletionDocumentationNoLsp(cItem: any)
+def ShowCompletionDocumentation(cItem: any)
   if cItem->empty() || cItem->type() != v:t_dict
     return
   endif
@@ -319,77 +319,7 @@ enddef
 # process the 'completionItem/resolve' reply from the LSP server
 # Result: CompletionItem
 export def CompletionResolveReply(lspserver: dict<any>, cItem: any)
-  if cItem->empty() || cItem->type() != v:t_dict
-    return
-  endif
-
-  # check if completion item is still selected
-  var cInfo = complete_info()
-  if cInfo->empty()
-      || !cInfo.pum_visible
-      || cInfo.selected == -1
-      || cInfo.items[cInfo.selected]->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data.label !=# cItem.label
-    return
-  endif
-
-  var infoText: list<string>
-  var infoKind: string
-
-  if cItem->has_key('detail') && !cItem.detail->empty()
-    # Solve a issue where if a server send the detail field with "\n",
-    # on the completion popup, everything will be joined with "^@"
-    # (example: typescript-language-server)
-    infoText->extend(cItem.detail->split("\n"))
-  endif
-
-  if cItem->has_key('documentation')
-    if !infoText->empty()
-      infoText->extend(['- - -'])
-    endif
-    if cItem.documentation->type() == v:t_dict
-      # MarkupContent
-      if cItem.documentation.kind == 'plaintext'
-        infoText->extend(cItem.documentation.value->split("\n"))
-        infoKind = 'text'
-      elseif cItem.documentation.kind == 'markdown'
-        infoText->extend(cItem.documentation.value->split("\n"))
-        infoKind = 'lspgfm'
-      else
-        util.ErrMsg($'Error: Unsupported documentation type ({cItem.documentation.kind})')
-        return
-      endif
-    elseif cItem.documentation->type() == v:t_string
-      infoText->extend(cItem.documentation->split("\n"))
-    else
-      util.ErrMsg($'Error: Unsupported documentation ({cItem.documentation->string()})')
-      return
-    endif
-  endif
-
-  if infoText->empty()
-    return
-  endif
-
-  # check if completion item is changed in meantime
-  cInfo = complete_info()
-  if cInfo->empty()
-      || !cInfo.pum_visible
-      || cInfo.selected == -1
-      || cInfo.items[cInfo.selected]->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data.label !=# cItem.label
-    return
-  endif
-
-  var id = popup_findinfo()
-  if id > 0
-    var bufnr = id->winbufnr()
-    id->popup_settext(infoText)
-    infoKind->setbufvar(bufnr, '&ft')
-    id->popup_show()
-  endif
+    ShowCompletionDocumentation(cItem)
 enddef
 
 # omni complete handler
@@ -501,7 +431,7 @@ def LspResolve()
       if !item.user_data->has_key('documentation')
         lspserver.resolveCompletion(item.user_data)
       else
-        ShowCompletionDocumentationNoLsp(item.user_data)
+        ShowCompletionDocumentation(item.user_data)
       endif
   endif
 enddef