[WIP] do not merge: integration tests with language servers (#959)

* download rust-analyzer

* added empty testproject-rust

* add integration tests for LspDocumentFormatSync

* wipeout all buffer

* set shiftwidth and tabstop

* set gobal shiftwidth and tabstop

* remove tabstop

* sleep 100m

* remove l:got

* get latest line

* sleep 4000m

* use setl shiftwidth=4

* use %bwipeout!

* wait for rust-analyzer to start

* fix lint issues

* indent left

* remove log

* disable log

* set timeout to 10sec

* add 100m sleep

* download rust-analyzer for linux neovim

* add message to diagnostics test

* severity is optional in diagnostics

* download rust-analyzer for mac_neovim

* update README.md with test section
This commit is contained in:
Prabir Shrestha
2020-12-23 20:10:22 -08:00
committed by GitHub
parent 3176fd0fd4
commit 4ff1d41412
15 changed files with 151 additions and 6 deletions

View File

@@ -31,6 +31,13 @@ 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
@@ -38,6 +45,7 @@ jobs:
shell: bash
run: |
export PATH=~/nvim/bin:$PATH
export PATH=~/langservers:$PATH
export PATH=~/themis/bin:$PATH
export THEMIS_VIM=nvim
nvim --version

View File

@@ -33,6 +33,13 @@ 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
@@ -40,6 +47,7 @@ jobs:
shell: bash
run: |
export PATH=~/vim/bin:$PATH
export PATH=~/langservers:$PATH
export PATH=~/themis/bin:$PATH
export THEMIS_VIM=vim
vim --version

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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]], {})

View File

@@ -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

View File

@@ -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

View File

@@ -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}
\},
\]

1
test/testproject-rust/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
target/

5
test/testproject-rust/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "testproject-rust"
version = "0.1.0"

View File

@@ -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]

View File

@@ -0,0 +1,3 @@
fn format () {
unimplemented!();
}

View File

@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@@ -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