]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add a simple rust language server test
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 11 Feb 2024 04:37:09 +0000 (20:37 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 11 Feb 2024 04:37:09 +0000 (20:37 -0800)
.github/workflows/unitests.yml
test/run_tests.sh
test/rust_tests.vim [new file with mode: 0644]

index 245157ee34fdb273637cb80ddfa63bbd4fe22e46..52c7667fe872a320a46ca2e4efdbcb5a654daabc 100644 (file)
@@ -25,6 +25,7 @@ jobs:
           sudo apt install -y golang
           sudo apt install -y gopls
           # install the rust language server
+          sudo apt install -y cargo rust-src
           mkdir -p ~/.local/bin
           curl -L https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip -c - > ~/.local/bin/rust-analyzer
           chmod +x ~/.local/bin/rust-analyzer
index e99590538d096ff631d87fce90e422bd5a2120c1..1a1e69bf7243c647153218761687429840849c9e 100755 (executable)
@@ -10,7 +10,7 @@ fi
 
 VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term"
 
-TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim"
+TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim rust_tests.vim"
 
 RunTestsInFile() {
   testfile=$1
diff --git a/test/rust_tests.vim b/test/rust_tests.vim
new file mode 100644 (file)
index 0000000..d6402d8
--- /dev/null
@@ -0,0 +1,58 @@
+vim9script
+# Unit tests for LSP rust-analyzer client
+
+source common.vim
+source term_util.vim
+source screendump.vim
+
+var lspServers = [{
+      filetype: ['rust'],
+      path: exepath('rust-analyzer'),
+      args: []
+  }]
+call LspAddServer(lspServers)
+echomsg systemlist($'{lspServers[0].path} --version')
+
+def g:Test_LspGotoDef()
+  settagstack(0, {items: []})
+  :cd xrust_tests/src
+  try
+    silent! edit ./main.rs
+    sleep 600m
+    var lines: list<string> =<< trim END
+      fn foo() {
+      }
+      fn bar() {
+        foo();
+      }
+    END
+    append('$', lines)
+    g:WaitForServerFileLoad(0)
+    cursor(7, 5)
+    :LspGotoDefinition
+    assert_equal([4, 4], [line('.'), col('.')])
+    :%bw!
+  finally
+    :cd ../..
+  endtry
+enddef
+
+def g:Test_ZZZ_Cleanup()
+  delete('./xrust_tests', 'rf')
+enddef
+
+# Start the rust-analyzer language server.  Returns true on success and false
+# on failure.
+def g:StartLangServer(): bool
+  system('cargo new xrust_tests')
+  :cd xrust_tests/src
+  var status = false
+  try
+    status = g:StartLangServerWithFile('./main.rs')
+  finally
+    :cd ../..
+  endtry
+  return status
+enddef
+
+# vim: shiftwidth=2 softtabstop=2 noexpandtab