-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
WIP Fix HandleLSPDiagnostics buffer match logic. #2524
WIP Fix HandleLSPDiagnostics buffer match logic. #2524
Conversation
To find the buffer corresponding to URIs reported by LSP the HandleLSPDiagnostics() method uses the built-in bufnr() function. From the documentation we learn that the first parameter of bufnr() is an expression, not a path. EclipseLSP will report project wide errors (e.g. gradle errors) that are not related to any actual source file with an URI that corresponds to the project root folder, e.g: file:///home/username/Projects/gradle-simple This URI will match any open buffer of files within the project root hiearchy, thus project-wide errors appear as part of every file within the project, e.g: file:///home/username/Projects/gradle-simple/src/main/java/Hello.java To fix this, this MR adds '^' to the beginning and '$' at the end of the URI path to force an exact match. This is how is recommended in vim help (see :h bufname).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Add a test for this and apply this to the tsserver function too.
@w0rp I have modified the TS diagnostics function too to force exact match of files. Regarding tests for this I require some guidance since the s:HandleLSPDiagnostics() method is private to the lsp_linter.vim script, thus cannot be directly tested without renaming it. Another way would be to modify the ale#lsp#response#ReadDiagnostics() function to do the buffer resolution and return it as part of the l:loclist. This would allow us to test the buffer resolution by simple modifications to the test_read_lsp_diagnostics.vader test. Not sure if this would break a lot of other things. |
Have a look at |
@w0rp I am having some issues getting one of my LSP tests to pass:
I have verified the LSP linter works as expected in vim/nvim (e.g. the project wide errors do not appear on the loclist). But in the test the loclist seems to be always populated with the error. I have verified that the "l:bufffer" variable is indeed set to "-1", therefore the "empty(l:info)" condition is true and the s:HandleLSPDiagnostics() method returns at that point:
Not sure what the problem could be here but it seems to affect only the test. |
I'll see if I can fix the test today. |
I've fixed the tests now. Data in tests wasn't being set up and torn down properly in a few places. The tests should now pass when you run them in your editor with |
Cheers! 🍻 |
To find the buffer corresponding to URIs reported by LSP the
HandleLSPDiagnostics() method uses the built-in bufnr() function. From
the documentation we learn that the first parameter of bufnr() is
an expression, not a path.
EclipseLSP will report project wide errors (e.g. gradle errors) that are
not related to any actual source file with an URI that corresponds to the
project root folder, e.g:
file:///home/username/Projects/gradle-simple
This URI will match any open buffer of files within the project root
hiearchy, thus project-wide errors appear as part of every file within
the project, e.g:
file:///home/username/Projects/gradle-simple/src/main/java/Hello.java
To fix this, this MR adds '^' to the beginning and '$' at the end of the
URI path to force an exact match. This is how is recommended in vim
help (see :h bufname).
Where are the tests? Have you added tests? Have you updated the tests? Read the
comment above and the documentation referenced in it first. Write tests!
Seriously, read
:help ale-dev
and write tests.