From 79e42fed14b35767d53d7d443a644a037e012b89 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 10 May 2019 13:42:41 +0100 Subject: #2403 - Make ale_disable_lsp apply consistently, and document it better --- autoload/ale.vim | 2 +- autoload/ale/lsp_linter.vim | 5 ++ doc/ale.txt | 9 +- test/lsp/test_did_save_event.vader | 3 + test/test_ignoring_linters.vader | 95 ++++++++++++++++++++++ ...test_redundant_tsserver_rendering_avoided.vader | 4 + 6 files changed, 116 insertions(+), 2 deletions(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index a887834b..04329dfd 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -97,7 +97,7 @@ function! s:Lint(buffer, should_lint_file, timer_id) abort " Apply ignore lists for linters only if needed. let l:ignore_config = ale#Var(a:buffer, 'linters_ignore') let l:disable_lsp = ale#Var(a:buffer, 'disable_lsp') - let l:linters = !empty(l:ignore_config) + let l:linters = !empty(l:ignore_config) || l:disable_lsp \ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config, l:disable_lsp) \ : l:linters diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 3a596d62..f70042dd 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -10,6 +10,11 @@ endif " Check if diagnostics for a particular linter should be ignored. function! s:ShouldIgnore(buffer, linter_name) abort + " Ignore all diagnostics if LSP integration is disabled. + if ale#Var(a:buffer, 'disable_lsp') + return 1 + endif + let l:config = ale#Var(a:buffer, 'linters_ignore') " Don't load code for ignoring diagnostics if there's nothing to ignore. diff --git a/doc/ale.txt b/doc/ale.txt index 8261050a..5b290b06 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -142,6 +142,8 @@ ALE offers several options for controlling which linters are run. * Selecting linters to run. - |g:ale_linters| * Aliasing filetypes for linters - |g:ale_linter_aliases| * Only running linters you asked for. - |g:ale_linters_explicit| +* Disabling only a subset of linters. - |g:ale_linters_ignore| +* Disabling LSP linters and `tsserver`. - |g:ale_disable_lsp| ------------------------------------------------------------------------------- @@ -321,6 +323,9 @@ servers. LSP linters can be used in combination with any other linter, and will automatically connect to LSP servers when needed. ALE also supports `tsserver` for TypeScript, which uses a different but very similar protocol. +If you want to use another plugin for LSP features and tsserver, you can use +the |g:ale_disable_lsp| setting to disable ALE's own LSP integrations, or +ignore particular linters with |g:ale_linters_ignore|. ------------------------------------------------------------------------------- 5.1 Completion *ale-completion* @@ -627,7 +632,9 @@ g:ale_disable_lsp *g:ale_disable_lsp* Type: |Number| Default: `0` - When this option is set to `1`, ALE ignores all linters powered by LSP. + When this option is set to `1`, ALE ignores all linters powered by LSP, + and also `tsserver`. + Please see also |ale-lsp|. diff --git a/test/lsp/test_did_save_event.vader b/test/lsp/test_did_save_event.vader index 423138af..1a60bc9f 100644 --- a/test/lsp/test_did_save_event.vader +++ b/test/lsp/test_did_save_event.vader @@ -3,12 +3,15 @@ Before: Save g:ale_enabled Save g:ale_linters Save g:ale_run_synchronously + Save g:ale_disable_lsp call ale#test#SetDirectory('/testplugin/test/completion') call ale#test#SetFilename('dummy.txt') runtime autoload/ale/lsp.vim + let g:ale_disable_lsp = 0 + unlet! b:ale_disable_lsp let g:ale_lint_on_save = 1 let b:ale_enabled = 1 let g:ale_lsp_next_message_id = 1 diff --git a/test/test_ignoring_linters.vader b/test/test_ignoring_linters.vader index 2d9c67de..f2e9e5c9 100644 --- a/test/test_ignoring_linters.vader +++ b/test/test_ignoring_linters.vader @@ -300,3 +300,98 @@ Execute(Buffer ignore lists should be applied for LSP linters): call ale#lsp_linter#HandleLSPResponse(347, g:lsp_message) AssertEqual [], g:loclist + +Execute(ale_disable_lsp should be applied for tsserver): + call ale#test#SetFilename('filename.ts') + call ale#engine#InitBufferInfo(bufnr('')) + + let g:lsp_message = { + \ 'seq': 0, + \ 'type': 'event', + \ 'event': 'syntaxDiag', + \ 'body': { + \ 'file': g:dir . '/filename.ts', + \ 'diagnostics':[ + \ { + \ 'start': { + \ 'line':2, + \ 'offset':14, + \ }, + \ 'end': { + \ 'line':2, + \ 'offset':15, + \ }, + \ 'text': ''','' expected.', + \ "code":1005 + \ }, + \ ], + \ }, + \} + + call ale#lsp_linter#HandleLSPResponse(347, g:lsp_message) + + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 14, + \ 'nr': 1005, + \ 'code': '1005', + \ 'type': 'E', + \ 'end_col': 15, + \ 'end_lnum': 2, + \ 'text': ''','' expected.', + \ }, + \ ], + \ g:loclist + + let g:loclist = [] + let b:ale_disable_lsp = 1 + call ale#lsp_linter#HandleLSPResponse(347, g:lsp_message) + + AssertEqual [], g:loclist + +Execute(ale_disable_lsp should be applied for LSP linters): + call ale#test#SetFilename('filename.py') + call ale#engine#InitBufferInfo(bufnr('')) + call ale#lsp_linter#SetLSPLinterMap({'347': 'lsplinter'}) + + let g:lsp_message = { + \ 'jsonrpc': '2.0', + \ 'method': 'textDocument/publishDiagnostics', + \ 'params': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'diagnostics': [ + \ { + \ 'severity': 1, + \ 'message': 'x', + \ 'range': { + \ 'start': {'line': 0, 'character': 9}, + \ 'end': {'line': 0, 'character': 9}, + \ }, + \ } + \ ], + \ }, + \} + + call ale#lsp_linter#HandleLSPResponse(347, g:lsp_message) + + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'col': 10, + \ 'type': 'E', + \ 'end_col': 9, + \ 'end_lnum': 1, + \ 'text': 'x', + \ } + \ ], + \ g:loclist + + let b:ale_disable_lsp = 1 + let g:loclist = [] + + call ale#lsp_linter#HandleLSPResponse(347, g:lsp_message) + + AssertEqual [], g:loclist diff --git a/test/test_redundant_tsserver_rendering_avoided.vader b/test/test_redundant_tsserver_rendering_avoided.vader index 6e0b2d30..6125ebc2 100644 --- a/test/test_redundant_tsserver_rendering_avoided.vader +++ b/test/test_redundant_tsserver_rendering_avoided.vader @@ -1,5 +1,9 @@ Before: Save g:ale_buffer_info + Save g:ale_disable_lsp + + let g:ale_disable_lsp = 0 + unlet! b:ale_disable_lsp function! CreateError(type, message) abort let l:diagnostics = [] -- cgit v1.2.3