From: Yegappan Lakshmanan Date: Sun, 26 Mar 2023 15:11:21 +0000 (-0700) Subject: Add tests for the Go language server X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0de044604d6782e82026145510f065c561b4ce91;p=vim-lsp.git Add tests for the Go language server --- diff --git a/.github/workflows/unitests.yml b/.github/workflows/unitests.yml index d7af3c6..6dc7144 100644 --- a/.github/workflows/unitests.yml +++ b/.github/workflows/unitests.yml @@ -8,11 +8,17 @@ jobs: - name: Install packages run: | sudo apt update + # install clangd language server sudo apt install -y clangd-14 + # install nodejs sudo apt install -y curl curl -fsSL https://deb.nodesource.com/setup_18.x | sudo bash - sudo apt install -y nodejs + # install typescript language server sudo npm install -g typescript-language-server typescript + # install golang language server + sudo apt install -y golang + sudo apt install -y gopls - name: Setup Vim uses: rhysd/action-setup-vim@v1 id: vim diff --git a/test/gopls_tests.vim b/test/gopls_tests.vim new file mode 100644 index 0000000..a574009 --- /dev/null +++ b/test/gopls_tests.vim @@ -0,0 +1,49 @@ +vim9script +# Unit tests for Vim Language Server Protocol (LSP) golang client + +source common.vim + +var lspServers = [{ + filetype: ['go'], + path: exepath('gopls'), + args: ['serve'] + }] +call LspAddServer(lspServers) +echomsg systemlist($'{lspServers[0].path} version') + +# Test for :LspGotoDefinition, :LspGotoDeclaration, etc. +def g:Test_LspGoto() + :silent! edit Xtest.go + sleep 200m + + var lines =<< trim END + package main + + func foo() { + } + + func bar() { + foo(); + } + END + + setline(1, lines) + :redraw! + g:WaitForServerFileLoad(0) + + cursor(7, 1) + :LspGotoDefinition + assert_equal([3, 6], [line('.'), col('.')]) + exe "normal! \" + assert_equal([7, 1], [line('.'), col('.')]) + + bw! +enddef + +# Start the gopls language server. Returns true on success and false on +# failure. +def g:StartLangServer(): bool + return g:StartLangServerWithFile('Xtest.go') +enddef + +# vim: shiftwidth=2 softtabstop=2 noexpandtab diff --git a/test/run_tests.sh b/test/run_tests.sh index d9dc265..b7bde7f 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -10,7 +10,7 @@ fi VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term" -TESTS="tsserver_tests.vim clangd_tests.vim" +TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim" for testfile in $TESTS do diff --git a/test/tsserver_tests.vim b/test/tsserver_tests.vim index 156cfc8..68f7d5b 100644 --- a/test/tsserver_tests.vim +++ b/test/tsserver_tests.vim @@ -94,9 +94,10 @@ def g:Test_LspDiag() endfor g:LspOptionsSet({showDiagInPopup: true}) - :%bw! + bw! enddef +# Test for :LspGotoDefinition, :LspGotoDeclaration, etc. def g:Test_LspGoto() :silent! edit Xtest.ts sleep 200m @@ -160,6 +161,8 @@ def g:Test_LspGoto() assert_equal(3, line('.')) assert_equal([], popup_list()) popup_clear() + + bw! enddef # Test for auto-completion. Make sure that only keywords that matches with the