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

Expose field name suggestions for ignored fields that are typos #13

Open
nipunn1313 opened this issue Aug 15, 2021 · 2 comments
Open

Expose field name suggestions for ignored fields that are typos #13

nipunn1313 opened this issue Aug 15, 2021 · 2 comments

Comments

@nipunn1313
Copy link

nipunn1313 commented Aug 15, 2021

For example, if deserializing something like

[dependencies]
serde = { version = "1.0.126", optional = true, feautres = ["derive"] }

With something like

let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| {
    unused.insert(format!("{}", path));
})?;

We could have serde-ignored (perhaps behind a feature flag) leverage something like lev_distance to give suggestions - which the callsite could use as suggestions

Possible new call syntax

let manifest: TomlManifest = serde_ignored::deserialize_with_suggestions(toml, 2 /* lev distance */, |path: Path, suggestions: Vec<Path>| {
    if ! suggestions.empty() {
      print("{} unused. Did you mean {}", path, suggestions[0]);
    }
    unused.insert(stringify(path));
})?;

^ which would ideally print "dependencies.serde.feautres unused. Did you mean dependencies.serde.features"

Inspired by
rust-lang/cargo#5264 and
rust-lang/cargo#9731

@nipunn1313
Copy link
Author

I'm not sure if the idea I gave for this problem is actually achievable. In reading up, I found:

Deserializer for struct might look like this https://serde.rs/deserialize-struct.html
The wrapping deserializer in serde-ignored is passed a visitor, but can't get a list of possible valid strings that the visitor's visit_str would accept, therefore it can't augment self.path with suggestions.
I suppose it could call visitor.visit_str(guess) with a bunch of guesses of short-edit-distance, but that's hardly appetizing.

What's a better way to do this sort of thing?

@petr-tik
Copy link

petr-tik commented Apr 4, 2022

i think this would be a great addition and only reinforce the rust culture of actionable error messages

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

No branches or pull requests

2 participants