improve error locations for unexpected properties #664
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.
Why
At replit we use taplo for providing lsp support for our
.replit
configuration file in Repls. We love Taplo!However, when an unexpected property appears that's invalid according to
additionalProperties: false
from the corresponding JSON schema, the LSP highlights the whole file!for example, making invalid changes to this valid
.replit
file i used for a throwaway Repl I made when debugging this issue:results in this UX:
note in this screenshot that the diagnostics are collated to the first diagnostic range, which is the whole file:
those error spans aren't the most helpful, especially that 2nd screenshot 😬
What changed
taplo::dom::Node::text_ranges
method to accept a new argumentinclude_children: bool
which conditionally recurses into children when the value is true.true
was the default behavior prior to this changetaplo_common::schema::NodeValidationError::text_ranges
method to conditionally passfalse
to the above method.jsonschema::error::ValidationErrorKind::AdditionalProperties
errors result in this value beingfalse
, but it may be desired that other error kinds should result in this value beingfalse
lint
andlsp
commands to use the newNodeValidationError::text_ranges
method instead ofNode::text_ranges
Node::text_ranges
passtrue
as the parameter to minimize unexpected behaviorthis results in this new behavior: