fix(macros): resolve quick start source info from item spans#18
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Quick Start failures (Issue #17) by improving how the statum-macros proc-macros resolve source file + module path information, preferring annotated item spans over proc-macro call-site spans and avoiding non-disk paths during source scans.
Changes:
- Add span-based source/module resolution helpers in
macro_registryand switch#[state],#[machine],#[transition], and#[validators]to use them. - Improve validator machine resolution diagnostics by using span-derived source info (with call-site fallback) for source scanning.
- Add a Quick Start regression UI fixture and update docs to use repo-relative links so link checking works under
act.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
statum-macros/tests/ui/valid_quick_start.rs |
Adds a Quick Start regression fixture exercising #[state], #[machine], and #[transition]. |
statum-macros/tests/macro_errors.rs |
Registers the new Quick Start UI test as a passing trybuild case. |
statum-macros/src/validators/resolution.rs |
Uses span-derived source info to improve candidate scanning/diagnostics during validator machine resolution. |
statum-macros/src/validators.rs |
Adjusts parse_validators to accept a parsed ItemImpl (caller parses once). |
statum-macros/src/state.rs |
Switches #[state] enum metadata/module resolution to span-based helpers. |
statum-macros/src/machine/metadata.rs |
Switches #[machine] struct metadata/module resolution to span-based helpers. |
statum-macros/src/lib.rs |
Uses impl-item spans for resolving module path in #[transition] / #[validators], and parses ItemImpl once for validators. |
macro_registry/src/callsite.rs |
Introduces span-based (file,line) and module-path helpers, rejecting non-disk paths before scanning. |
macro_registry/Cargo.toml |
Adds proc-macro2 with span-locations to support span-based resolution. |
docs/inspector-plan.md |
Replaces absolute local-file links with repo-relative links for CI doc link checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
statum-macros/src/lib.rs
Outdated
| let line_number = Span::call_site().start().line; | ||
| let module_path = match resolved_current_module_path(Span::call_site(), "#[validators]") { | ||
| let item_impl = parse_macro_input!(item as ItemImpl); | ||
| let line_number = item_impl.impl_token.span.start().line; |
There was a problem hiding this comment.
line_number for #[validators] is now taken from item_impl.impl_token.span.start().line, which can be 0 when span location info is unavailable. That value is later used to derive stable hashed identifiers (and potentially in diagnostics), so a 0 can increase the chance of identifier collisions and reduce error-message quality. Consider deriving the line number via macro_registry::callsite::source_info_for_span_or_callsite(item_impl.impl_token.span) (or falling back to Span::call_site().start().line when 0).
| let line_number = item_impl.impl_token.span.start().line; | |
| let mut line_number = item_impl.impl_token.span.start().line; | |
| if line_number == 0 { | |
| line_number = Span::call_site().start().line; | |
| } |
There was a problem hiding this comment.
Fixed in 3b71577. #[validators] now derives line_number from source_info_for_span_or_callsite(span) and only falls back to the raw span line when needed.
Fixes #17.
Summary
#[state],#[machine],#[transition], and#[validators]docs/inspector-plan.mdto repo-relative links so the docs link check passes underactTesting