feat: provide context around the language config (merged TOML) on load error #13755
+71
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed while working with Helix recently (noted in #11666) that if I produced a bad configuration, it was hard to tell what I'd done wrong.
This is made doubly hard as the true source of the bug is a merged TOML (the default language config and the user's language config). The user's config may have many languages in, but if a language fails to parse into a
Configuration
(serde-derived struct) then the entire block will be given as the error source, so you would just see for example:I added a second step where, in the case of an error, this merged TOML value is retrieved, then converted to a string (thus allowing an error from parsing it to have a span, i.e. to know which byte and thus which line it occurred at, and thus to track down which language section it was in).
I then added a simple "go to the end of the section" and put a sensible limit of no more than 50 lines of context (for the example of the Rust language section it was 20 lines, and you need to read at least 8 lines to see the
name = "rust
line, as it's alphabetised when merging by the looks of it).The resulting diagnostic would be very helpful when in a tricky situtation. In the case shown here, you'd be able to see that the error was misleading: the duplicate field is actually due to an alias. With only the
language
line though you could be really stumped trying to figure this one out.