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

improve error locations for unexpected properties #664

Merged

Conversation

cdmistman
Copy link
Contributor

@cdmistman cdmistman commented Aug 30, 2024

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:

run = "cargo run -- /etc/replit/dotreplit.schema.json dotreplit.json"
modules = ["rust-stable"]

[nix]
channel = "stable-24_05"

results in this UX:
image

note in this screenshot that the diagnostics are collated to the first diagnostic range, which is the whole file:
image
image
image

those error spans aren't the most helpful, especially that 2nd screenshot 😬

What changed

  1. updated taplo::dom::Node::text_ranges method to accept a new argument include_children: bool which conditionally recurses into children when the value is true. true was the default behavior prior to this change
  2. created new taplo_common::schema::NodeValidationError::text_ranges method to conditionally pass false to the above method.
    • right now, only jsonschema::error::ValidationErrorKind::AdditionalProperties errors result in this value being false, but it may be desired that other error kinds should result in this value being false
    • i wanted to minimize changing behavior in case this resulted in unexpected behavior
  3. updated lint and lsp commands to use the new NodeValidationError::text_ranges method instead of Node::text_ranges
  4. all other calls to Node::text_ranges pass true as the parameter to minimize unexpected behavior

this results in this new behavior:
image
image

@cdmistman
Copy link
Contributor Author

note in the new-behavior screenshots that only the value is underlined with the error. i'd like this to underline the full entry, but i'll figure that out later

@panekj panekj merged commit b536710 into tamasfe:master Aug 30, 2024
37 checks passed
@panekj
Copy link
Collaborator

panekj commented Aug 30, 2024

Thanks!

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.

2 participants