-
Notifications
You must be signed in to change notification settings - Fork 270
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
Fix Diagnostic Positions #261
Fix Diagnostic Positions #261
Conversation
Moving things around a little in @JPinkney Please let me know if you'd rather I didn't move things around (e.g. extracting helpers into their own util file). I've been running |
Looking at the pipeline, clearly I should be compiling after every step too — on it. |
Moving around things works for me if it makes the code cleaner 👍 Let me know when this PR is ready to review and i'll take a look! |
So, as I dig deeper on this, the issue is that the exceptions from While the exceptions give accurate starting positions (including line and column numbers), there is — as far as I can tell — no good way to reconstruct the exceptions' ending positions. I've tried doing so with the I'm not really sure what the next step is. I'm now getting accurate diagnostics for a few error types, and only a couple of tests are failing right now, but I'm really not confident that trying to hack around the AST parsing library won't just create more problems not reflected in the tests. I could, of course, be completely overlooking something obvious, but it seems like we'd need to build out a different approach for the diagnostic generation. I'll investigate this further, but diagnostic positions way back in |
We've had the yaml ast parser since the beginning and yaml-ast-parser-custom-tags (the one we use) should just be master of yaml-ast-parser with one patch ontop. If I were to guess, the problems arose with this massive PR: https://github.com/redhat-developer/yaml-language-server/pull/147/files. I'll have to take a deeper look. One noticeable thing I've found is that convert error in 0.4.1 seems to use a much simpler convertError function: https://github.com/redhat-developer/yaml-language-server/blob/0.4.1/src/languageservice/parser/yamlParser.ts#L203. I can't recall why the convertError function was changed and I can't find any associated issue with that change either. So maybe the solution is to just change the convertError function back |
It looks like doing something like: const line = e.mark.line < 0 ? 0 : e.mark.line;
const character = e.mark.position + e.mark.column < 0 ? 0 : e.mark.position + e.mark.column; in convert error might work. The only issue with that code is it seems to be showing the error on the value instead of the key. const line = e.mark.line < 0 ? 0 : e.mark.line;
const character = e.mark.column + 1; might work as well. It seems to show the error on the correct location in my limited testing |
Sorry for being a little slow with this PR — @JPinkney if you want to take just a quick peek at this, I'm pretty sure that I successfully reverted the diagnostic positions to how they were handled in |
assert.equal(result.length, 2); | ||
assert.deepEqual( | ||
result[0], | ||
createExpectedError(BlockMappingEntryError, 1, 13, 1, 13) | ||
createExpectedError(BlockMappingEntryError, 1, 2, 1, 2) |
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.
I feel pretty confident that the old test was wrong — the error should be on character two, the line doesn't extend to a thirteenth character.
This is in line with the logging I did on the testing suite in 0.4.1
.
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.
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.
^output from 0.4.1
And just to document this here: I didn't realize that the language server spec includes a function that will determine the line and character position from the absolute position in the string, |
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.
Super small nitpicks but overall it's really good! I'm excited to get this in
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.
Oops meant to click request changes, just for the nitpicks then I'll merge 😉
Also it will need to be rebased |
7eeb75e
to
75a369f
Compare
Implemented the requested changes — let me know if we need anything else for a merge! I think the positions are still a little weird with some kinds of errors, but reverting to the old working implementation I think will fix a lot of them. |
See issue #260