diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-20 04:22:43 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-20 04:22:43 +0800 |
| commit | f6113a33f782d1eabd350e3b34ce8de2cec2f8d3 (patch) | |
| tree | eef1ce51194d467a50901ade540a60c3374527fb /mingling_macros/src/extensions/routeify.rs | |
| parent | 12d8b602415f1c0688f47c8f002e48a4de1c683c (diff) | |
feat(routeify): map `?` span to `route!` for tooling support
Use the span of the `?` token when generating the macro invocation in
the `#[routeify]` transformation, so that rust-analyzer resolves hover
and go-to-definition on `?` to the `route!` macro's documentation
Diffstat (limited to 'mingling_macros/src/extensions/routeify.rs')
| -rw-r--r-- | mingling_macros/src/extensions/routeify.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mingling_macros/src/extensions/routeify.rs b/mingling_macros/src/extensions/routeify.rs index f011fb9..27077ff 100644 --- a/mingling_macros/src/extensions/routeify.rs +++ b/mingling_macros/src/extensions/routeify.rs @@ -10,8 +10,9 @@ use proc_macro::TokenStream; use quote::ToTokens; +use syn::spanned::Spanned; use syn::visit_mut::VisitMut; -use syn::{Expr, ItemFn, parse_macro_input}; +use syn::{parse_macro_input, Expr, ItemFn}; struct RouteifyTransform; @@ -23,8 +24,14 @@ impl VisitMut for RouteifyTransform { let inner = &*try_expr.expr; let inner_tokens = inner.to_token_stream(); + // Set the span of the generated `route` ident to the `?` token's span, + // so that rust-analyzer resolves the `?` position to the `route!` macro + // instead of the standard Try trait, showing the route macro's docs on hover. + let q_span = try_expr.question_token.span(); + let route_ident = proc_macro2::Ident::new("route", q_span); + if let Ok(macro_expr) = syn::parse2::<Expr>(quote::quote! { - ::mingling::macros::route!(#inner_tokens) + ::mingling::macros::#route_ident!(#inner_tokens) }) { *expr = macro_expr; } |
