From 1054ca9a336559e7f852c049f7723aa794a6ced3 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Mon, 5 Jun 2023 18:49:19 -0700 Subject: [PATCH] Fix test failures --- autoload/lsp/buffer.vim | 2 +- autoload/lsp/completion.vim | 4 +- autoload/lsp/diag.vim | 4 +- autoload/lsp/lsp.vim | 30 ++++++------ autoload/lsp/lspserver.vim | 6 +-- autoload/lsp/outline.vim | 6 +-- autoload/lsp/textedit.vim | 2 +- autoload/lsp/util.vim | 10 ++-- test/clangd_tests.vim | 96 +++++++++++++++++++------------------ 9 files changed, 83 insertions(+), 77 deletions(-) diff --git a/autoload/lsp/buffer.vim b/autoload/lsp/buffer.vim index 9d9d348..62d5915 100644 --- a/autoload/lsp/buffer.vim +++ b/autoload/lsp/buffer.vim @@ -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 var fname: string = @% - if fname == '' + if fname->empty() return {} endif diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 5e7710d..e7fd324 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -120,7 +120,7 @@ def CompletionUltiSnips(prefix: string, items: list>) 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 diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index e3f8fa5..81eb657 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -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() diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 00aadac..8c3859f 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -201,7 +201,7 @@ def ShowServer(arg: string) var windowName: string = '' var lines: list = [] - 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> = LspGetServers(bnr, ftype) @@ -648,7 +648,7 @@ export def AddServer(serverList: list>) 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 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('') 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('')) - 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 diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 201c097..c2d0763 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -165,7 +165,7 @@ def InitServer(lspserver: dict, 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, request: dict, result: any, error: dict) 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, triggerKind_arg: number, triggerChar: st endif var fname = @% - if fname == '' + if fname->empty() return endif diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index 88d6a43..ad0cc36 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -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 diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim index 8471ed0..374d907 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -171,7 +171,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list>): 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 diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index c956ee8..220d14c 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -261,7 +261,7 @@ export def JumpToLspLocation(location: dict, 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): string var foundDirs: dict = {} 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 diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index dcd418c..c630b49 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -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 =<< 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 @@ -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 =<< 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 =<< 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 =<< 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 =<< 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 @@ -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 =<< 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 =<< trim END #include @@ -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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< 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 =<< trim END typedef struct Foo_ { @@ -1668,12 +1670,12 @@ def g:Test_OmniComplete_FirstColumn() feedkeys("G0i\\", '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 =<< trim END #include @@ -1690,12 +1692,12 @@ def g:Test_OmniComplete_Multibyte() cursor(5, 36) feedkeys("cwthis\\", '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 =<< trim END struct test_ { @@ -1721,12 +1723,12 @@ def g:Test_OmniComplete_Struct() cursor(11, 12) feedkeys("cw\\\\\", '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 =<< 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: -- 2.48.1