Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the lsp diagnostic message format #2425

Merged
merged 6 commits into from
Apr 15, 2019
Merged

Conversation

shuwens
Copy link
Contributor

@shuwens shuwens commented Apr 8, 2019

Here I am trying to improve the LSP diagnostic message format via replacing the line breaks with spaces (see #2301). This fix will affect the message in the status line, virtual text and the ALEDetail.

However, I don't think this is what we desire: now the ALEDetail no longer has the line breaks. I assume the virtual text region is somehow binded with the ALEDetail? Any input on it?

Regards,

* replace the line breaks with spaces
@@ -27,6 +27,7 @@ function! ale#lsp#response#ReadDiagnostics(response) abort

for l:diagnostic in a:response.params.diagnostics
let l:severity = get(l:diagnostic, 'severity', 0)
let l:diagnostic.message = substitute(l:diagnostic.message, "\n", ' ', 'g')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of modifying the incoming Dictionary, set the value with newlines in the detail key, and the value with newlines replaced in the text key. Add tests for this.

@w0rp w0rp added this to In Review in Old Working List via automation Apr 8, 2019
@shuwens
Copy link
Contributor Author

shuwens commented Apr 8, 2019

I believe the code actually works but I am still failing the test. Am I missing something here?

" we want to preserve the line breaks for `detail` but replace with
" spaces for text
let l:diagnostic.detail = l:diagnostic.message
let l:diagnostic.text = substitute(l:diagnostic.message, "\n", ' ', 'g')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't modify the incoming object here, just adjust the objects we're creating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like:

        let l:diagnostic.text = l:diagnostic.message
        let l:diagnostic.text = substitute(l:diagnostic.text, "\n", ' ', 'g')

I don't think this passes the unit test. I am not very good at Vimscript so sorry about these problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass substitute(l:diagnostic.message, "\n", ' ', 'g') to the text key below without modifying the object, and use l:diagnostic.message below that as before.

@shuwens
Copy link
Contributor Author

shuwens commented Apr 10, 2019

I just convert this PR to use the simple approach as suggested but the test is still failing. Is there something wrong with the test I wrote?

\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ {
\ 'range': Range(9, 14, 11, 22),
\ 'message': 'cannot borrow `cap` as mutable more than once at a time\n\nmutable borrow starts here in previous iteration of loop',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\ 'message': 'cannot borrow `cap` as mutable more than once at a time\n\nmutable borrow starts here in previous iteration of loop',
\ 'message': "cannot borrow `cap` as mutable more than once at a time\n\nmutable borrow starts here in previous iteration of loop",

Here's the problem with your test. Escapes like \n are only applied for double quoted strings.

@@ -28,7 +28,7 @@ function! ale#lsp#response#ReadDiagnostics(response) abort
for l:diagnostic in a:response.params.diagnostics
let l:severity = get(l:diagnostic, 'severity', 0)
let l:loclist_item = {
\ 'text': l:diagnostic.message,
\ 'text': substitute(l:diagnostic.message, "\n", ' ', 'g'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\ 'text': substitute(l:diagnostic.message, "\n", ' ', 'g'),
\ 'text': substitute(l:diagnostic.message, '\(\r\n\|\n\|\r\)', ' ', 'g'),

I think you should handle Windows style CRLF newlines too. For example:

:echo substitute("one\ntwo\r\nthree\rfour", '\(\r\n\|\n\|\r\)', ' ', 'g')

The string for the regex has to be single quoted here. Add tests for \r by itself and \r\n.

@w0rp w0rp merged commit 7f31065 into dense-analysis:master Apr 15, 2019
Old Working List automation moved this from In Review to Done Apr 15, 2019
@w0rp
Copy link
Member

w0rp commented Apr 15, 2019

Cheers! 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants