summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Emmott <fe@fb.com>2018-07-30 15:19:59 -0700
committerFred Emmott <fe@fb.com>2018-08-02 09:06:48 -0700
commit2768bf15ba5ca95f126405459c4a8180e814af18 (patch)
tree49ac9e30790dc36498bf6dcd915e1031f86e0ce3
parent16d0c52d24e8948b8bd8030e3fd112e0b6361c06 (diff)
downloadale-2768bf15ba5ca95f126405459c4a8180e814af18.zip
Handle LSP codes for `%code%` in message formats
fixes #1767
-rw-r--r--autoload/ale/lsp/response.vim14
-rw-r--r--doc/ale.txt6
-rw-r--r--test/lsp/test_read_lsp_diagnostics.vader9
-rw-r--r--test/test_engine_lsp_response_handling.vader2
-rw-r--r--test/test_ignoring_linters.vader1
5 files changed, 27 insertions, 5 deletions
diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim
index 48740ad1..b389ab18 100644
--- a/autoload/ale/lsp/response.vim
+++ b/autoload/ale/lsp/response.vim
@@ -47,7 +47,12 @@ function! ale#lsp#response#ReadDiagnostics(response) abort
endif
if has_key(l:diagnostic, 'code')
- let l:loclist_item.nr = l:diagnostic.code
+ if type(l:diagnostic.code) == v:t_string
+ let l:loclist_item.code = l:diagnostic.code
+ elseif type(l:diagnostic.code) == v:t_number && l:diagnostic.code != -1
+ let l:loclist_item.code = string(l:diagnostic.code)
+ let l:loclist_item.nr = l:diagnostic.code
+ endif
endif
call add(l:loclist, l:loclist_item)
@@ -70,7 +75,12 @@ function! ale#lsp#response#ReadTSServerDiagnostics(response) abort
\}
if has_key(l:diagnostic, 'code')
- let l:loclist_item.nr = l:diagnostic.code
+ if type(l:diagnostic.code) == v:t_string
+ let l:loclist_item.code = l:diagnostic.code
+ elseif type(l:diagnostic.code) == v:t_number && l:diagnostic.code != -1
+ let l:loclist_item.code = string(l:diagnostic.code)
+ let l:loclist_item.nr = l:diagnostic.code
+ endif
endif
if get(l:diagnostic, 'category') is# 'warning'
diff --git a/doc/ale.txt b/doc/ale.txt
index 15a20469..e68ba9df 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2318,6 +2318,12 @@ ale#linter#Define(filetype, linter) *ale#linter#Define()*
`type` - Defaults to `'E'`.
`nr` - Defaults to `-1`.
+ Numeric error code. If `nr` is not `-1`, `code` should have
+ the same value.
+ `code` - No default.
+
+ String error code.
+
`executable` A |String| naming the executable itself which
will be run. This value will be used to check if the
program requested is installed or not.
diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader
index 444272aa..134a7161 100644
--- a/test/lsp/test_read_lsp_diagnostics.vader
+++ b/test/lsp/test_read_lsp_diagnostics.vader
@@ -18,7 +18,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
\ 'col': 11,
\ 'end_lnum': 5,
\ 'end_col': 16,
- \ 'nr': 'some-error',
+ \ 'code': 'some-error',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
@@ -39,7 +39,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
\ 'col': 4,
\ 'end_lnum': 2,
\ 'end_col': 4,
- \ 'nr': 'some-warning',
+ \ 'code': 'some-warning',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
@@ -60,7 +60,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing se
\ 'col': 11,
\ 'end_lnum': 5,
\ 'end_col': 16,
- \ 'nr': 'some-error',
+ \ 'code': 'some-error',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
@@ -126,6 +126,7 @@ Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver respon
\ {
\ 'type': 'E',
\ 'nr': 2365,
+ \ 'code': '2365',
\ 'text': 'Operator ''''+'''' cannot be applied to types ''''3'''' and ''''{}''''.',
\ 'lnum': 1,
\ 'col': 11,
@@ -142,6 +143,7 @@ Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle warnings from t
\ 'lnum': 27,
\ 'col': 3,
\ 'nr': 2515,
+ \ 'code': '2515',
\ 'end_lnum': 27,
\ 'type': 'W',
\ 'end_col': 14,
@@ -157,6 +159,7 @@ Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle suggestions fro
\ 'lnum': 27,
\ 'col': 3,
\ 'nr': 2515,
+ \ 'code': '2515',
\ 'end_lnum': 27,
\ 'type': 'I',
\ 'end_col': 14,
diff --git a/test/test_engine_lsp_response_handling.vader b/test/test_engine_lsp_response_handling.vader
index 517d82c0..ddcd7b2e 100644
--- a/test/test_engine_lsp_response_handling.vader
+++ b/test/test_engine_lsp_response_handling.vader
@@ -62,6 +62,7 @@ Execute(tsserver syntax error responses should be handled correctly):
\ 'col': 14,
\ 'vcol': 0,
\ 'nr': 1005,
+ \ 'code': '1005',
\ 'type': 'E',
\ 'text': ''','' expected.',
\ 'valid': 1,
@@ -135,6 +136,7 @@ Execute(tsserver semantic error responses should be handled correctly):
\ 'col': 14,
\ 'vcol': 0,
\ 'nr': 1005,
+ \ 'code': '1005',
\ 'type': 'E',
\ 'text': 'Some semantic error',
\ 'valid': 1,
diff --git a/test/test_ignoring_linters.vader b/test/test_ignoring_linters.vader
index af31fce3..1ddd30e8 100644
--- a/test/test_ignoring_linters.vader
+++ b/test/test_ignoring_linters.vader
@@ -190,6 +190,7 @@ Execute(Buffer ignore lists should be applied for tsserver):
\ 'lnum': 2,
\ 'col': 14,
\ 'nr': 1005,
+ \ 'code': '1005',
\ 'type': 'E',
\ 'end_col': 15,
\ 'end_lnum': 2,