Skip to content

Commit

Permalink
Add a simple rust language server test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Feb 11, 2024
1 parent bc2f5c0 commit 2d24447
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/unitests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions test/rust_tests.vim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d24447

Please sign in to comment.