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

🐛 Fix JSON array/object parsers not absorbing child parser errors #1132

Merged
merged 13 commits into from
May 16, 2024

Conversation

TheAfroOfDoom
Copy link
Contributor

@TheAfroOfDoom TheAfroOfDoom commented May 13, 2024

Summary

these parsers were not absorbing their child parser's errors due to them calling the JSON entry parser (json(dumpErrors = true))

with dumpErrors = true, the child parsers would dump errors into a temporary context that wasn't actually then sent to the language server

https://github.com/TheAfroOfDoom/Spyglass/blob/b6ecdcad78be7a44ef564afdfc9c51daedf38de8/packages/json/src/parser/entry.ts#L40-L42

fix is to not use the entry parser and instead use json(dumpErrors = false) so the errors from child parsers are absorbed later by the parent parsers and ultimately outputted to the language server

https://github.com/TheAfroOfDoom/Spyglass/blob/b6ecdcad78be7a44ef564afdfc9c51daedf38de8/packages/core/src/parser/util.ts#L67-L70

the JSON array and object parsers were the only two places i found that were incorrectly using the entry parser


Screenshots

JSON array parser

before after
image image

JSON object parser

before after
image image

Blockers

this PR likely should wait until #1127 is merged since that PR fixes a related bug

(the branch is currently rebased off of #1127, so those commits will show up here)

#1127 has been merged, so no more blockers 😄

Copy link
Member

@MulverineX MulverineX left a comment

Choose a reason for hiding this comment

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

Make sure to rebase but besides that, this looks great 👍

@TheAfroOfDoom TheAfroOfDoom force-pushed the fix-string-error-not-displaying branch from 370c273 to 74a6855 Compare May 14, 2024 01:32
@TheAfroOfDoom TheAfroOfDoom force-pushed the fix-string-error-not-displaying branch from 5bffcff to 41b5c8b Compare May 14, 2024 03:12
@TheAfroOfDoom TheAfroOfDoom requested review from misode and SPGoding May 14, 2024 03:12
- covers generic cases, not the bug yet
- they aren't outputting errors as they should
  - for invalid char escape (`\z`)
  - for invalid unicode escape (`\u1z34`)
- giving `entry` as the `value` parser made it dump errors early (to a dummy `ctx`), before we absorbed them to a parent parser
- covers generic cases, not the bug yet
- same as the array stuff earlier...
- only not working when the error is in the `value`; the `key` is fine
  - this makes sense when you see that `key`/`value` use different parsers
@TheAfroOfDoom TheAfroOfDoom force-pushed the fix-string-error-not-displaying branch from 41b5c8b to f3258fe Compare May 14, 2024 23:09
Copy link
Member

@misode misode left a comment

Choose a reason for hiding this comment

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

I made some changes in order to make the json entry parser not take a boolean. Instead the error dumping is now handled by a separate wrapper, to make the intent more clear in the JSON initialize function and also so we don't accidentally dump errors in the future.

@TheAfroOfDoom TheAfroOfDoom requested a review from misode May 16, 2024 05:25
@misode misode merged commit ad778e3 into SpyglassMC:main May 16, 2024
3 checks passed
@TheAfroOfDoom TheAfroOfDoom deleted the fix-string-error-not-displaying branch May 17, 2024 03:19
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.

4 participants