I broke up with neovim....vim is my best friend now

This commit is contained in:
LinlyBoi
2023-04-30 08:14:07 +03:00
parent 0d185449c5
commit 4a4a6b1e81
5245 changed files with 468325 additions and 25 deletions

View File

@@ -0,0 +1,103 @@
Tests
=====
## Directory structure
- [`test/unit`](./unit): Unit tests
- [`test/unit/test.vimspec`](./unit/test.vimspec): Unit test cases
- [`test/unit/runtime`](./unit/runtime): Runtime directory loaded on running unit tests. They mocks several external APIs like `ale#*` or `lsp#*`
- [`test/integ`](./integ): Integration tests
- [`test/integ/test.vimspec`](./integ/test.vimspec): Integration test cases
- [`test/integ/deps`](./integ/deps): Dependant plugins
## Unit tests
Unit tests confirm vim-lsp-ale works as intended.
### Prerequisites
Unit tests can be run with no dependency because they mock every external API.
[vim-themis](https://github.com/thinca/vim-themis) is used as test runner.
By default, it runs tests with `vim` command. When running tests with Neovim, set `THEMIS_VIM=nvim` environment variable.
### Run unit tests
```sh
cd path/to/vim-lsp-ale
git clone https://github.com/thinca/vim-themis.git
# Run tests with Vim
./vim-themis/bin/themis ./test/unit/
# Run tests with NeoVim
THEMIS_VIM=nvim ./vim-themis/bin/themis ./test/unit/
```
### Measure unit test coverage
[covimerage](https://github.com/Vimjas/covimerage) is used to measure test coverage. Install it by `pip install covimerage`.
Set a file path to `THEMIS_PROFILE` environment variable and run unit tests. Vim will store the profile data to the file.
`covimerage` command will convert the profile data into coverage data for `coverage` command provided by Python.
```sh
cd path/to/vim-lsp-ale
git clone https://github.com/thinca/vim-themis.git
# Run test case with $THEMIS_PROFILE environment variable
THEMIS_PROFILE=profile.txt ./vim-themis/bin/themis ./test/unit
# Store coverage data at .coverage_covimerage converted from the profile data
covimerage write_coverage profile.txt
# Show coverage report by `coverage` command
coverage report
```
## Integration tests
Integration tests confirm integrity among vim-lsp, ALE, vim-lsp-ale and a language server.
### Prerequisites
Integration tests require all dependencies are installed in [deps](./integ/deps) directory.
```sh
cd path/to/vim-lsp-ale
git clone https://github.com/prabirshrestha/vim-lsp.git test/integ/deps/vim-lsp
git clone https://github.com/dense-analysis/ale.git test/integ/deps/ale
```
[rust-analyzer](https://rust-analyzer.github.io/) is used as language server to run integration tests.
Download the binary following [the instruction](https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary)
and put the binary in `$PATH` directory.
And [vim-themis](https://github.com/thinca/vim-themis) is used as test runner.
Note that integration tests were not confirmed on Windows.
### Run integration tests
```sh
cd path/to/vim-lsp-ale
git clone https://github.com/thinca/vim-themis.git
./vim-themis/bin/themis ./test/integ/
```
### Log files
When some integration tests fail, the following log files would be useful to investigate the failure.
- `test/integ/integ_messages.txt`: Messages in `:message` area while running the tests
- `test/integ/lsp-log.txt`: Log information of vim-lsp. It records communications between vim-lsp and a language server
## CI
Tests are run continuously on GitHub Actions.
https://github.com/rhysd/vim-lsp-ale/actions?query=workflow%3ACI
- Unit tests are run on Linux, macOS and Windows with Vim and Neovim
- Integration tests are run on Linux with Vim and Neovim

View File

@@ -0,0 +1,4 @@
/deps/vim-lsp
/deps/ale
/lsp-log.txt
/integ_messages.txt

View File

@@ -0,0 +1,44 @@
call themis#option('exclude', 'test/README.md')
let s:dir = expand('<sfile>:p:h')
let s:sep = has('win32') ? '\' : '/'
let s:vim_lsp_dir = join([s:dir, 'deps', 'vim-lsp'], s:sep)
let s:ale_dir = join([s:dir, 'deps', 'ale'], s:sep)
if !isdirectory(s:vim_lsp_dir)
throw 'vim-lsp is not cloned at ' . s:vim_lsp_dir
endif
if !isdirectory(s:ale_dir)
throw 'ALE is not cloned at ' . s:ale_dir
endif
function! IntegTestRootDir() abort
return s:dir
endfunction
execute 'set rtp+=' . s:vim_lsp_dir
execute 'set rtp+=' . s:ale_dir
filetype plugin indent on
let g:lsp_log_file = 'lsp-log.txt'
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'rust-analyzer',
\ 'cmd': { server_info -> ['rust-analyzer'] },
\ 'allowlist': ['rust'],
\ })
let g:ale_linters = { 'rust': ['vim-lsp'] }
runtime plugin/lsp_ale.vim
runtime plugin/lsp.vim
runtime plugin/ale.vim
" This is called automatically at VimEnter, but our tests load vim-lsp
" after the event. So manually call it here
call lsp#enable()
let s:helper = themis#helper('assert')
call themis#helper('command').with(s:helper)
" vim: set ft=vim:

View File

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

View File

@@ -0,0 +1,9 @@
[package]
name = "project"
version = "0.1.0"
authors = ["rhysd <lin90162@yahoo.co.jp>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,2 @@
/target
**/*.rs.bk

View File

@@ -0,0 +1,3 @@
pub fn do_something() {
let this_variable_is_unused = 42;
}

View File

@@ -0,0 +1,103 @@
let s:SEP = has('win32') ? '\' : '/'
function! s:get_debug_info(bufnr) abort
let uri = lsp#utils#get_buffer_uri(a:bufnr)
let all_diags = lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(uri)
return "\nall diags: " . string(all_diags)
\ . "\nlocation list: " . string(ale#engine#GetLoclist(a:bufnr))
\ . "\nserver_status: " . lsp#get_server_status()
\ . "\ncurrent lines: " . string(getline(1, '$'))
endfunction
Describe rust-analyzer
Before all
if !executable('rust-analyzer')
throw 'rust-analyzer command is not found. It must be installed for running integration tests'
endif
let dir = IntegTestRootDir()
execute 'cd' dir
let file = join([dir, 'project', 'src', 'lib.rs'], s:SEP)
" Note: It might be better to write lib.rs here and delete in `After all` hook rather than
" modifying a file committed to repository directly.
let lib_rs_contents = readfile(file)
End
After all
" Restore contents of lib.rs since it was modified by test case
call writefile(lib_rs_contents, file)
redir! > integ_messages.txt
if exists(':LspStatus')
LspStatus
else
echom 'No :LspStatus command is defined'
endif
message
redir END
End
Before each
execute 'edit!' file
End
After each
bwipeout!
End
It shows diagnostics results with ALE through vim-lsp
Assert lsp#ale#enabled()
let bufnr = bufnr('')
let elapsed = 0 " in seconds
let timeout = 120 " in seconds
let counts = ale#statusline#Count(bufnr)
while elapsed <= timeout
if counts.total > 0
break
endif
sleep 1
let elapsed += 1
let counts = ale#statusline#Count(bufnr)
endwhile
let info = s:get_debug_info(bufnr)
Assert True(counts.total > 0, 'No error found after ' . elapsed . ' seconds' . info)
let loclist = ale#engine#GetLoclist(bufnr)
Assert NotEmpty(loclist, 'Location list from ALE is empty after ' . elapsed . ' seconds. ' . info)
let item = loclist[0]
let item_str = string(item)
Assert Equals(item.linter_name, 'vim-lsp', item_str . info)
Assert True(item.from_other_source, item_str . info)
Assert Match(item.filename, 'lib\.rs$', item_str . info)
Assert Match(item.text, 'this_variable_is_unused', item_str . info)
" Fix the problem
normal! ggjdd
write
let elapsed = 0 " in seconds
let counts = ale#statusline#Count(bufnr)
while elapsed <= timeout
if counts.total == 0
break
endif
sleep 1
let elapsed += 1
let counts = ale#statusline#Count(bufnr)
endwhile
let info = s:get_debug_info(bufnr)
Assert True(counts.total == 0, 'Error found after ' . elapsed . ' seconds' . info)
" Check the error was removed from location list since it'd been fixed
let loclist = ale#engine#GetLoclist(bufnr)
Assert Empty(loclist, 'Location list from ALE is not empty after ' . elapsed . ' seconds. ' . info)
End
End
" vim: set ft=vim:

View File

@@ -0,0 +1,18 @@
call themis#option('exclude', 'test/README.md')
let s:dir = expand('<sfile>:p:h')
let s:sep = has('win32') ? '\' : '/'
let s:runtime_dir = join([s:dir, 'runtime'], s:sep)
execute 'set rtp+=' . s:runtime_dir
let s:helper = themis#helper('assert')
call themis#helper('command').with(s:helper)
if $THEMIS_PROFILE !=# ''
execute 'profile' 'start' $THEMIS_PROFILE
profile! file ./autoload/lsp/ale.vim
profile! file ./plugin/lsp_ale.vim
endif
" vim: set ft=vim:

View File

@@ -0,0 +1,62 @@
function! ale#other_source#StartChecking(bufnr, name) abort
let s:start_checking_called = [a:bufnr, a:name]
endfunction
function! ale#other_source#ShowResults(bufnr, name, results) abort
let s:show_results_called = [a:bufnr, a:name, a:results]
endfunction
function! ale#other_source#last_start_checking() abort
return s:start_checking_called
endfunction
function! ale#other_source#last_show_results() abort
return s:show_results_called
endfunction
function! WaitUntil(func, ...) abort
let timeout = get(a:, 1, 1) " 1sec by default
let total = 0
while !a:func()
sleep 100m
let total += 0.1
if total >= timeout
" Note: v:true/v:false are not supported by themis.vim
" https://github.com/thinca/vim-themis/pull/56
return 0
endif
endwhile
return 1
endfunction
function! ale#other_source#wait_until_show_results() abort
let timeout = 1
let total = 0
while s:show_results_called is v:null
let total += 0.1
if total > timeout
throw 'ale#other_source#ShowResults() was not called while 1 second'
endif
sleep 100m
endwhile
endfunction
function! ale#other_source#check_show_no_result() abort
let timeout = 1
let total = 0
while s:show_results_called is v:null
let total += 0.1
if total > timeout
return
endif
sleep 100m
endwhile
throw 'ale#other_source#ShowResults() was called within 1 second: ' . string(s:show_results_called)
endfunction
function! ale#other_source#reset() abort
let s:start_checking_called = v:null
let s:show_results_called = v:null
endfunction
call ale#other_source#reset()

View File

@@ -0,0 +1,2 @@
function! lsp#stream() abort
endfunction

View File

@@ -0,0 +1,35 @@
function! lsp#callbag#pipe(source, filter, sink) abort
let s:Filter = a:filter
let s:Next = a:sink.next
return {-> extend(s:, {'disposed': v:true})}
endfunction
function! lsp#callbag#filter(pred) abort
return a:pred
endfunction
function! lsp#callbag#subscribe(sink) abort
return a:sink
endfunction
" Functions for tests
function! lsp#callbag#piped() abort
return s:Filter isnot v:null && s:Next isnot v:null
endfunction
function! lsp#callbag#disposed() abort
return s:disposed
endfunction
function! lsp#callbag#reset() abort
let s:Filter = v:null
let s:Next = v:null
let s:disposed = v:false
endfunction
function! lsp#callbag#mock_receive(res) abort
if s:Filter(a:res)
call s:Next(a:res)
endif
endfunction

View File

@@ -0,0 +1,7 @@
function! lsp#internal#diagnostics#state#_is_enabled_for_buffer(bufnr) abort
return a:bufnr == g:lsp_ale_test_mock_bufnr
endfunction
function! lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(uri) abort
return g:lsp_ale_test_mock_diags
endfunction

View File

@@ -0,0 +1,19 @@
function! lsp#ui#vim#utils#diagnostics_to_loc_list(res) abort
if len(s:loclists) == 0
return []
endif
let ret = s:loclists[0]
let s:loclists = s:loclists[1:]
return ret
endfunction
function! lsp#ui#vim#utils#mock_diagnostics_to_loc_list(loclists) abort
let s:loclists = copy(a:loclists)
endfunction
function! lsp#ui#vim#utils#reset() abort
let s:loclists = []
endfunction
call lsp#ui#vim#utils#reset()

View File

@@ -0,0 +1,11 @@
function! lsp#utils#get_buffer_uri(bufnr) abort
return 'file://' . s:bufname
endfunction
function! lsp#utils#uri_to_path(uri) abort
return s:bufname
endfunction
function! lsp#utils#mock_buf_name(name) abort
let s:bufname = a:name
endfunction

View File

@@ -0,0 +1,471 @@
function! s:test_diags() abort
return {
\ 'gopls': {
\ 'method': 'textDocument/publishDiagnostics',
\ 'jsonrpc': '2.0',
\ 'params': {
\ 'uri': 'file:///path/to/dummy.txt',
\ 'diagnostics': [
\ {
\ 'source': 'compiler',
\ 'range': {
\ 'end': {'character': 4, 'line': 4},
\ 'start': {'character': 1, 'line': 4}
\ },
\ 'message': 'error message 1',
\ 'severity': 1
\ },
\ {
\ 'source': 'compiler',
\ 'range': {
\ 'end': {'character': 4, 'line': 4},
\ 'start': {'character': 1, 'line': 4}
\ },
\ 'message': 'warning message 1',
\ 'severity': 2
\ }
\ ]
\ }
\ }
\}
endfunction
function! s:test_locs() abort
return [[
\ {
\ 'lnum': 5,
\ 'col': 2,
\ 'filename': '/path/to/dummy.txt',
\ 'text': 'compiler:Error:error message 1'
\ },
\ {
\ 'lnum': 5,
\ 'col': 2,
\ 'filename': '/path/to/dummy.txt',
\ 'text': 'compiler:Warning:warning message 1'
\ }
\ ]]
endfunction
function! s:test_diags_all_severities() abort
let diags = s:test_diags()
let diag = diags.gopls.params.diagnostics[0]
let diags.gopls.params.diagnostics = []
for [sev, name] in [[1, 'error'], [2, 'warning'], [3, 'info'], [4, 'hint']]
let d = copy(diag)
let d.severity = sev
let d.message = name . ' message'
let diags.gopls.params.diagnostics += [d]
endfor
return diags
endfunction
function! s:test_locs_all_severities() abort
let loc = s:test_locs()[0][0]
let locs = []
for [sev, name] in [[1, 'Error'], [2, 'Warning'], [3, 'Info'], [4, 'Hint']]
let l = copy(loc)
let l.text = 'compiler:' . name . ':' . tolower(name) . ' message'
let locs += [l]
endfor
return [locs]
endfunction
function! s:test_expected_locs_all_severities() abort
let loc = s:test_locs()[0][0]
let locs = []
for [sev, name, type] in [[1, 'Error', 'E'], [2, 'Warning', 'W'], [3, 'Info', 'I'], [4, 'Hint', 'H']]
let l = copy(loc)
let l.type = type
let l.text = '[gopls] compiler:' . name . ':' . tolower(name) . ' message'
let locs += [l]
endfor
return locs
endfunction
function! s:modify_loc_item(item, type) abort
let a:item.type = a:type
let a:item.text = '[gopls] ' . a:item.text
return a:item
endfunction
Describe vim-lsp-ale
Before all
" Set bufffer name to 'foo'
file /path/to/dummy.txt
End
Before each
call lsp#ale#_reset_prev_num_diags()
call lsp#callbag#reset()
call ale#other_source#reset()
call lsp#ui#vim#utils#reset()
call lsp#utils#mock_buf_name('/path/to/dummy.txt')
let g:lsp_ale_test_mock_diags = {}
let g:lsp_ale_test_mock_bufnr = bufnr('')
doautocmd User lsp_setup
let g:ale_want_results_buffer = bufnr('')
End
After each
call lsp#ale#disable()
End
It enables vim-lsp's diagnostics and disables to output diagnostics
Assert True(g:lsp_diagnostics_enabled)
Assert False(g:lsp_diagnostics_highlights_enabled)
Assert False(g:lsp_diagnostics_signs_enabled)
Assert False(g:lsp_diagnostics_echo_cursor)
Assert False(g:lsp_diagnostics_virtual_text_enabled)
End
It disables ALE's LSP support
Assert True(g:ale_disable_lsp)
End
It defines plugin-lsp-ale autocmd group
Assert True(exists('g:loaded_lsp_ale'))
redir => autocmds
autocmd plugin-lsp-ale
redir END
Assert True(stridx(autocmds, 'lsp_setup') >= 0, autocmds)
Assert True(stridx(autocmds, 'ALEWantResults') >= 0, autocmds)
End
It subscribes notification stream on lsp_setup autocmd event
Assert True(lsp#callbag#piped())
End
It stops subscribing stream when lsp#ale#disable() is called
call lsp#ale#enable()
Assert True(lsp#ale#enabled())
call lsp#ale#disable()
Assert False(lsp#ale#enabled())
Assert True(lsp#callbag#disposed())
call lsp#ale#disable()
Assert False(lsp#ale#enabled())
End
Context ALEWantResults
It does not notify results when vim-lsp-ale is disabled
call lsp#ale#disable()
doautocmd User ALEWantResults
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
It does not notify results when the buffer disables LSP
Assert Equals(ale#other_source#last_start_checking(), v:null)
let g:lsp_ale_test_mock_bufnr = -1
doautocmd User ALEWantResults
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
It does not notify on no diagnostics error
Assert Equals(ale#other_source#last_start_checking(), v:null)
Assert Equals(ale#other_source#last_show_results(), v:null)
let g:lsp_ale_test_mock_diags = {}
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
Assert Equals(ale#other_source#last_show_results(), v:null)
End
It notifies location list items converted from diagnostics results
Assert Equals(ale#other_source#last_start_checking(), v:null)
Assert Equals(ale#other_source#last_show_results(), v:null)
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let [show_bufnr, show_name, loclist] = ale#other_source#last_show_results()
Assert Equals(show_bufnr, bufnr)
Assert Equals(show_name, 'vim-lsp')
let expected_locs = s:test_locs()[0]
call s:modify_loc_item(expected_locs[0], 'E')
call s:modify_loc_item(expected_locs[1], 'W')
Assert Equals(loclist, expected_locs)
End
It filters diagnostics results by severity
Assert Equals(ale#other_source#last_start_checking(), v:null)
Assert Equals(ale#other_source#last_show_results(), v:null)
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let actual_diags = s:test_diags()
" Set 'hint' severity. Default threshold is 'info'
let actual_diags.gopls.params.diagnostics[1].severity = 4
let g:lsp_ale_test_mock_diags = actual_diags
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let [show_bufnr, show_name, loclist] = ale#other_source#last_show_results()
Assert Equals(show_bufnr, bufnr)
Assert Equals(show_name, 'vim-lsp')
Assert Equals(len(loclist), 1, string(loclist))
End
It skips notifying results to ALE when no error continues to happen
let bufnr = bufnr('')
" Prepare empty results
let diags = s:test_diags()
let diags.gopls.params.diagnostics = []
let g:lsp_ale_test_mock_diags = diags
" First notification
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', []])
call ale#other_source#reset()
" Second notification
doautocmd User ALEWantResults
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
End
Context textDocument/publishDiagnostics notification
It notifies diagnostics results to ALE
Assert Equals(ale#other_source#last_start_checking(), v:null)
Assert Equals(ale#other_source#last_show_results(), v:null)
let bufnr = bufnr('')
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
let response = { 'response': s:test_diags()['gopls'], 'server': 'gopls' }
call lsp#callbag#mock_receive(response)
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let [show_bufnr, show_name, loclist] = ale#other_source#last_show_results()
Assert Equals(show_bufnr, bufnr)
Assert Equals(show_name, 'vim-lsp')
let expected_locs = s:test_locs()[0]
call s:modify_loc_item(expected_locs[0], 'E')
call s:modify_loc_item(expected_locs[1], 'W')
Assert Equals(loclist, expected_locs)
End
It does nothing when receiving notification other than textDocument/publishDiagnostics
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
let response = {
\ 'server': 'gopls',
\ 'response': {
\ 'method': 'something/doSomethihg',
\ 'jsonrpc': '2.0',
\ 'params': {},
\ }
\ }
call lsp#callbag#mock_receive(response)
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
It does nothing when method or server is missing in the notification
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
for response in [
\ {
\ 'response': {
\ 'method': 'something/doSomethihg',
\ 'jsonrpc': '2.0',
\ 'params': {},
\ }
\ },
\ {
\ 'server': 'gopls',
\ 'response': {
\ 'jsonrpc': '2.0',
\ 'params': {},
\ }
\ }
\ ]
call lsp#callbag#mock_receive(response)
endfor
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
It does nothing when received notification is for buffer which doesn't exist
let bufnr = bufnr('')
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
call lsp#utils#mock_buf_name('/path/to/somewhere/else.txt')
let response = { 'response': s:test_diags()['gopls'], 'server': 'gopls' }
call lsp#callbag#mock_receive(response)
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
It notifies empty list when notification says no lint error was found
let bufnr = bufnr('')
let response = { 'response': s:test_diags()['gopls'], 'server': 'gopls' }
let response.response.params.diagnostics = []
call lsp#callbag#mock_receive(response)
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', []])
End
It skips sending results to ALE when no error continues to happen
let bufnr = bufnr('')
let diags = s:test_diags()
let diags.gopls.params.diagnostics = []
" First notification
let response = { 'response': diags.gopls, 'server': 'gopls' }
call lsp#callbag#mock_receive(response)
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', []])
call ale#other_source#reset()
" Second notification
call lsp#callbag#mock_receive(response)
call ale#other_source#check_show_no_result()
Assert Equals(ale#other_source#last_start_checking(), v:null)
End
End
Describe g:lsp_ale_diagnostics_severity
Before
let saved_diagnostics_severity = g:lsp_ale_diagnostics_severity
End
After
let g:lsp_ale_diagnostics_severity = saved_diagnostics_severity
End
It filters results by severity 'error'
let g:lsp_ale_diagnostics_severity = 'error'
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs_all_severities())
let g:lsp_ale_test_mock_diags = s:test_diags_all_severities()
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let expected = s:test_expected_locs_all_severities()
call filter(expected, {_, l -> l.type ==# 'E'})
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', expected])
End
It filters results by severity 'warning'
let g:lsp_ale_diagnostics_severity = 'warning'
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs_all_severities())
let g:lsp_ale_test_mock_diags = s:test_diags_all_severities()
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let expected = s:test_expected_locs_all_severities()
call filter(expected, {_, l -> l.type =~# 'E\|W'})
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', expected])
End
It filters results by severity 'information'
let g:lsp_ale_diagnostics_severity = 'information'
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs_all_severities())
let g:lsp_ale_test_mock_diags = s:test_diags_all_severities()
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let expected = s:test_expected_locs_all_severities()
call filter(expected, {_, l -> l.type =~# 'E\|W\|I'})
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', expected])
End
It filters results by severity 'hint'
let g:lsp_ale_diagnostics_severity = 'hint'
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs_all_severities())
let g:lsp_ale_test_mock_diags = s:test_diags_all_severities()
let bufnr = bufnr('')
doautocmd User ALEWantResults
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_start_checking(), [bufnr, 'vim-lsp'])
let expected = s:test_expected_locs_all_severities()
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', expected])
End
It throws an error when invalid value is set
let g:lsp_ale_diagnostics_severity = 'invalid!'
let bufnr = bufnr('')
call lsp#ui#vim#utils#mock_diagnostics_to_loc_list(s:test_locs())
let g:lsp_ale_test_mock_diags = s:test_diags()
call lsp#callbag#mock_receive({ 'response': s:test_diags().gopls, 'server': 'gopls' })
if has('nvim')
Throws /^vim-lsp-ale: Unexpected severity/ ale#other_source#wait_until_show_results()
else
" XXX: No way to catch exception thrown while sleeping. Indirectly
" check the error was handled correctly by checking the result is
" set to empty.
call ale#other_source#wait_until_show_results()
Assert Equals(ale#other_source#last_show_results(), [bufnr, 'vim-lsp', []])
endif
End
End
End
" vim: set ft=vim: