Skip to content
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

fix: Rust-Analyzer hover information / redundant spans #2836

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions leptos_macro/src/view/component_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ pub(crate) fn component_to_tokens(
})
.unwrap_or_else(|| quote! { #name });

let value = quote_spanned!(value.span()=> { #value });

quote_spanned! {attr.span()=>
.#name(#[allow(unused_braces)] #value)
quote! {
.#name(#[allow(unused_braces)] { #value })
}
});

Expand Down Expand Up @@ -262,30 +260,18 @@ pub(crate) fn component_to_tokens(
quote! {}
};

let name_ref = quote_spanned! {name.span()=>
&#name
};

let build = quote_spanned! {name.span()=>
.build()
};

let component_props_builder = quote_spanned! {name.span()=>
::leptos::component::component_props_builder(#name_ref #generics)
};

#[allow(unused_mut)] // used in debug
let mut component = quote_spanned! {node.span()=>
let mut component = quote! {
{
#[allow(unreachable_code)]
::leptos::component::component_view(
#[allow(clippy::needless_borrows_for_generic_args)]
#name_ref,
#component_props_builder
&#name,
::leptos::component::component_props_builder(&#name #generics)
#(#props)*
#(#slots)*
#children
#build
.build()
)
#spreads
}
Expand Down
10 changes: 2 additions & 8 deletions leptos_macro/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,20 +673,14 @@ pub(crate) fn event_type_and_handler(
let event_type = if is_custom {
event_type
} else if let Some(ev_name) = event_name_ident {
let span = ev_name.span();
quote_spanned! {
span => #ev_name
}
quote! { #ev_name }
} else {
event_type
};

let event_type = if is_force_undelegated {
let undelegated = if let Some(undelegated) = undelegated_ident {
let span = undelegated.span();
quote_spanned! {
span => #undelegated
}
quote! { #undelegated }
} else {
quote! { undelegated }
};
Expand Down
13 changes: 6 additions & 7 deletions leptos_macro/src/view/slot_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ pub(crate) fn slot_to_tokens(
})
.unwrap_or_else(|| quote! { #name });

let value = quote_spanned!(value.span()=> { #value });

quote_spanned! {attr.span()=>
.#name(#[allow(unused_braces)] #value)
quote! {
.#name(#[allow(unused_braces)] { #value })
}
});

Expand Down Expand Up @@ -136,8 +134,9 @@ pub(crate) fn slot_to_tokens(
items_to_bind.iter().map(|ident| quote! { #ident, });

let clonables = items_to_clone.iter().map(|ident| {
let ident_ref = quote_spanned!(ident.span()=> &#ident);
quote! { let #ident = ::core::clone::Clone::clone(#ident_ref); }
quote_spanned! {ident.span()=>
let #ident = ::core::clone::Clone::clone(&#ident);
}
});

if bindables.len() > 0 {
Expand Down Expand Up @@ -169,7 +168,7 @@ pub(crate) fn slot_to_tokens(
.span();
let slot = Ident::new(&slot, span);
let value = if values.len() > 1 {
quote_spanned! {span=>
quote! {
::std::vec![
#(#values)*
]
Expand Down
Loading