From 889e6338fe37a4960fded05deaaa760619fa4c03 Mon Sep 17 00:00:00 2001 From: Diego Mendes Date: Wed, 2 Oct 2019 09:22:04 -0300 Subject: [PATCH 01/15] highest phpstan level in doc updated --- doc/ale-php.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ale-php.txt b/doc/ale-php.txt index d41fb50d..e17e1023 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -157,9 +157,9 @@ g:ale_php_phpstan_level *g:ale_php_phpstan_level* Type: |String| Default: `''` - This variable controls the rule levels. 0 is the loosest and 4 is the + This variable controls the rule levels. 0 is the loosest and 7 is the strictest. If this option isn't set, the rule level will be controlled by - the configuration file. If no configuration file can be detected, `'4'` will + the configuration file. If no configuration file can be detected, `'7'` will be used instead. From 618f2d71fcfb13b99f221de6c47120c572a912d8 Mon Sep 17 00:00:00 2001 From: Murfalo Date: Thu, 3 Oct 2019 13:17:17 -0400 Subject: [PATCH 02/15] Added automatic compile-commands-dir arg to ale_cpp_clangd linter --- ale_linters/cpp/clangd.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ale_linters/cpp/clangd.vim b/ale_linters/cpp/clangd.vim index fab605f4..8b7f0284 100644 --- a/ale_linters/cpp/clangd.vim +++ b/ale_linters/cpp/clangd.vim @@ -5,7 +5,11 @@ call ale#Set('cpp_clangd_executable', 'clangd') call ale#Set('cpp_clangd_options', '') function! ale_linters#cpp#clangd#GetCommand(buffer) abort - return '%e' . ale#Pad(ale#Var(a:buffer, 'cpp_clangd_options')) + let l:build_dir = ale#c#GetBuildDirectory(a:buffer) + + return '%e' + \ . ale#Pad(ale#Var(a:buffer, 'cpp_clangd_options')) + \ . (!empty(l:build_dir) ? ' -compile-commands-dir=' . ale#Escape(l:build_dir) : '') endfunction call ale#linter#Define('cpp', { From b96574e5b5f54be44dc806a7fe41644a46246628 Mon Sep 17 00:00:00 2001 From: Josh Reichardt Date: Fri, 4 Oct 2019 10:48:06 -0700 Subject: [PATCH 03/15] Fix Powershell emoji --- supported-tools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supported-tools.md b/supported-tools.md index 1a297946..fbe1ef28 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -341,8 +341,8 @@ formatting. * Pony * [ponyc](https://github.com/ponylang/ponyc) * PowerShell - * [powershell](https://github.com/PowerShell/PowerShell) :floppy_disk - * [psscriptanalyzer](https://github.com/PowerShell/PSScriptAnalyzer) :floppy_disk + * [powershell](https://github.com/PowerShell/PowerShell) :floppy_disk: + * [psscriptanalyzer](https://github.com/PowerShell/PSScriptAnalyzer) :floppy_disk: * Prolog * [swipl](https://github.com/SWI-Prolog/swipl-devel) * proto From 35f51221f1519c591a6d26a8d8acd12388deab50 Mon Sep 17 00:00:00 2001 From: Murfalo Date: Wed, 9 Oct 2019 13:30:10 -0400 Subject: [PATCH 04/15] Updated ale_linters/c/clangd.vim to match ale_linters/cpp/clangd.vim --- ale_linters/c/clangd.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim index 79b600fa..5ca30973 100644 --- a/ale_linters/c/clangd.vim +++ b/ale_linters/c/clangd.vim @@ -5,7 +5,11 @@ call ale#Set('c_clangd_executable', 'clangd') call ale#Set('c_clangd_options', '') function! ale_linters#c#clangd#GetCommand(buffer) abort - return '%e' . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) + let l:build_dir = ale#c#GetBuildDirectory(a:buffer) + + return '%e' + \ . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) + \ . (!empty(l:build_dir) ? ' -compile-commands-dir=' . ale#Escape(l:build_dir) : '') endfunction call ale#linter#Define('c', { From a62f26434ac68eaddea7642201ddf0335e91d384 Mon Sep 17 00:00:00 2001 From: Murfalo Date: Wed, 9 Oct 2019 13:40:04 -0400 Subject: [PATCH 05/15] Added tests for clangd compile commands dectection --- ale_linters/c/clangd.vim | 1 + ale_linters/cpp/clangd.vim | 1 + .../compile_commands.json | 0 .../with_compile_commands/compile_commands.json | 0 .../test_c_clangd_command_callbacks.vader | 16 ++++++++++++++-- 5 files changed, 16 insertions(+), 2 deletions(-) rename test/command_callback/clangd_paths/{ => with_build_dir/unusual_build_dir_name}/compile_commands.json (100%) create mode 100644 test/command_callback/clangd_paths/with_compile_commands/compile_commands.json diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim index 5ca30973..c42d4497 100644 --- a/ale_linters/c/clangd.vim +++ b/ale_linters/c/clangd.vim @@ -3,6 +3,7 @@ call ale#Set('c_clangd_executable', 'clangd') call ale#Set('c_clangd_options', '') +call ale#Set('c_build_dir', '') function! ale_linters#c#clangd#GetCommand(buffer) abort let l:build_dir = ale#c#GetBuildDirectory(a:buffer) diff --git a/ale_linters/cpp/clangd.vim b/ale_linters/cpp/clangd.vim index 8b7f0284..14f3fe55 100644 --- a/ale_linters/cpp/clangd.vim +++ b/ale_linters/cpp/clangd.vim @@ -3,6 +3,7 @@ call ale#Set('cpp_clangd_executable', 'clangd') call ale#Set('cpp_clangd_options', '') +call ale#Set('c_build_dir', '') function! ale_linters#cpp#clangd#GetCommand(buffer) abort let l:build_dir = ale#c#GetBuildDirectory(a:buffer) diff --git a/test/command_callback/clangd_paths/compile_commands.json b/test/command_callback/clangd_paths/with_build_dir/unusual_build_dir_name/compile_commands.json similarity index 100% rename from test/command_callback/clangd_paths/compile_commands.json rename to test/command_callback/clangd_paths/with_build_dir/unusual_build_dir_name/compile_commands.json diff --git a/test/command_callback/clangd_paths/with_compile_commands/compile_commands.json b/test/command_callback/clangd_paths/with_compile_commands/compile_commands.json new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader index dc52097d..67f801db 100644 --- a/test/command_callback/test_c_clangd_command_callbacks.vader +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -18,9 +18,9 @@ Execute(The project root should be detected correctly): AssertLSPProject '' - call ale#test#SetFilename('clangd_paths/dummy.c') + call ale#test#SetFilename('clangd_paths/with_compile_commands/dummy.c') - AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths') + AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths/with_compile_commands') Execute(The executable should be configurable): let g:ale_c_clangd_executable = 'foobar' @@ -32,3 +32,15 @@ Execute(The options should be configurable): AssertLinter 'clangd', ale#Escape('clangd') . ' ' . b:ale_c_clangd_options +Execute(The compile command database should be detected correctly): + call ale#test#SetFilename('clangd_paths/with_build_dir/dummy_src/dummy.c') + + let b:ale_c_clangd_options = '' + let b:ale_c_build_dir = '' + let b:ale_c_build_dir_names = ['unusual_build_dir_name'] + let b:ale_c_parse_compile_commands = 1 + + AssertLinter 'clangd', ale#Escape('clangd') + \ . ' -compile-commands-dir=' + \ . ale#Escape(g:dir . '/clangd_paths/with_build_dir/unusual_build_dir_name') + From d488198c9c1491cff1c93b0163ecd1ff20e4dae5 Mon Sep 17 00:00:00 2001 From: Murfalo Date: Wed, 9 Oct 2019 13:52:17 -0400 Subject: [PATCH 06/15] Hopefully fixed issue with Windows paths --- test/command_callback/test_c_clangd_command_callbacks.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader index 67f801db..64aa8f13 100644 --- a/test/command_callback/test_c_clangd_command_callbacks.vader +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -42,5 +42,5 @@ Execute(The compile command database should be detected correctly): AssertLinter 'clangd', ale#Escape('clangd') \ . ' -compile-commands-dir=' - \ . ale#Escape(g:dir . '/clangd_paths/with_build_dir/unusual_build_dir_name') + \ . ale#Escape(ale#path#Simplify(g:dir . '/clangd_paths/with_build_dir/unusual_build_dir_name')) From a1fab5981120a71355924b0d51d6b17423e7319f Mon Sep 17 00:00:00 2001 From: Murfalo Date: Wed, 9 Oct 2019 14:24:41 -0400 Subject: [PATCH 07/15] Suboptimal fix to prevent variables from leaking out of new clangd test --- test/command_callback/test_c_clangd_command_callbacks.vader | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader index 64aa8f13..753dc9a8 100644 --- a/test/command_callback/test_c_clangd_command_callbacks.vader +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -4,6 +4,11 @@ Before: Save &filetype let &filetype = 'c' + Save b:ale_c_clangd_options + Save b:ale_c_build_dir + Save b:ale_c_build_dir_names + Save b:ale_c_parse_compile_commands + After: call ale#assert#TearDownLinterTest() From 5a1505ad62262263224ed8d0f908515fc116f776 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 13 Oct 2019 09:06:38 -0400 Subject: [PATCH 08/15] Fix TCP server config example. The docs for the `address` parameter of `Define` say: > This argument must only be set if the `lsp` argument > is set to `'socket'`. --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index c6e48043..01b6181d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -172,7 +172,7 @@ address to connect to instead. > call ale#linter#Define('filetype_here', { \ 'name': 'any_name_you_want', - \ 'lsp': 'stdio', + \ 'lsp': 'socket', \ 'address': 'servername:1234', \ 'project_root': '/path/to/root_of_project', \}) From b24fd13423656e14fa266405e1f238f0ec65cfb3 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 16 Oct 2019 17:23:31 +0100 Subject: [PATCH 09/15] Bump the ALE version --- autoload/ale.vim | 2 +- test/test_ale_has.vader | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index 3a4e79c8..1664e710 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -156,7 +156,7 @@ function! ale#Queue(delay, ...) abort endif endfunction -let s:current_ale_version = [2, 5, 0] +let s:current_ale_version = [2, 6, 0] " A function used to check for ALE features in files outside of the project. function! ale#Has(feature) abort diff --git a/test/test_ale_has.vader b/test/test_ale_has.vader index b2df01fe..b8a99103 100644 --- a/test/test_ale_has.vader +++ b/test/test_ale_has.vader @@ -1,4 +1,5 @@ Execute(Checks for versions below the current version should succeed): + AssertEqual 1, ale#Has('ale-2.6.0') AssertEqual 1, ale#Has('ale-2.5.0') AssertEqual 1, ale#Has('ale-2.4.0') AssertEqual 1, ale#Has('ALE-2.2.1') From f4070f6c43b3cb2e7463d8426a68d5a726991288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borges?= Date: Thu, 17 Oct 2019 17:28:48 +0100 Subject: [PATCH 10/15] Add definition of c/clangd's language as C (#2791) * Add definition of c/clangd's language as C * Update tests for clangd to be called with '-x c' * Change to use single quotes instead of double quotes --- ale_linters/c/clangd.vim | 2 +- .../test_c_clangd_command_callbacks.vader | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim index 79b600fa..0bb38d43 100644 --- a/ale_linters/c/clangd.vim +++ b/ale_linters/c/clangd.vim @@ -5,7 +5,7 @@ call ale#Set('c_clangd_executable', 'clangd') call ale#Set('c_clangd_options', '') function! ale_linters#c#clangd#GetCommand(buffer) abort - return '%e' . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) + return '%e -x c' . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) endfunction call ale#linter#Define('c', { diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader index dc52097d..15726163 100644 --- a/test/command_callback/test_c_clangd_command_callbacks.vader +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -4,14 +4,18 @@ Before: Save &filetype let &filetype = 'c' + let b:command_tail = ' -x c' + After: + unlet! b:command_tail + call ale#assert#TearDownLinterTest() Execute(The language string should be correct): AssertLSPLanguage 'c' Execute(The default executable should be correct): - AssertLinter 'clangd', ale#Escape('clangd') + AssertLinter 'clangd', ale#Escape('clangd') . b:command_tail Execute(The project root should be detected correctly): call ale#test#SetFilename(tempname() . '/dummy.c') @@ -25,10 +29,10 @@ Execute(The project root should be detected correctly): Execute(The executable should be configurable): let g:ale_c_clangd_executable = 'foobar' - AssertLinter 'foobar', ale#Escape('foobar') + AssertLinter 'foobar', ale#Escape('foobar') . b:command_tail Execute(The options should be configurable): let b:ale_c_clangd_options = '-compile-commands-dir=foo' - AssertLinter 'clangd', ale#Escape('clangd') . ' ' . b:ale_c_clangd_options + AssertLinter 'clangd', ale#Escape('clangd') . b:command_tail . ' ' . b:ale_c_clangd_options From e5a4c82917a17e759350d5137fb1afbf3e933c2a Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Fri, 18 Oct 2019 01:32:31 +0900 Subject: [PATCH 11/15] Add support for nimlsp (#2815) * Add support for nimlsp.vim * Add test and docs for nimlsp * Add nimlsp to supported-tools.md * Add nimlsp to doc/ale-supported-languages-and-tools.txt --- ale_linters/nim/nimlsp.vim | 33 +++++++++++++++++++ doc/ale-nim.txt | 25 ++++++++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 3 ++ supported-tools.md | 1 + .../test_nimlsp_command_callback.vader | 12 +++++++ test/nim-test-files/with-git/src/source.nim | 0 test/test_nimlsp_project_root.vader | 19 +++++++++++ 8 files changed, 94 insertions(+) create mode 100644 ale_linters/nim/nimlsp.vim create mode 100644 doc/ale-nim.txt create mode 100644 test/command_callback/test_nimlsp_command_callback.vader create mode 100644 test/nim-test-files/with-git/src/source.nim create mode 100644 test/test_nimlsp_project_root.vader diff --git a/ale_linters/nim/nimlsp.vim b/ale_linters/nim/nimlsp.vim new file mode 100644 index 00000000..5d041043 --- /dev/null +++ b/ale_linters/nim/nimlsp.vim @@ -0,0 +1,33 @@ +" Author: jeremija +" Description: Support for nimlsp (language server for nim) + +call ale#Set('nim_nimlsp_nim_sources', '') + +function! ale_linters#nim#nimlsp#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git') + + if !empty(l:project_root) + return fnamemodify(l:project_root, ':h:h') + endif + + return '' +endfunction + +function! ale_linters#nim#nimlsp#GetCommand(buffer) abort + let l:nim_sources = ale#Var(a:buffer, 'nim_nimlsp_nim_sources') + + if !empty(l:nim_sources) + let l:nim_sources = ale#Escape(l:nim_sources) + endif + + return '%e' . ale#Pad(l:nim_sources) +endfunction + +call ale#linter#Define('nim', { +\ 'name': 'nimlsp', +\ 'lsp': 'stdio', +\ 'executable': 'nimlsp', +\ 'command': function('ale_linters#nim#nimlsp#GetCommand'), +\ 'language': 'nim', +\ 'project_root': function('ale_linters#nim#nimlsp#GetProjectRoot'), +\}) diff --git a/doc/ale-nim.txt b/doc/ale-nim.txt new file mode 100644 index 00000000..ad7aa686 --- /dev/null +++ b/doc/ale-nim.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE Nim Integration *ale-nim-options* + + +=============================================================================== +nimcheck *ale-nim-nimcheck* + + ALE does not provide additional configuration options for `nimcheck` at this + point. + + +=============================================================================== +nimlsp *ale-nim-nimlsp* + +g:nim_nimlsp_nim_sources *g:nim_nimlsp_nim_sources* + + Type: |String| + Default: `''` + + Sets the path to Nim source repository as the first argument to `nimlsp` + command. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index a5b7c35e..e2379b70 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -282,6 +282,7 @@ Notes: * `nasm`!! * Nim * `nim check`!! + * `nimlsp` * nix * `nix-instantiate` * `nixpkgs-fmt` diff --git a/doc/ale.txt b/doc/ale.txt index 01b6181d..b142e956 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2307,6 +2307,9 @@ documented in additional help files. mmc...................................|ale-mercury-mmc| nasm....................................|ale-nasm-options| nasm..................................|ale-nasm-nasm| + nim.....................................|ale-nim-options| + nimcheck..............................|ale-nim-nimcheck| + nimlsp................................|ale-nim-nimlsp| nix.....................................|ale-nix-options| nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt| nroff...................................|ale-nroff-options| diff --git a/supported-tools.md b/supported-tools.md index 226baeaf..c302d38c 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -291,6 +291,7 @@ formatting. * [nasm](https://www.nasm.us/) :floppy_disk: * Nim * [nim check](https://nim-lang.org/docs/nimc.html) :floppy_disk: + * [nimlsp](https://github.com/PMunch/nimlsp) * nix * [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) * [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) diff --git a/test/command_callback/test_nimlsp_command_callback.vader b/test/command_callback/test_nimlsp_command_callback.vader new file mode 100644 index 00000000..c109deef --- /dev/null +++ b/test/command_callback/test_nimlsp_command_callback.vader @@ -0,0 +1,12 @@ +Before: + call ale#assert#SetUpLinterTest('nim', 'nimlsp') + +After: + call ale#assert#TearDownLinterTest() + +Execute(It does not set nim sources by default): + AssertLinter 'nimlsp', ale#Escape('nimlsp') + +Execute(Sets nimlsp and escapes sources from g:ale_nim_nimlsp_nim_sources): + let g:ale_nim_nimlsp_nim_sources = '/path/to /Nim' + AssertLinter 'nimlsp', ale#Escape('nimlsp') . ' ' . ale#Escape('/path/to /Nim') diff --git a/test/nim-test-files/with-git/src/source.nim b/test/nim-test-files/with-git/src/source.nim new file mode 100644 index 00000000..e69de29b diff --git a/test/test_nimlsp_project_root.vader b/test/test_nimlsp_project_root.vader new file mode 100644 index 00000000..e7027575 --- /dev/null +++ b/test/test_nimlsp_project_root.vader @@ -0,0 +1,19 @@ +Before: + runtime ale_linters/nim/nimlsp.vim + call ale#test#SetDirectory('/testplugin/test') + +After: + if isdirectory(g:dir . '/.git') + call delete(g:dir . '/.git', 'd') + endif + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + + +Execute(Detect root of nim project with .git/ correctly): + call ale#test#SetFilename('nim-test-files/with-git/src/source.nim') + call mkdir(g:dir . '/.git') + AssertEqual + \ ale#path#Simplify(g:dir), + \ ale_linters#nim#nimlsp#GetProjectRoot(bufnr('')) From b27df1b169cabb12e94b102cd8b6a788b2c864b2 Mon Sep 17 00:00:00 2001 From: Donnie West Date: Thu, 17 Oct 2019 21:47:07 -0500 Subject: [PATCH 12/15] Allow code actions to work on callback based sources --- autoload/ale/completion.vim | 2 +- test/completion/test_completion_events.vader | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index a15ca514..63e2247c 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -722,7 +722,7 @@ endfunction function! ale#completion#HandleUserData(completed_item) abort let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '') - if l:source isnot# 'ale-automatic' && l:source isnot# 'ale-manual' + if l:source isnot# 'ale-automatic' && l:source isnot# 'ale-manual' && l:source isnot# 'ale-callback' return endif diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index e06ac98b..d70fefeb 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -431,6 +431,12 @@ Execute(HandleUserData should call ale#code_action#HandleCodeAction): \}) AssertEqual g:handle_code_action_called, 2 + let b:ale_completion_info = {'source': 'ale-callback'} + call ale#completion#HandleUserData({ + \ 'user_data': '{"codeActions": [{"description":"", "changes": []}]}' + \}) + AssertEqual g:handle_code_action_called, 3 + Execute(ale#code_action#HandleCodeAction should not be called when when source is not ALE): call MockHandleCodeAction() let b:ale_completion_info = {'source': 'syntastic'} From 8698c44e2a65357518eb59d0f5e33498082a3198 Mon Sep 17 00:00:00 2001 From: Donnie West Date: Thu, 17 Oct 2019 21:16:04 -0500 Subject: [PATCH 13/15] Fix tsserver not returning details for items with empty source --- autoload/ale/completion.vim | 13 ++++++++++--- test/completion/test_lsp_completion_messages.vader | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index a15ca514..8b29d848 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -492,10 +492,17 @@ function! ale#completion#HandleTSServerResponse(conn_id, response) abort let l:identifiers = [] for l:name in l:names - call add(l:identifiers, { + let l:identifier = { \ 'name': l:name.word, - \ 'source': get(l:name, 'source', ''), - \}) + \} + let l:source = get(l:name, 'source', '') + + " Empty source results in no details for the completed item + if !empty(l:source) + call extend(l:identifier, { 'source': l:source }) + endif + + call add(l:identifiers, l:identifier) endfor let b:ale_completion_info.request_id = ale#lsp#Send( diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader index b997ac86..4b7392f5 100644 --- a/test/completion/test_lsp_completion_messages.vader +++ b/test/completion/test_lsp_completion_messages.vader @@ -190,10 +190,8 @@ Execute(The right message sent to the tsserver LSP when the first completion mes \ 'source': '/path/to/foo.ts', \ }, { \ 'name': 'FooBar', - \ 'source': '', \ }, { \ 'name': 'frazzle', - \ 'source': '', \ }], \ 'offset': 1, \ 'line': 1, From 5e69aaf4c2b4ffbfd4fbe0af820e23bf559b8e14 Mon Sep 17 00:00:00 2001 From: Andre Souto Date: Fri, 18 Oct 2019 16:17:54 +0100 Subject: [PATCH 14/15] Adding support for LSP `window/showMessage` method (#2652) * Added base handling for window/showMessage * Ignoring severity log * Code formatting * Added user configurable severity * Preferring ale#util#ShowMessage over echo'ing directly * Using format similar to ale_echo_msg_format for consistency * Updating docs * Added LSP log config string; improved tests * Use warning as fallback for incorrect user config --- autoload/ale.vim | 7 ++ autoload/ale/lsp_linter.vim | 6 ++ autoload/ale/lsp_window.vim | 58 ++++++++++++ doc/ale.txt | 49 ++++++++++ test/lsp/test_handling_window_requests.vader | 94 ++++++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 autoload/ale/lsp_window.vim create mode 100644 test/lsp/test_handling_window_requests.vader diff --git a/autoload/ale.vim b/autoload/ale.vim index 1664e710..ee1a0d54 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -5,11 +5,18 @@ " Strings used for severity in the echoed message let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error') let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info') +let g:ale_echo_msg_log_str = get(g:, 'ale_echo_msg_log_str', 'Log') let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') " Ignoring linters, for disabling some, or ignoring LSP diagnostics. let g:ale_linters_ignore = get(g:, 'ale_linters_ignore', {}) let g:ale_disable_lsp = get(g:, 'ale_disable_lsp', 0) +" LSP window/showMessage format +let g:ale_lsp_show_message_format = get(g:, 'ale_lsp_show_message_format', '%severity%:%linter%: %s') +" Valid values mimic LSP definitions (error, warning and information; log is +" never shown) +let g:ale_lsp_show_message_severity = get(g:, 'ale_lsp_show_message_severity', 'error') + let s:lint_timer = -1 let s:getcmdwintype_exists = exists('*getcmdwintype') diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 190a16b4..e4148ceb 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -130,6 +130,12 @@ function! ale#lsp_linter#HandleLSPResponse(conn_id, response) abort call s:HandleLSPErrorMessage(l:linter_name, a:response) elseif l:method is# 'textDocument/publishDiagnostics' call s:HandleLSPDiagnostics(a:conn_id, a:response) + elseif l:method is# 'window/showMessage' + call ale#lsp_window#HandleShowMessage( + \ s:lsp_linter_map[a:conn_id], + \ g:ale_lsp_show_message_format, + \ a:response.params + \) elseif get(a:response, 'type', '') is# 'event' \&& get(a:response, 'event', '') is# 'semanticDiag' call s:HandleTSServerDiagnostics(a:response, 'semantic') diff --git a/autoload/ale/lsp_window.vim b/autoload/ale/lsp_window.vim new file mode 100644 index 00000000..15cd0a1e --- /dev/null +++ b/autoload/ale/lsp_window.vim @@ -0,0 +1,58 @@ +" Author: suoto +" Description: Handling of window/* LSP methods, although right now only +" handles window/showMessage + +" Constants for message type codes +let s:LSP_MESSAGE_TYPE_DISABLED = 0 +let s:LSP_MESSAGE_TYPE_ERROR = 1 +let s:LSP_MESSAGE_TYPE_WARNING = 2 +let s:LSP_MESSAGE_TYPE_INFORMATION = 3 +let s:LSP_MESSAGE_TYPE_LOG = 4 + +" Translate strings from the user config to a number so we can check +" severities +let s:CFG_TO_LSP_SEVERITY = { +\ 'disabled': s:LSP_MESSAGE_TYPE_DISABLED, +\ 'error': s:LSP_MESSAGE_TYPE_ERROR, +\ 'warning': s:LSP_MESSAGE_TYPE_WARNING, +\ 'information': s:LSP_MESSAGE_TYPE_INFORMATION, +\ 'info': s:LSP_MESSAGE_TYPE_INFORMATION, +\ 'log': s:LSP_MESSAGE_TYPE_LOG +\} + +" Handle window/showMessage response. +" - details: dict containing linter name and format (g:ale_lsp_show_message_format) +" - params: dict with the params for the call in the form of {type: number, message: string} +function! ale#lsp_window#HandleShowMessage(linter_name, format, params) abort + let l:message = a:params.message + let l:type = a:params.type + + " Get the configured severity level threshold and check if the message + " should be displayed or not + let l:configured_severity = tolower(get(g:, 'ale_lsp_show_message_severity', 'error')) + " If the user has confgured with a value we can't find on the conversion + " dict, fall back to warning + let l:cfg_severity_threshold = get(s:CFG_TO_LSP_SEVERITY, l:configured_severity, s:LSP_MESSAGE_TYPE_WARNING) + + if l:type > l:cfg_severity_threshold + return + endif + + " Severity will depend on the message type + if l:type is# s:LSP_MESSAGE_TYPE_ERROR + let l:severity = g:ale_echo_msg_error_str + elseif l:type is# s:LSP_MESSAGE_TYPE_INFORMATION + let l:severity = g:ale_echo_msg_info_str + elseif l:type is# s:LSP_MESSAGE_TYPE_LOG + let l:severity = g:ale_echo_msg_log_str + else + " Default to warning just in case + let l:severity = g:ale_echo_msg_warning_str + endif + + let l:string = substitute(a:format, '\V%severity%', l:severity, 'g') + let l:string = substitute(l:string, '\V%linter%', a:linter_name, 'g') + let l:string = substitute(l:string, '\V%s\>', l:message, 'g') + + call ale#util#ShowMessage(l:string) +endfunction diff --git a/doc/ale.txt b/doc/ale.txt index b142e956..177b67df 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -801,6 +801,15 @@ g:ale_echo_msg_info_str *g:ale_echo_msg_info_str* The string used for `%severity%` for info. See |g:ale_echo_msg_format| +g:ale_echo_msg_log_str *g:ale_echo_msg_log_str* + + Type: |String| + Default: `'Log'` + + The string used for `%severity%` for log, used only for handling LSP show + message requests. See |g:ale_lsp_show_message_format| + + g:ale_echo_msg_warning_str *g:ale_echo_msg_warning_str* Type: |String| @@ -1251,6 +1260,46 @@ b:ale_loclist_msg_format *b:ale_loclist_msg_format* The strings for configuring `%severity%` are also used for this option. + +g:ale_lsp_show_message_format *g:ale_lsp_show_message_format* + + Type: |String| + Default: `'%severity%:%linter%: %s'` + + This variable defines the format that messages received from an LSP will + have when echoed. The following sequences of characters will be replaced. + + `%s` - replaced with the message text + `%linter%` - replaced with the name of the linter + `%severity%` - replaced with the severity of the message + + The strings for `%severity%` levels "error", "info" and "warning" are shared + with |g:ale_echo_msg_format|. Severity "log" is unique to + |g:ale_lsp_show_message_format| and it can be configured via + + |g:ale_echo_msg_log_str| - Defaults to `'Log'` + + Please note that |g:ale_lsp_show_message_format| *can not* be configured + separately for each buffer like |g:ale_echo_msg_format| can. + + +g:ale_lsp_show_message_severity *g:ale_lsp_show_message_severity* + + Type: |String| + Default: `'error'` + + This variable defines the minimum severity level an LSP message needs to be + displayed. Messages below this level are discarded; please note that + messages with `Log` severity level are always discarded. + + Possible values follow the LSP spec `MessageType` definition: + + `'error'` - Displays only errors. + `'warning'` - Displays errors and warnings. + `'information'` - Displays errors, warnings and infos + `'log'` - Same as `'information'` + + g:ale_lsp_root *g:ale_lsp_root* b:ale_lsp_root *b:ale_lsp_root* diff --git a/test/lsp/test_handling_window_requests.vader b/test/lsp/test_handling_window_requests.vader new file mode 100644 index 00000000..551d5975 --- /dev/null +++ b/test/lsp/test_handling_window_requests.vader @@ -0,0 +1,94 @@ +Before: + let g:expr_list = [] + let g:linter_name = 'some_linter' + let g:format = '%severity%:%linter%: %s' + " Get the default value to restore it + let g:default_severity = g:ale_lsp_show_message_severity + let g:ale_lsp_show_message_severity = 'information' + + function! ale#util#ShowMessage(expr) abort + call add(g:expr_list, a:expr) + endfunction + +After: + unlet! g:expr_list + unlet! g:linter_name + unlet! g:format + let g:ale_lsp_show_message_severity = g:default_severity + unlet! g:default_severity + +Execute(ale#lsp_window#HandleShowMessage() should only show errors when severity is set to "error"): + let g:ale_lsp_show_message_severity = 'error' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual ['Error:some_linter: an error'], g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should only show errors and warnings when severity is set to "warning"): + let g:ale_lsp_show_message_severity = 'warning' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual ['Error:some_linter: an error', 'Warning:some_linter: a warning'], g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should only show errors, warnings and infos when severity is set to "information"): + let g:ale_lsp_show_message_severity = 'information' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual [ + \ 'Error:some_linter: an error', + \ 'Warning:some_linter: a warning', + \ 'Info:some_linter: an info'], + \ g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should only show errors, warnings and infos when severity is set to "info"): + let g:ale_lsp_show_message_severity = 'info' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual [ + \ 'Error:some_linter: an error', + \ 'Warning:some_linter: a warning', + \ 'Info:some_linter: an info'], + \ g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should show all messages is severity is set to "log"): + let g:ale_lsp_show_message_severity = 'log' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual [ + \ 'Error:some_linter: an error', + \ 'Warning:some_linter: a warning', + \ 'Info:some_linter: an info', + \ 'Log:some_linter: a log'], + \ g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should not show anything if severity is configured as disabled): + let g:ale_lsp_show_message_severity = 'disabled' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual [], g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should use "warning" when severity is set to an invalid value): + let g:ale_lsp_show_message_severity = 'foo' + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':1,'message':'an error'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':2,'message':'a warning'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':'an info'}) + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':4,'message':'a log'}) + AssertEqual [ + \ 'Error:some_linter: an error', + \ 'Warning:some_linter: a warning'], + \ g:expr_list + +Execute(ale#lsp_window#HandleShowMessage() should escape quotes on messages): + call ale#lsp_window#HandleShowMessage(g:linter_name, g:format, {'type':3,'message':"this is an 'info'"}) + AssertEqual ['Info:some_linter: this is an ''info'''], g:expr_list From c06467438dff38b939fd81b32395296d01a59df6 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 18 Oct 2019 16:22:17 +0100 Subject: [PATCH 15/15] Mention the disabled option for message severity --- autoload/ale/lsp_window.vim | 2 +- doc/ale.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/ale/lsp_window.vim b/autoload/ale/lsp_window.vim index 15cd0a1e..9a27f2f1 100644 --- a/autoload/ale/lsp_window.vim +++ b/autoload/ale/lsp_window.vim @@ -30,7 +30,7 @@ function! ale#lsp_window#HandleShowMessage(linter_name, format, params) abort " Get the configured severity level threshold and check if the message " should be displayed or not let l:configured_severity = tolower(get(g:, 'ale_lsp_show_message_severity', 'error')) - " If the user has confgured with a value we can't find on the conversion + " If the user has configured with a value we can't find on the conversion " dict, fall back to warning let l:cfg_severity_threshold = get(s:CFG_TO_LSP_SEVERITY, l:configured_severity, s:LSP_MESSAGE_TYPE_WARNING) diff --git a/doc/ale.txt b/doc/ale.txt index 177b67df..291e90fb 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1298,6 +1298,7 @@ g:ale_lsp_show_message_severity *g:ale_lsp_show_message_ `'warning'` - Displays errors and warnings. `'information'` - Displays errors, warnings and infos `'log'` - Same as `'information'` + `'disabled'` - Doesn't display any information at all. g:ale_lsp_root *g:ale_lsp_root*