]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Fix test failures
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 6 Jun 2023 01:49:19 +0000 (18:49 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 6 Jun 2023 01:49:19 +0000 (18:49 -0700)
autoload/lsp/buffer.vim
autoload/lsp/completion.vim
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
autoload/lsp/outline.vim
autoload/lsp/textedit.vim
autoload/lsp/util.vim
test/clangd_tests.vim

index 9d9d348204cf5b14dfaf01b05bc1cbc9865569f7..62d591562b08bfa82188b4699bc7515f9b12ffc4 100644 (file)
@@ -151,7 +151,7 @@ enddef
 # Returns an empty dict if the server is not found or is not ready.
 export def CurbufGetServerChecked(feature: string = null_string): dict<any>
   var fname: string = @%
-  if fname == ''
+  if fname->empty()
     return {}
   endif
 
index 5e7710dda200d7a9e275dca408854cee92855cce..e7fd32499b2d96c09c60092c7a86e7ef1a02f272 100644 (file)
@@ -120,7 +120,7 @@ def CompletionUltiSnips(prefix: string, items: list<dict<any>>)
     var txt = parts[0]->readfile()[parts[1]->str2nr() : parts[1]->str2nr() + 20]
     var restxt = item.description .. "\n\n"
     for line in txt
-      if line == "" || line[0 : 6] == "snippet"
+      if line->empty() || line[0 : 6] == "snippet"
        break
       else
        restxt = restxt .. line .. "\n"
@@ -524,7 +524,7 @@ def g:LspOmniFunc(findstart: number, base: string): any
     var prefix = lspserver.omniCompleteKeyword
 
     # Don't attempt to filter on the items, when "isIncomplete" is set
-    if prefix == '' || lspserver.completeItemsIsIncomplete
+    if prefix->empty() || lspserver.completeItemsIsIncomplete
       return res
     endif
 
index e3f8fa5a2b192656e563241caeece24a6cf93a2e..81eb6572853b1f2dfa207881cbdfa06b642ab591 100644 (file)
@@ -380,7 +380,7 @@ enddef
 # Returns true if diagnostics is not empty and false if it is empty.
 def DiagsUpdateLocList(bnr: number): bool
   var fname: string = bnr->bufname()->fnamemodify(':p')
-  if fname == ''
+  if fname->empty()
     return false
   endif
 
@@ -602,7 +602,7 @@ enddef
 # jump to the next/previous/first diagnostic message in the current buffer
 export def LspDiagsJump(which: string, a_count: number = 0): void
   var fname: string = expand('%:p')
-  if fname == ''
+  if fname->empty()
     return
   endif
   var bnr: number = bufnr()
index 00aadac6cb7fef136f0ff3740c52bb8f3c08d694..8c3859f3baf66e287398433a6199d0932adf2d5f 100644 (file)
@@ -201,7 +201,7 @@ def ShowServer(arg: string)
 
   var windowName: string = ''
   var lines: list<string> = []
-  if arg == '' || arg == 'status'
+  if arg->empty() || arg == 'status'
     windowName = $'LangServer-Status'
     for lspserver in lspservers
       if !lines->empty()
@@ -485,7 +485,7 @@ export def AddFile(bnr: number): void
   endif
 
   var ftype: string = bnr->getbufvar('&filetype')
-  if ftype == ''
+  if ftype->empty()
     return
   endif
   var lspservers: list<dict<any>> = LspGetServers(bnr, ftype)
@@ -648,7 +648,7 @@ export def AddServer(serverList: list<dict<any>>)
     endif
 
     if !server->has_key('name') || server.name->type() != v:t_string
-                                                       || server.name == ''
+                                                       || server.name->empty()
       # Use the executable name (without the extension) as the language server
       # name.
       server.name = server.path->fnamemodify(':t:r')
@@ -704,7 +704,7 @@ enddef
 # received ('initialize' LSP reply message)
 export def ServerReady(): bool
   var fname: string = @%
-  if fname == ''
+  if fname->empty()
     return false
   endif
 
@@ -755,7 +755,7 @@ enddef
 # Display the diagnostics for the current line in the status line.
 export def LspShowCurrentDiagInStatusLine()
   var fname: string = @%
-  if fname == ''
+  if fname->empty()
     return
   endif
 
@@ -766,7 +766,7 @@ enddef
 export def ErrorCount(): dict<number>
   var res = {Error: 0, Warn: 0, Info: 0, Hint: 0}
   var fname: string = @%
-  if fname == ''
+  if fname->empty()
     return res
   endif
 
@@ -831,7 +831,7 @@ def g:LspRequestDocSymbols()
   endif
 
   var fname: string = @%
-  if fname == ''
+  if fname->empty()
     return
   endif
 
@@ -914,10 +914,10 @@ export def Rename(a_newName: string)
   endif
 
   var newName: string = a_newName
-  if newName == ''
+  if newName->empty()
     var sym: string = expand('<cword>')
     newName = input($"Rename symbol '{sym}' to: ", sym)
-    if newName == ''
+    if newName->empty()
       return
     endif
 
@@ -960,9 +960,9 @@ export def SymbolSearch(queryArg: string)
   endif
 
   var query: string = queryArg
-  if query == ''
+  if query->empty()
     query = input('Lookup symbol: ', expand('<cword>'))
-    if query == ''
+    if query->empty()
       return
     endif
   endif
@@ -982,9 +982,9 @@ enddef
 # Add a workspace folder. Default is to use the current folder.
 export def AddWorkspaceFolder(dirArg: string)
   var dirName: string = dirArg
-  if dirName == ''
+  if dirName->empty()
     dirName = input('Add Workspace Folder: ', getcwd(), 'dir')
-    if dirName == ''
+    if dirName->empty()
       return
     endif
   endif
@@ -1004,9 +1004,9 @@ enddef
 # Remove a workspace folder. Default is to use the current folder.
 export def RemoveWorkspaceFolder(dirArg: string)
   var dirName: string = dirArg
-  if dirName == ''
+  if dirName->empty()
     dirName = input('Remove Workspace Folder: ', getcwd(), 'dir')
-    if dirName == ''
+    if dirName->empty()
       return
     endif
   endif
index 201c097bf7407d62ed9b979693e667bb0e899c17..c2d07639ea9296f6de7e8bef42e478c28a122ee1 100644 (file)
@@ -165,7 +165,7 @@ def InitServer(lspserver: dict<any>, bnr: number)
   if !rootSearchFiles->empty()
     rootPath = util.FindNearestRootDir(bufDir, rootSearchFiles)
   endif
-  if rootPath == ''
+  if rootPath->empty()
     var cwd = getcwd()
 
     # bufDir is within cwd
@@ -319,7 +319,7 @@ enddef
 def SendResponse(lspserver: dict<any>, request: dict<any>, result: any, error: dict<any>)
   if (request.id->type() == v:t_string
        && (request.id->trim() =~ '[^[:digit:]]\+'
-           || request.id->trim() == ''))
+           || request.id->trim()->empty()))
     || (request.id->type() != v:t_string && request.id->type() != v:t_number)
     util.ErrMsg('request.id of response to LSP server is not a correct number')
     return
@@ -622,7 +622,7 @@ def GetCompletion(lspserver: dict<any>, triggerKind_arg: number, triggerChar: st
   endif
 
   var fname = @%
-  if fname == ''
+  if fname->empty()
     return
   endif
 
index 88d6a43bac56948a292354bb27880c568327ce89..ad0cc36c023e1e550e2b1e63826929a53196be96 100644 (file)
@@ -29,7 +29,7 @@ def OutlineJumpToSymbol()
   if wid == -1
     # Find a window showing a normal buffer and use it
     for w in getwininfo()
-      if w.winid->getwinvar('&buftype') == ''
+      if w.winid->getwinvar('&buftype')->empty()
        wid = w.winid
        wid->win_gotoid()
        break
@@ -145,7 +145,7 @@ enddef
 
 def OutlineHighlightCurrentSymbol()
   var fname: string = expand('%')->fnamemodify(':p')
-  if fname == '' || &filetype == ''
+  if fname->empty() || &filetype->empty()
     return
   endif
 
@@ -227,7 +227,7 @@ export def OpenOutlineWindow(cmdmods: string, winsize: number)
   var prevWinID: number = win_getid()
 
   var mods = cmdmods
-  if mods == ''
+  if mods->empty()
     if opt.lspOptions.outlineOnRight
       mods = ':vert :botright'
     else
index 8471ed0ef705b52f738f130fc775bf7e0a9d95b8..374d9075c6c5edf995e520ac37b66878d7064bcd 100644 (file)
@@ -171,7 +171,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list<dict<any>>): void
   # lines.
   var dellastline: bool = false
   if start_line == 0 && bnr->getbufinfo()[0].linecount == 1 &&
-                                       util.GetBufOneLine(bnr, 1) == ''
+                                       util.GetBufOneLine(bnr, 1)->empty()
     dellastline = true
   endif
 
index c956ee80e65cf9342253f5573463a03f0f009077..220d14cb60630f3c7d82f479af7db186c9b01489 100644 (file)
@@ -261,7 +261,7 @@ export def JumpToLspLocation(location: dict<any>, cmdmods: string)
   var fname = LspUriToFile(uri)
 
   # jump to the file and line containing the symbol
-  if cmdmods == ''
+  if cmdmods->empty()
     var bnr: number = fname->bufnr()
     if bnr == bufnr()
       # Set the previous cursor location mark. Instead of using setpos(), m' is
@@ -324,7 +324,7 @@ export def FindNearestRootDir(startDir: string, files: list<any>): string
   var foundDirs: dict<bool> = {}
 
   for file in files
-    if file->type() != v:t_string || file == ''
+    if file->type() != v:t_string || file->empty()
       continue
     endif
     var isDir = file[-1 : ] == '/' || file[-1 : ] == '\'
@@ -358,7 +358,11 @@ export def GetBufOneLine(bnr: number, lnum: number): string
     # getbufoneline() was introduced in patch 9.0.0916
     return bnr->getbufoneline(lnum)
   else
-    return bnr->getbufline(lnum)[0]
+    var l = bnr->getbufline(lnum)
+    if l->empty()
+      return ''
+    endif
+    return l[0]
   endif
 enddef
 
index dcd418cad441b3ae03b44eed477da5e7aaff639e..c630b49ff8c885204f2de70d0892ff73cc788587 100644 (file)
@@ -38,7 +38,7 @@ echomsg clangdVerDetail
 
 # Test for formatting a file using LspFormat
 def g:Test_LspFormat()
-  :silent! edit Xtest.c
+  :silent! edit XLspFormat.c
   sleep 200m
   setline(1, ['  int i;', '  int j;'])
   :redraw!
@@ -133,7 +133,7 @@ enddef
 
 # Test for :LspFormat when using composing characters
 def g:Test_LspFormat_ComposingChars()
-  :silent! edit Xtest.c
+  :silent! edit XLspFormatComposing.c
   sleep 200m
   var lines =<< trim END
     void fn(int aVar)
@@ -160,7 +160,7 @@ enddef
 
 # Test for formatting a file using 'formatexpr'
 def g:Test_LspFormatExpr()
-  :silent! edit Xtest.c
+  :silent! edit XLspFormat.c
   sleep 200m
   setlocal formatexpr=lsp#lsp#FormatExpr()
   setline(1, ['  int i;', '  int j;'])
@@ -315,7 +315,7 @@ enddef
 
 # Test for LSP diagnostics
 def g:Test_LspDiag()
-  :silent! edit Xtest.c
+  :silent! edit XLspDiag.c
   sleep 200m
   var lines: list<string> =<< trim END
     void blueFunc()
@@ -399,7 +399,7 @@ enddef
 
 # Test for :LspDiagShow when using composing characters
 def g:Test_LspDiagShow_ComposingChars()
-  :silent! edit Xtest.c
+  :silent! edit XDiagShowCompose.c
   sleep 200m
   var lines =<< trim END
     #include <stdio.h>
@@ -428,7 +428,7 @@ def g:Test_LspProcessDiagHandler()
   g:LSPTest_modifyDiags = true
   g:LspOptionsSet({showDiagInPopup: false})
 
-  :silent! edit Xtest.c
+  :silent! edit XLspProcessDiag.c
   sleep 200m
   var lines: list<string> =<< trim END
     void blueFunc()
@@ -454,7 +454,7 @@ enddef
 
 # Test that the client have been able to configure the server to speak utf-32
 def g:Test_UnicodeColumnCalc()
-  :silent! edit Xtest.c
+  :silent! edit XUnicodeColumn.c
   sleep 200m
   var lines: list<string> =<< trim END
     int count;
@@ -483,12 +483,12 @@ def g:Test_UnicodeColumnCalc()
               execute('LspGotoDefinition')->split("\n"))
   assert_equal([2, 12], [line('.'), col('.')])
 
-  bw!
+  :%bw!
 enddef
 
 # Test for multiple LSP diagnostics on the same line
 def g:Test_LspDiag_Multi()
-  :silent! edit Xtest.c
+  :silent! edit XLspDiagMulti.c
   sleep 200m
 
   var bnr: number = bufnr()
@@ -639,12 +639,12 @@ def g:Test_LspDiag_Multi()
   assert_equal([1, 5], [line('.'), col('.')])
   g:LspOptionsSet({showDiagInPopup: true})
 
-  bw!
+  :%bw!
 enddef
 
 # Test for highlight diag inline
 def g:Test_LspHighlightDiagInline()
-  :silent! edit Xtest.c
+  :silent! edit XLspHighlightDiag.c
   sleep 200m
   setline(1, [
     'int main()',
@@ -676,12 +676,12 @@ def g:Test_LspHighlightDiagInline()
   props = prop_list(6)
   assert_equal(0, props->len())
 
-  bw!
+  :%bw!
 enddef
 
 # Test for :LspCodeAction
 def g:Test_LspCodeAction()
-  silent! edit Xtest.c
+  silent! edit XLspCodeAction.c
   sleep 200m
   var lines: list<string> =<< trim END
     void testFunc()
@@ -713,7 +713,7 @@ def g:Test_LspCodeAction()
   bw!
 
   # pattern and string prefix
-  silent! edit Xtest.c
+  silent! edit XLspCodeActionPattern.c
   sleep 200m
   var lines2: list<string> =<< trim END
     void testFunc()
@@ -760,7 +760,7 @@ enddef
 
 # Test for :LspCodeAction with symbols containing composing characters
 def g:Test_LspCodeAction_ComposingChars()
-  silent! edit Xtest.c
+  silent! edit XLspCodeActionComposing.c
   sleep 200m
   var lines =<< trim END
     #include <stdio.h>
@@ -788,12 +788,12 @@ def g:Test_LspCodeAction_ComposingChars()
   :LspCodeAction 1
   assert_equal('    printf("ą́ą́ą́ą́ = %d\n", aVar);', getline(7))
 
-  :bw!
+  :%bw!
 enddef
 
 # Test for :LspRename
 def g:Test_LspRename()
-  silent! edit Xtest.c
+  silent! edit XLspRename.c
   sleep 200m
   var lines: list<string> =<< trim END
     void F1(int count)
@@ -863,7 +863,7 @@ enddef
 
 # Test for :LspRename with composing characters
 def g:Test_LspRename_ComposingChars()
-  silent! edit Xtest.c
+  silent! edit XLspRenameComposing.c
   sleep 200m
   var lines: list<string> =<< trim END
     #include <stdio.h>
@@ -897,7 +897,7 @@ enddef
 
 # Test for :LspSelectionExpand and :LspSelectionShrink
 def g:Test_LspSelection()
-  silent! edit Xtest.c
+  silent! edit XLspSelection.c
   sleep 200m
   var lines: list<string> =<< trim END
     void F1(int count)
@@ -998,7 +998,7 @@ enddef
 # Test for :LspGotoDefinition, :LspGotoDeclaration and :LspGotoImpl
 def g:Test_LspGotoSymbol()
   settagstack(0, {items: []})
-  silent! edit Xtest.cpp
+  silent! edit XLspGotoSymbol.cpp
   sleep 600m
   var lines: list<string> =<< trim END
     class base {
@@ -1192,7 +1192,7 @@ enddef
 
 # Test for :LspHighlight
 def g:Test_LspHighlight()
-  silent! edit Xtest.c
+  silent! edit XLspHighlight.c
   sleep 200m
   var lines: list<string> =<< trim END
     void f1(int arg)
@@ -1231,7 +1231,7 @@ enddef
 
 # Test for :LspHover
 def g:Test_LspHover()
-  silent! edit Xtest.c
+  silent! edit XLspHover.c
   sleep 200m
   var lines: list<string> =<< trim END
     int f1(int a)
@@ -1282,7 +1282,7 @@ enddef
 
 # Test for :LspShowSignature
 def g:Test_LspShowSignature()
-  silent! edit Xtest.c
+  silent! edit XLspShowSignature.c
   sleep 200m
   var lines: list<string> =<< trim END
     int MyFunc(int a, int b)
@@ -1325,7 +1325,7 @@ enddef
 
 # Test for :LspSymbolSearch
 def g:Test_LspSymbolSearch()
-  silent! edit Xtest.c
+  silent! edit XLspSymbolSearch.c
   sleep 200m
   var lines: list<string> =<< trim END
     void lsptest_funcA()
@@ -1363,7 +1363,7 @@ enddef
 
 # Test for :LspSymbolSearch when using composing characters
 def g:Test_LspSymbolSearch_ComposingChars()
-  silent! edit Xtest.c
+  silent! edit XLspSymbolSearchCompose.c
   sleep 200m
   var lines: list<string> =<< trim END
     typedef void 😊😊😊😊;
@@ -1400,7 +1400,7 @@ enddef
 
 # Test for :LspIncomingCalls
 def g:Test_LspIncomingCalls()
-  silent! edit Xtest.c
+  silent! edit XLspIncomingCalls.c
   sleep 200m
   var lines: list<string> =<< trim END
     void xFunc(void)
@@ -1424,15 +1424,15 @@ def g:Test_LspIncomingCalls()
   assert_equal([1, 2], [winnr(), winnr('$')])
   var l = getline(1, '$')
   assert_equal('# Incoming calls to "xFunc"', l[0])
-  assert_match('- xFunc (Xtest.c \[.*\])', l[1])
-  assert_match('  + aFunc (Xtest.c \[.*\])', l[2])
-  assert_match('  + bFunc (Xtest.c \[.*\])', l[3])
+  assert_match('- xFunc (XLspIncomingCalls.c \[.*\])', l[1])
+  assert_match('  + aFunc (XLspIncomingCalls.c \[.*\])', l[2])
+  assert_match('  + bFunc (XLspIncomingCalls.c \[.*\])', l[3])
   :%bw!
 enddef
 
 # Test for :LspOutline
 def g:Test_LspOutline()
-  silent! edit Xtest.c
+  silent! edit XLspOutline.c
   sleep 200m
   var lines: list<string> =<< trim END
     void aFunc(void)
@@ -1520,8 +1520,8 @@ def g:Test_LspTagFunc()
     {
     }
   END
-  writefile(lines, 'Xtest.c')
-  :silent! edit Xtest.c
+  writefile(lines, 'Xtagfunc.c')
+  :silent! edit Xtagfunc.c
   g:WaitForServerFileLoad(1)
   :setlocal tagfunc=lsp#lsp#TagFunc
   cursor(3, 4)
@@ -1532,7 +1532,7 @@ def g:Test_LspTagFunc()
 
   :set tagfunc&
   :%bw!
-  delete('Xtest.c')
+  delete('Xtagfunc.c')
 enddef
 
 # Test for setting the 'tagfunc' with composing characters in symbols
@@ -1548,8 +1548,8 @@ def g:Test_LspTagFunc_ComposingChars()
         dVar = 10;
     }
   END
-  writefile(lines, 'Xtest.c', 'D')
-  :silent! edit! Xtest.c
+  writefile(lines, 'XtagfuncCompose.c')
+  :silent! edit! XtagfuncCompose.c
   g:WaitForServerFileLoad(0)
   :setlocal tagfunc=lsp#lsp#TagFunc
   cursor(6, 5)
@@ -1564,13 +1564,14 @@ def g:Test_LspTagFunc_ComposingChars()
   :set tagfunc&
 
   :%bw!
+  delete('XtagfuncCompose.c')
 enddef
 
 # Test for the LspDiagsUpdated autocmd
 def g:Test_LspDiagsUpdated_Autocmd()
   g:LspAutoCmd = 0
   autocmd_add([{event: 'User', pattern: 'LspDiagsUpdated', cmd: 'g:LspAutoCmd = g:LspAutoCmd + 1'}])
-  silent! edit Xtest.c
+  silent! edit XLspDiagsAutocmd.c
   sleep 200m
   var lines: list<string> =<< trim END
     void aFunc(void)
@@ -1588,7 +1589,7 @@ def g:Test_LspDiagsUpdated_Autocmd()
   g:WaitForDiags(0)
   :%bw!
   autocmd_delete([{event: 'User', pattern: 'LspDiagsUpdated'}])
-  assert_equal(6, g:LspAutoCmd)
+  assert_equal(5, g:LspAutoCmd)
 enddef
 
 # Test custom notification handlers
@@ -1610,7 +1611,7 @@ def g:Test_LspCustomNotificationHandlers()
 enddef
 
 def g:Test_ScanFindIdent()
-  :silent! edit Xtest.c
+  :silent! edit XscanFindIdent.c
   sleep 200m
   var lines: list<string> =<< trim END
     int count;
@@ -1622,6 +1623,7 @@ def g:Test_ScanFindIdent()
     }
   END
   setline(1, lines)
+  g:WaitForServerFileLoad(0)
   :redraw!
 
   # LspGotoDefinition et al
@@ -1649,12 +1651,12 @@ def g:Test_ScanFindIdent()
   assert_equal('int counter;', getline(1))
   assert_equal('  return    counter + 1;', getline(6))
 
-  bw!
+  :%bw!
 enddef
 
 # Test for doing omni completion from the first column
 def g:Test_OmniComplete_FirstColumn()
-  :silent! edit Xtest.c
+  :silent! edit XOmniCompleteFirstColumn.c
   sleep 200m
   var lines: list<string> =<< trim END
     typedef struct Foo_ {
@@ -1668,12 +1670,12 @@ def g:Test_OmniComplete_FirstColumn()
 
   feedkeys("G0i\<C-X>\<C-O>", 'xt')
   assert_equal('Foo_t#define FOO 1', getline('.'))
-  :bw!
+  :%bw!
 enddef
 
 # Test for doing omni completion from the first column
 def g:Test_OmniComplete_Multibyte()
-  :silent! edit Xtest.c
+  :silent! edit XOmniCompleteMultibyte.c
   sleep 200m
   var lines: list<string> =<< trim END
     #include <string.h>
@@ -1690,12 +1692,12 @@ def g:Test_OmniComplete_Multibyte()
   cursor(5, 36)
   feedkeys("cwthis\<C-X>\<C-O>", 'xt')
   assert_equal('  int len = strlen("©©©©©") + thisVar;', getline('.'))
-  :bw!
+  :%bw!
 enddef
 
 # Test for doing omni completion from the first column
 def g:Test_OmniComplete_Struct()
-  :silent! edit Xtest.c
+  :silent! edit XOmniCompleteStruct.c
   sleep 200m
   var lines: list<string> =<< trim END
     struct test_ {
@@ -1721,12 +1723,12 @@ def g:Test_OmniComplete_Struct()
   cursor(11, 12)
   feedkeys("cw\<C-X>\<C-O>\<C-N>\<C-N>\<C-Y>", 'xt')
   assert_equal('    pTest->foo = 20;', getline('.'))
-  :bw!
+  :%bw!
 enddef
 
 # Test for doing omni completion for symbols with composing characters
 def g:Test_OmniComplete_ComposingChars()
-  :silent! edit Xtest.c
+  :silent! edit XOmniCompleteCompose.c
   sleep 200m
   var lines: list<string> =<< trim END
     void Func1(void)
@@ -1790,7 +1792,7 @@ def g:Test_LspServer()
               execute('LspServer trace xyz')->split("\n"))
   assert_equal(['Error: Unsupported argument "verbose xyz"'],
               execute('LspServer trace verbose xyz')->split("\n"))
-  :bw!
+  :%bw!
 enddef
 
 # TODO: