-
Notifications
You must be signed in to change notification settings - Fork 313
wit-parser: Add validation hooks for custom linting
#2419
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
base: main
Are you sure you want to change the base?
wit-parser: Add validation hooks for custom linting
#2419
Conversation
wit-parser: Add validation hooks for custom linting
|
Redirecting review because I'm not familiar with |
wit-parser: Add validation hooks for custom lintingwit-parser: Add validation hooks for custom linting
|
Apologies for the delay in reviewing this, it's been a busy week! This is a conceptually large enough change that the design in this PR isn't a slam-dunk to me just yet, and it might still be worth considering some of the other options that you laid out. Could you describe your end goal with this a bit more to help shape the thinking there? For example what are you looking to do with spans after a |
|
No problem! Thanks for the response. I totally understand wanting to consider other options that's why I tried to explore and present a few. Not sure if you clicked the links but they lead to diffs with all the changes made for that strategy. The So the first strategy is about making The second strategy, the PR, is allowing consuming code to hook into the resolution process to add additional validation rules at a point in the lifecycle where the |
|
FWIW, I'm working on something for which I'd like to have source span information available as well. Not for validation, but to enable jumping to the line an item is defined in. More generally, making spans available seems like the strictly more expressive change, which might be worth considering. |
|
Ok thanks for the info @wilfreddenton, that helps me at least! Given your use case, what @tschneidereit is describing, and my own experience, I might actually lean more towards including spans on items themselves rather than having side tables or just one pass where the spans are available. I think that'll be the most flexible in terms of what consumers can do with the information. I agree though it's not an easy change, so I think it'd be worth to game it out first before fully committing to ensure it's reasonable. For the breaking change aspect that's ok, this crate has a new major version on all releases intentionally to enable this sort of development. For Default, going this route would I believe basically require that impl to exist. I think the most appropriate default value would be some sort of sentinel for "not present". @wilfreddenton with those two problems in theory resolved, how would you feel about the span-in-item route? |
|
Yes happy to go with the span-in-item route. My main concern with it was breaking changes. The strategy is pretty well explored here: main...wilfreddenton:wasm-tools:wit-parser-spans-in-structs
Are you saying that you want If we want
Would you please provide a quick initial pass of feedback on that diff above? Then I can make the updates and either force push those commits into this PR or close this one and make a new one, whichever you prefer. |
#2418
There are two strategies I've explored for giving consumers access to source locations:
Make spans available on resolved items so consumers can inspect them after resolution. There are two ways I found to do this
span: Option<Span>directly toTypeDef,Function,Interface,WorldHashMap<Id, Span>fields onResolveResolvederivesDefaultso not likely to break consumers)Hook into internal validation (this PR)
Keep spans private but let consumers hook into the resolution process via a
Validatortrait with callbacks.push_*calls, not after-the-fact inspectionThis PR implements Strategy 2 because it avoids breaking changes and has zero cost for existing. However, I'm happy to go with one of the other strategies or something totally new that I haven't considered.
Here's an example of how a consumer would use this new features: