From 484a70f0c0c9109ab6825fa67e481d862237207c Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Wed, 15 Aug 2018 14:19:32 -0700 Subject: [PATCH 1/4] Use new-ish LSP 'relatedInformation' field for :ALEDetail --- autoload/ale/lsp/response.vim | 10 ++++++++ test/lsp/test_read_lsp_diagnostics.vader | 29 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim index 561be62e..7984369d 100644 --- a/autoload/ale/lsp/response.vim +++ b/autoload/ale/lsp/response.vim @@ -55,6 +55,16 @@ function! ale#lsp#response#ReadDiagnostics(response) abort endif endif + if has_key(l:diagnostic, 'relatedInformation') + let l:related = deepcopy(l:diagnostic.relatedInformation) + call map(l:related, {key, val -> + \ ale#path#FromURI(val.location.uri)) . + \ ':' . val.location.range.start.line . ':' . val.location.range.start.character . + \ ': ' . val.message + \ }) + let l:loclist_item.detail = join(l:related, "\n") . "\n" + endif + call add(l:loclist, l:loclist_item) endfor diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index df187a24..c1df55f0 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -140,6 +140,35 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages): \ }, \ ]}}) +Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for detail): + AssertEqual [ + \ { + \ 'type': 'E', + \ 'text': 'Something went wrong!', + \ 'lnum': 1, + \ 'col': 3, + \ 'end_lnum': 1, + \ 'end_col': 3, + \ 'relatedInformation': [{ + \ 'message': 'might be this', + \ 'location': { + \ 'uri': 'file:///tmp/someotherfile.txt', + \ 'range': { + \ 'start': { 'line': 42, 'character': 79 }, + \ 'end': { 'line': 43, 'character': 80 }, + \ } + \ } + \ }] + \ } + \ ], + \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ + \ { + \ 'range': Range(0, 2, 0, 2), + \ 'message': 'Something went wrong!', + \ 'detail': 'file:///tmp/someotherfile.txt:42:79: might be this' + \ } + \ ]}}) + Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses): AssertEqual \ [ From c467db3ed99dc7c911ddb1fefa9d66ac84fc76a6 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Wed, 15 Aug 2018 14:31:30 -0700 Subject: [PATCH 2/4] Better formatting --- autoload/ale/lsp/response.vim | 6 +++--- test/lsp/test_read_lsp_diagnostics.vader | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim index 7984369d..4b895ac7 100644 --- a/autoload/ale/lsp/response.vim +++ b/autoload/ale/lsp/response.vim @@ -58,11 +58,11 @@ function! ale#lsp#response#ReadDiagnostics(response) abort if has_key(l:diagnostic, 'relatedInformation') let l:related = deepcopy(l:diagnostic.relatedInformation) call map(l:related, {key, val -> - \ ale#path#FromURI(val.location.uri)) . + \ ale#path#FromURI(val.location.uri) . \ ':' . val.location.range.start.line . ':' . val.location.range.start.character . - \ ': ' . val.message + \ ":\n\t" . val.message \ }) - let l:loclist_item.detail = join(l:related, "\n") . "\n" + let l:loclist_item.detail = l:diagnostic.message . "\n" . join(l:related, "\n") . "\n" endif call add(l:loclist, l:loclist_item) diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index c1df55f0..6708ad2f 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -165,7 +165,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ { \ 'range': Range(0, 2, 0, 2), \ 'message': 'Something went wrong!', - \ 'detail': 'file:///tmp/someotherfile.txt:42:79: might be this' + \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:42:79:\n\tmight be this" \ } \ ]}}) From 764da48c576c2be6b6d02ae6a7f59f9167b11de3 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Wed, 15 Aug 2018 14:40:51 -0700 Subject: [PATCH 3/4] Test file was the wrong way around --- test/lsp/test_read_lsp_diagnostics.vader | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index 6708ad2f..d795ae29 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -149,6 +149,13 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ 'col': 3, \ 'end_lnum': 1, \ 'end_col': 3, + \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:42:79:\n\tmight be this" + \ } + \ ], + \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ + \ { + \ 'range': Range(0, 2, 0, 2), + \ 'message': 'Something went wrong!', \ 'relatedInformation': [{ \ 'message': 'might be this', \ 'location': { @@ -160,13 +167,6 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ } \ }] \ } - \ ], - \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ - \ { - \ 'range': Range(0, 2, 0, 2), - \ 'message': 'Something went wrong!', - \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:42:79:\n\tmight be this" - \ } \ ]}}) Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses): From 4923d48d53a2ca64d2a125ff5ea4e4c9aa744f48 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Wed, 15 Aug 2018 14:46:57 -0700 Subject: [PATCH 4/4] Correct related information line numbers from 0-based to 1-based --- autoload/ale/lsp/response.vim | 5 +++-- test/lsp/test_read_lsp_diagnostics.vader | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim index 4b895ac7..69e88d56 100644 --- a/autoload/ale/lsp/response.vim +++ b/autoload/ale/lsp/response.vim @@ -59,10 +59,11 @@ function! ale#lsp#response#ReadDiagnostics(response) abort let l:related = deepcopy(l:diagnostic.relatedInformation) call map(l:related, {key, val -> \ ale#path#FromURI(val.location.uri) . - \ ':' . val.location.range.start.line . ':' . val.location.range.start.character . + \ ':' . (val.location.range.start.line + 1) . + \ ':' . (val.location.range.start.character + 1) . \ ":\n\t" . val.message \ }) - let l:loclist_item.detail = l:diagnostic.message . "\n" . join(l:related, "\n") . "\n" + let l:loclist_item.detail = l:diagnostic.message . "\n" . join(l:related, "\n") endif call add(l:loclist, l:loclist_item) diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index d795ae29..be50fbe8 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -149,7 +149,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ 'col': 3, \ 'end_lnum': 1, \ 'end_col': 3, - \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:42:79:\n\tmight be this" + \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:43:80:\n\tmight be this" \ } \ ], \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ @@ -162,7 +162,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ 'uri': 'file:///tmp/someotherfile.txt', \ 'range': { \ 'start': { 'line': 42, 'character': 79 }, - \ 'end': { 'line': 43, 'character': 80 }, + \ 'end': { 'line': 142, 'character': 179}, \ } \ } \ }]