From f6113a33f782d1eabd350e3b34ce8de2cec2f8d3 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 20 Jul 2026 04:22:43 +0800 Subject: 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 --- mingling_macros/src/extensions/routeify.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mingling_macros/src/extensions/routeify.rs') 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::(quote::quote! { - ::mingling::macros::route!(#inner_tokens) + ::mingling::macros::#route_ident!(#inner_tokens) }) { *expr = macro_expr; } -- cgit