Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration tests with language servers #959

Merged
merged 25 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/linux_neovim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ jobs:
mkdir -p ~/nvim/bin
curl -L https://github.com/neovim/neovim/releases/download/${{matrix.neovim_version}}/nvim.appimage -o ~/nvim/bin/nvim
chmod u+x ~/nvim/bin/nvim
- name: Download language servers
shell: bash
run: |
mkdir -p ~/langservers
curl -L https://github.com/rust-analyzer/rust-analyzer/releases/download/2020-12-21/rust-analyzer-linux -o ~/langservers/rust-analyzer
chmod u+x ~/langservers/rust-analyzer
~/langservers/rust-analyzer --version
- name: Download test runner
shell: bash
run: git clone --depth 1 --branch v1.5.5 --single-branch https://github.com/thinca/vim-themis ~/themis
- name: Run tests
shell: bash
run: |
export PATH=~/nvim/bin:$PATH
export PATH=~/langservers:$PATH
export PATH=~/themis/bin:$PATH
export THEMIS_VIM=nvim
nvim --version
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/linux_vim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ jobs:
mkdir -p ~/vim/bin
curl -L https://github.com/vim/vim-appimage/releases/download/v${{matrix.vim_version}}/GVim-v${{matrix.vim_version}}.glibc${{matrix.glibc_version}}-x86_64.AppImage -o ~/vim/bin/vim
chmod u+x ~/vim/bin/vim
- name: Download language servers
shell: bash
run: |
mkdir -p ~/langservers
curl -L https://github.com/rust-analyzer/rust-analyzer/releases/download/2020-12-21/rust-analyzer-linux -o ~/langservers/rust-analyzer
chmod u+x ~/langservers/rust-analyzer
~/langservers/rust-analyzer --version
- name: Download test runner
shell: bash
run: git clone --depth 1 --branch v1.5.5 --single-branch https://github.com/thinca/vim-themis ~/themis
- name: Run tests
shell: bash
run: |
export PATH=~/vim/bin:$PATH
export PATH=~/langservers:$PATH
export PATH=~/themis/bin:$PATH
export THEMIS_VIM=vim
vim --version
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/mac_neovim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ jobs:
- name: Download test runner
shell: bash
run: git clone --depth 1 --branch v1.5.5 --single-branch https://github.com/thinca/vim-themis ~/themis
- name: Download language servers
shell: bash
run: |
mkdir -p ~/langservers
curl -L https://github.com/rust-analyzer/rust-analyzer/releases/download/2020-12-21/rust-analyzer-mac -o ~/langservers/rust-analyzer
chmod u+x ~/langservers/rust-analyzer
~/langservers/rust-analyzer --version
- name: Run tests
shell: bash
run: |
export PATH=~/nvim-osx64/bin:$PATH
export PATH=~/langservers:$PATH
export PATH=~/themis/bin:$PATH
export THEMIS_VIM=nvim
nvim --version
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,9 @@ let g:lsp_log_file = expand('~/vim-lsp.log')
" for asyncomplete.vim log
let g:asyncomplete_log_file = expand('~/asyncomplete.log')
```

## Tests

[vim-themis](https://github.com/thinca/vim-themis) is used for testing. To run
integration tests [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer)
exectuable must be in path.
2 changes: 1 addition & 1 deletion autoload/lsp/ui/vim/highlights.vim
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function! s:place_highlights(server_name, path, diagnostics) abort
let [l:line, l:start_col] = lsp#utils#position#lsp_to_vim(l:bufnr, l:item['range']['start'])
let [l:_, l:end_col] = lsp#utils#position#lsp_to_vim(l:bufnr, l:item['range']['end'])

let l:name = get(s:severity_sign_names_mapping, l:item['severity'], 'LspError')
let l:name = get(s:severity_sign_names_mapping, get(l:item, 'severity', 3), 'LspError')
let l:hl_name = l:name . 'Highlight'
call nvim_buf_add_highlight(l:bufnr, l:ns, l:hl_name, l:line - 1, l:start_col - 1, l:end_col - 1)
endfor
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsp/ui/vim/virtual.vim
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function! s:place_virtual(server_name, path, diagnostics) abort
for l:item in a:diagnostics
let l:line = l:item['range']['start']['line']

let l:name = get(s:severity_sign_names_mapping, l:item['severity'], 'LspError')
let l:name = get(s:severity_sign_names_mapping, get(l:item, 'severity', 3), 'LspError')
let l:hl_name = l:name . 'Virtual'
call nvim_buf_set_virtual_text(l:bufnr, l:ns, l:line,
\ [[g:lsp_virtual_text_prefix . l:item['message'], l:hl_name]], {})
Expand Down
6 changes: 6 additions & 0 deletions test/.themisrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ set encoding=utf-8
call themis#option('recursive', 1)
call themis#option('reporter', 'spec')
call themis#helper('command').with(themis#helper('assert'))

set runtimepath+=./test/utils

" let g:lsp_log_verbose = 1
" let g:lsp_log_file = expand("~/.config/nvim/data/lsp.log")
autocmd BufNewFile,BufRead *.rs setfiletype rust
37 changes: 37 additions & 0 deletions test/integration/rust/document_formatting.vimspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Describe integration#rust#document_formatting
Before
%bwipeout!
if lsp#test#hasproject('rust')
call lsp#test#openproject('rust', {})
endif
End

After all
%bwipeout!
call lsp#test#closeproject('rust')
End


It should correctly format document when using LspDocumentFormatSync
if !lsp#test#hasproject('rust')
Skip rust project not supported
endif

setl shiftwidth=4

normal! m'
execute printf('keepalt keepjumps edit %s', lsp#test#projectdir('rust') . '/src/documentformat.rs')
let l:original = getline(1, "$")

call execute('LspDocumentFormatSync')

let got = getline(1, "$")
let want = [
\ 'fn format() {',
\ ' unimplemented!();',
\ '}'
\ ]
Assert Equals(got, want)
End

End
8 changes: 4 additions & 4 deletions test/lsp/ui/vim/diagnostics.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Describe lsp#uivim#diagnostics

let l:tests = [
\{
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range}]}}},
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range, 'message': 'm'}]}}},
\ 'want': {'information': 0, 'hint': 0, 'warning': 0, 'error': 1}
\},
\{
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 2, 'range': l:range}]}}},
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 2, 'range': l:range, 'message': 'm'}]}}},
\ 'want': {'information': 0, 'hint': 0, 'warning': 1, 'error': 0}
\},
\{
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range}, {'severity': 2, 'range': l:range}]}}},
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range, 'message': 'm'}, {'severity': 2, 'range': l:range, 'message': 'm'}]}}},
\ 'want': {'information': 0, 'hint': 0, 'warning': 1, 'error': 1}
\},
\{
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range}, {'range': l:range}]}}},
\ 'input': {'response': {'params': {'uri': l:uri, 'diagnostics': [{'severity': 1, 'range': l:range, 'message': 'm'}, {'range': l:range, 'message': 'm'}]}}},
\ 'want': {'information': 0, 'hint': 0, 'warning': 0, 'error': 2}
\},
\]
Expand Down
1 change: 1 addition & 0 deletions test/testproject-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
5 changes: 5 additions & 0 deletions test/testproject-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/testproject-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "testproject-rust"
version = "0.1.0"
authors = ["Prabir Shrestha <mail@prabir.me>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions test/testproject-rust/src/documentformat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn format () {
unimplemented!();
}
3 changes: 3 additions & 0 deletions test/testproject-rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
51 changes: 51 additions & 0 deletions test/utils/autoload/lsp/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function! lsp#test#projectdir(name) abort
if a:name ==# 'rust'
return expand('%:p:h') .'/test/testproject-rust'
else
throw 'projectdir not supported for ' . a:name
endif
endfunction

function! lsp#test#openproject(name, options) abort
call lsp#enable()
if a:name ==# 'rust'
call lsp#register_server({
\ 'name': 'rust',
\ 'cmd': ['rust-analyzer'],
\ 'allowlist': ['rust'],
\ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'Cargo.toml'))},
\ 'capabilities': { 'experimental': { 'statusNotification': v:true } },
\ })
" status notification required to know ready status of rust analyzer
" for more info refer to: https://github.com/rust-analyzer/rust-analyzer/pull/5188

" open .rs file to trigger rust analyzer then close it
execute printf('keepalt keepjumps edit %s', lsp#test#projectdir(a:name) . '/src/documentformat.rs')
%bwipeout!

" wait for ready status from rust-analyzer
call lsp#callbag#pipe(
\ lsp#stream(),
\ lsp#callbag#filter({x->has_key(x, 'response') && has_key(x['response'], 'method')
\ && x['response']['method'] ==# 'rust-analyzer/status' && x['response']['params']['status'] ==# 'ready' }),
\ lsp#callbag#take(1),
\ lsp#callbag#toList(),
\ ).wait({ 'timeout': 10000, 'sleep': 100 })
else
throw 'open project not not supported for ' . a:name
endif
endfunction

function! lsp#test#closeproject(name) abort
if lsp#test#hasproject(a:name)
silent! call lsp#stop_sserver(a:name)
endif
endfunction

function! lsp#test#hasproject(name) abort
if a:name ==# 'rust' && executable('rust-analyzer')
return 1
else
return 0
endif
endfunction