]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Handle exceptions when starting the language server in tests
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 13 Apr 2023 14:18:47 +0000 (07:18 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 13 Apr 2023 14:18:47 +0000 (07:18 -0700)
autoload/lsp/callhierarchy.vim
autoload/lsp/capabilities.vim
autoload/lsp/codeaction.vim
autoload/lsp/completion.vim
test/runner.vim

index 6e57571d5a2b2d38545feb8b51799a2831b5e2d4..e91d08ba71f18b71fc5e85dcf4db53983cd0e99f 100644 (file)
@@ -39,7 +39,7 @@ def CallHierarchyTreeItemRefresh(idx: number)
     if !reply->empty()
       for item in reply
        treeItem.children->add({item: w:LspCallHierIncoming ? item.from :
-                              item.to, open: false})
+                               item.to, open: false})
       endfor
     endif
   endif
index 9aefc5389524d041975d879da03bfeb42137fd0e..15a97664e11894fd3c00fc7f69c1a472150592f2 100644 (file)
@@ -286,7 +286,7 @@ export def GetClientCaps(): dict<any>
                        'source.organizeImports']
          }
        },
-        isPreferredSupport: true,
+       isPreferredSupport: true,
        disabledSupport: true
       },
       codeLens: {
@@ -307,7 +307,7 @@ export def GetClientCaps(): dict<any>
        symbolKind: {valueSet: range(1, 25)}
       },
       hover: {
-        contentFormat: ['plaintext', 'markdown']
+       contentFormat: ['plaintext', 'markdown']
       },
       foldingRange: {lineFoldingOnly: true},
       inlayHint: {dynamicRegistration: false},
index 81a146fe39b9a34499cb008e2a2ca80b70832fd0..faa11bd3e8f793f7d24f3cb9468ab46ce27e9441 100644 (file)
@@ -100,24 +100,24 @@ export def ApplyCodeAction(lspserver: dict<any>, actionlist: list<dict<any>>, qu
       wrap: 0,
       title: 'Code action',
       callback: (_, result) => {
-        # Invalid item selected or closed the popup
-        if result <= 0 || result > text->len()
-          return
-        endif
+       # Invalid item selected or closed the popup
+       if result <= 0 || result > text->len()
+         return
+       endif
 
-        # Do the code action
-        HandleCodeAction(lspserver, actions[result - 1])
+       # Do the code action
+       HandleCodeAction(lspserver, actions[result - 1])
       },
       filter: (winid, key) => {
-        if key == 'h' || key == 'l'
-          winid->popup_close(-1)
-        elseif key->str2nr() > 0
-          # assume less than 10 entries are present
-          winid->popup_close(key->str2nr())
-        else
-          return popup_filter_menu(winid, key)
-        endif
-        return 1
+       if key == 'h' || key == 'l'
+         winid->popup_close(-1)
+       elseif key->str2nr() > 0
+         # assume less than 10 entries are present
+         winid->popup_close(key->str2nr())
+       else
+         return popup_filter_menu(winid, key)
+       endif
+       return 1
       },
     })
   else
index dbf5b7e50d84906406549aefec560b433e506e73..11ba8fdd26328522d33cf628b2cb7fab0e668672 100644 (file)
@@ -141,28 +141,28 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
   var start_col = start_idx + 1
 
   if opt.lspOptions.ultisnipsSupport
-      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 = readfile(parts[0])[str2nr(parts[1]) : str2nr(parts[1]) + 20]
-          var restxt = item.description .. "\n\n"
-          for line in txt
-              if line == ""
-                  break
-              else
-                  restxt = restxt .. line .. "\n"
-              endif
-          endfor
-          items->add({
-              label: key,
-              data: {
-                  entryNames: [key],
-              },
-              kind: 15,
-              documentation: restxt,
-          })
+    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 = readfile(parts[0])[str2nr(parts[1]) : str2nr(parts[1]) + 20]
+      var restxt = item.description .. "\n\n"
+      for line in txt
+       if line == ""
+         break
+       else
+         restxt = restxt .. line .. "\n"
+       endif
       endfor
+      items->add({
+       label: key,
+       data: {
+         entryNames: [key],
+       },
+       kind: 15,
+       documentation: restxt,
+      })
+    endfor
   endif
 
   #writefile([$'chcol = {chcol}, starttext = [{starttext}], prefix = [{prefix}], start_idx = {start_idx}, end_idx = {end_idx}, start_col = {start_col}'], '/tmp/lspcomplete.log', 'a')
@@ -176,17 +176,17 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
     if item->has_key('textEdit') && opt.lspOptions.completionMatcher != 'fuzzy'
       var start_charcol: number
       if prefix != ''
-        start_charcol = charidx(starttext, start_idx) + 1
+       start_charcol = charidx(starttext, start_idx) + 1
       else
-        start_charcol = chcol
+       start_charcol = chcol
       endif
       var textEdit = item.textEdit
       var textEditStartCol = textEdit.range.start.character
       if textEditStartCol != start_charcol
-        var offset = start_charcol - textEditStartCol - 1
-        d.word = textEdit.newText[offset : ]
+       var offset = start_charcol - textEditStartCol - 1
+       d.word = textEdit.newText[offset : ]
       else
-        d.word = textEdit.newText
+       d.word = textEdit.newText
       endif
     elseif item->has_key('insertText')
       d.word = item.insertText
@@ -203,25 +203,25 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
 
       # plain text completion
       if prefix != ''
-        # If the completion item text doesn't start with the current (case
-        # ignored) keyword prefix, skip it.
-        if opt.lspOptions.completionMatcher == 'icase'
-          if d.word->tolower()->stridx(prefix) != 0
-            continue
-          endif
-        # If the completion item text doesn't fuzzy match with the current
-        # keyword prefix, skip it.
-        elseif opt.lspOptions.completionMatcher == 'fuzzy'
-          if matchfuzzy([d.word], prefix)->empty()
-            continue
-          endif
-        # If the completion item text doesn't start with the current keyword
-        # prefix, skip it.
-        else
-          if d.word->stridx(prefix) != 0
-            continue
-          endif
-        endif
+       # If the completion item text doesn't start with the current (case
+       # ignored) keyword prefix, skip it.
+       if opt.lspOptions.completionMatcher == 'icase'
+         if d.word->tolower()->stridx(prefix) != 0
+           continue
+         endif
+       # If the completion item text doesn't fuzzy match with the current
+       # keyword prefix, skip it.
+       elseif opt.lspOptions.completionMatcher == 'fuzzy'
+         if matchfuzzy([d.word], prefix)->empty()
+           continue
+         endif
+       # If the completion item text doesn't start with the current keyword
+       # prefix, skip it.
+       else
+         if d.word->stridx(prefix) != 0
+           continue
+         endif
+       endif
       endif
     endif
 
@@ -242,18 +242,18 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
       d.info = 'Lazy doc'
     else
       if item->has_key('detail') && item.detail != ''
-        # Solve a issue where if a server send a detail field
-        # with a "\n", on the menu will be everything joined with
-        # a "^@" separating it. (example: clangd)
-        d.menu = item.detail->split("\n")[0]
+       # Solve a issue where if a server send a detail field
+       # with a "\n", on the menu will be everything joined with
+       # a "^@" separating it. (example: clangd)
+       d.menu = item.detail->split("\n")[0]
       endif
       if item->has_key('documentation')
-        if item.documentation->type() == v:t_string && item.documentation != ''
-          d.info = item.documentation
-        elseif item.documentation->type() == v:t_dict
-            && item.documentation.value->type() == v:t_string
-          d.info = item.documentation.value
-        endif
+       if item.documentation->type() == v:t_string && item.documentation != ''
+         d.info = item.documentation
+       elseif item.documentation->type() == v:t_dict
+           && item.documentation.value->type() == v:t_string
+         d.info = item.documentation.value
+       endif
       endif
     endif
 
@@ -320,14 +320,14 @@ def ShowCompletionDocumentation(cItem: any)
     if cItem.documentation->type() == v:t_dict
       # MarkupContent
       if cItem.documentation.kind == 'plaintext'
-        infoText->extend(cItem.documentation.value->split("\n"))
-        infoKind = 'text'
+       infoText->extend(cItem.documentation.value->split("\n"))
+       infoKind = 'text'
       elseif cItem.documentation.kind == 'markdown'
-        infoText->extend(cItem.documentation.value->split("\n"))
-        infoKind = 'lspgfm'
+       infoText->extend(cItem.documentation.value->split("\n"))
+       infoKind = 'lspgfm'
       else
-        util.ErrMsg($'Error: Unsupported documentation type ({cItem.documentation.kind})')
-        return
+       util.ErrMsg($'Error: Unsupported documentation type ({cItem.documentation.kind})')
+       return
       endif
     elseif cItem.documentation->type() == v:t_string
       infoText->extend(cItem.documentation->split("\n"))
@@ -364,7 +364,7 @@ enddef
 # process the 'completionItem/resolve' reply from the LSP server
 # Result: CompletionItem
 export def CompletionResolveReply(lspserver: dict<any>, cItem: any)
-    ShowCompletionDocumentation(cItem)
+  ShowCompletionDocumentation(cItem)
 enddef
 
 # omni complete handler
@@ -474,9 +474,9 @@ def LspResolve()
   var item = v:event.completed_item
   if item->has_key('user_data') && !item.user_data->empty()
       if !item.user_data->has_key('documentation')
-        lspserver.resolveCompletion(item.user_data)
+       lspserver.resolveCompletion(item.user_data)
       else
-        ShowCompletionDocumentation(item.user_data)
+       ShowCompletionDocumentation(item.user_data)
       endif
   endif
 enddef
@@ -567,9 +567,9 @@ export def BufferInit(lspserver: dict<any>, bnr: number, ftype: string)
   endif
 
   acmds->add({bufnr: bnr,
-                 event: 'CompleteChanged',
-                 group: 'LSPBufferAutocmds',
-                 cmd: 'LspSetPopupFileType()'})
+             event: 'CompleteChanged',
+             group: 'LSPBufferAutocmds',
+             cmd: 'LspSetPopupFileType()'})
 
   # Execute LSP server initiated text edits after completion
   acmds->add({bufnr: bnr,
index e52f3ad56e0b09fbf480ce8fecd9b0704db84578..845787a5ca09ff7d1f7ed78f0da2d03b0d2a243f 100644 (file)
@@ -27,25 +27,33 @@ def LspRunTests()
     v:errmsg = ''
     try
       :%bw!
-      exe 'g:' .. f
+      exe $'g:{f}'
     catch
-      call add(v:errors, "Error: Test " .. f .. " failed with exception " .. v:exception .. " at " .. v:throwpoint)
+      call add(v:errors, $'Error: Test {f} failed with exception {v:exception} at {v:throwpoint}')
     endtry
     if v:errmsg != ''
-      call add(v:errors, "Error: Test " .. f .. " generated error " .. v:errmsg)
+      call add(v:errors, $'Error: Test {f} generated error {v:errmsg}')
     endif
     if !v:errors->empty()
       writefile(v:errors, 'results.txt', 'a')
-      writefile([f .. ': FAIL'], 'results.txt', 'a')
+      writefile([$'{f}: FAIL'], 'results.txt', 'a')
     else
-      writefile([f .. ': pass'], 'results.txt', 'a')
+      writefile([$'{f}: pass'], 'results.txt', 'a')
     endif
   endfor
 enddef
 
-exe 'source ' .. g:TestName
+try
 
-g:StartLangServer()
+  exe $'source {g:TestName}'
+  g:StartLangServer()
+
+catch
+
+  call add(v:errors, $'Error: Failed to start language server for {g:TestName} with exception {v:exception} at {v:throwpoint}')
+  qall!
+
+endtry
 
 LspRunTests()
 qall!