Skip to content

fix(vespera_macro): IDE free-fn count and raw cron alias guards (round 63) - #651

Open
owjs3901 wants to merge 2 commits into
mainfrom
fix/macrorest-round63
Open

owjs3901 wants to merge 2 commits into
mainfrom
fix/macrorest-round63

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Round-63 macro/rest fixes (pending findings R63-MR2-L1 and R63-MR5-L1).

Fixed

  • R63-MR2-L1 (LOW, IDE only): stale unknown-scope entry beside a handler with the same name. single_declaration_in_ide and moved_away (crates/vespera_macro/src/macro_storage.rs) counted every textual fn <name>, including impl methods, trait items and nested fns. An impl Repo { fn list(&self) } beside #[route(get)] pub async fn list() made the count 2, so rust-analyzer kept the stale entry and vespera! emitted list twice. The count is now count_free_fn_declarations: module-level fn items (inline modules included) plus the fn <name> text of macro_rules! bodies, which may expand to a second declaration. Unparsable text falls back to the textual count. declares_fn in retain_declared stays textual.
  • R63-MR5-L1 (LOW): raw spelling of the cron rename. In vespera_impl/cron_discovery/imports.rs, the two rename.rename == "cron" guards (explicit-import and inherited-rename arms) compared a raw identifier against &str, which is false for r#cron (syn Ident == &str compares the raw spelling). They now compare rename.unraw(). Effects: use other::cron as r#cron; is an explicit foreign import again (a bare #[cron] is no longer scheduled), and use super::cron as r#cron; in a child module inherits the parent's cron.

Refuted

  • component_schemas.rs:548 (f.sig.ident == name with raw function_name). Not a bug. function_name is sig.ident.to_string() and stays raw (r#match), and proc-macro2's Ident: PartialEq<str> matches a raw ident against its r#-prefixed spelling (checked in proc-macro2 1.0.99 fallback.rs: if self.raw { other.starts_with("r#") && sym == other[2..] }). The route name passed there is the raw one, so the comparison holds. The unraw-trimmed names at lines 437/441/478 are compared against unraw names and are unaffected.

Tests

  • macro_storage/tests.rs: ide_stale_entry_is_dropped_beside_an_impl_method_of_the_same_name, ide_moved_entry_is_dropped_when_an_impl_method_shares_the_name. Mutation check: with the old textual count both fail; with the fix both pass.
  • macro_storage/tests_count.rs: count_free_fn_declarations_counts_module_level_fns (impl/trait/nested fns, two modules, macro_rules! bodies at top level and in an inline module, comments, unparsable fallback).
  • cron_discovery/tests_alias.rs: raw_spelled_cron_imports_match_the_plain_spelling (8 cases). Before the fix, the foreign root raw rename, the raw rename beside a vespera glob, and the child super::cron as r#cron of a foreign cron fail; the rest are guards.

Checks

  • cargo test -p vespera_macro --lib: 7445 passed.
  • cargo clippy -p vespera_macro --all-targets --all-features -D warnings: clean. cargo fmt --check: clean.
  • bun scripts/check-version-alignment.ts: all 7 packages at 0.8.0.
  • Changepack: .changepacks/changepack_log_macrorest_round63.json (Patch, all 7 packages, ASCII note).
  • Changed files stay under 1000 lines (macro_storage.rs 632, tests_alias.rs 607).

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 30, 2026 18:55
… cron aliases unraw

- macro_storage: the IDE single-declaration and moved-away checks count
  module-level fn items (inline modules included, plus macro_rules!
  bodies) instead of every textual `fn <name>`, so an impl method sharing
  a handler's name no longer keeps a stale unknown-scope entry beside the
  saved one (duplicate route in rust-analyzer). Unparsable text falls
  back to the textual count.
- cron_discovery/imports: the `as cron` rename guards compare
  `rename.unraw()`, so `use other::cron as r#cron;` is an explicit
  foreign import and `use super::cron as r#cron;` inherits the parent's
  cron. syn's Ident == &str is false for a raw spelling.
- Tests: impl-method IDE cases, direct count cases, raw-spelled cron
  import cases (the foreign and child ones fail before the fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant