]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add tests for the Go language server
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 26 Mar 2023 15:11:21 +0000 (08:11 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 26 Mar 2023 15:11:21 +0000 (08:11 -0700)
.github/workflows/unitests.yml
test/gopls_tests.vim [new file with mode: 0644]
test/run_tests.sh
test/tsserver_tests.vim

index d7af3c6b7fa6656f569b30b10d7d8e4696d157bd..6dc7144739bcfdde94965231d6c5318be025b9e2 100644 (file)
@@ -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 (file)
index 0000000..a574009
--- /dev/null
@@ -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! \<C-t>"
+  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
index d9dc265af7c875470949f4d6487b42d246b35705..b7bde7fb2f3426cc0c25d8de3fc5f33da550ca80 100755 (executable)
@@ -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
index 156cfc8daa60c9a4f5e53d3f251b351af7ffc2a9..68f7d5bd036743b40dfb17c060fd493c2633a3a3 100644 (file)
@@ -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