.github/workflows/unitests.yml | 6 ++++++ test/gopls_tests.vim | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ test/run_tests.sh | 2 +- test/tsserver_tests.vim | 5 ++++- diff --git a/.github/workflows/unitests.yml b/.github/workflows/unitests.yml index d7af3c6b7fa6656f569b30b10d7d8e4696d157bd..6dc7144739bcfdde94965231d6c5318be025b9e2 100644 --- a/.github/workflows/unitests.yml +++ b/.github/workflows/unitests.yml @@ -8,11 +8,17 @@ steps: - 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 0000000000000000000000000000000000000000..a574009a1dbd1737790b99f755a0514f88683e5e --- /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 d9dc265af7c875470949f4d6487b42d246b35705..b7bde7fb2f3426cc0c25d8de3fc5f33da550ca80 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 156cfc8daa60c9a4f5e53d3f251b351af7ffc2a9..68f7d5bd036743b40dfb17c060fd493c2633a3a3 100644 --- a/test/tsserver_tests.vim +++ b/test/tsserver_tests.vim @@ -94,9 +94,10 @@ assert_equal("',' expected.", output[0]) 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 @@ feedkeys("jj\", 'xt') 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