Skip to content

Commit

Permalink
fix: improve rust-analyzer auto-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
pikaju committed Sep 24, 2023
1 parent ae986e7 commit 3a63fd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 11 additions & 4 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,17 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
false
};

parse_macro_input!(s as component::Model)
.is_transparent(is_transparent)
.into_token_stream()
.into()
let parse_result = syn::parse::<component::Model>(s.clone());

match parse_result {
Ok(model) => model
.is_transparent(is_transparent)
.into_token_stream()
.into(),
// Returning the original input stream in the case of a parsing
// error helps IDEs and rust-analyzer with auto-completion.
Err(_) => s,
}
}

/// Defines a component as an interactive island when you are using the
Expand Down
11 changes: 6 additions & 5 deletions leptos_macro/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ pub fn server_impl(
args: proc_macro::TokenStream,
s: TokenStream,
) -> TokenStream {
let function: syn::ItemFn =
match syn::parse(s).map_err(|e| e.to_compile_error()) {
Ok(f) => f,
Err(e) => return e.into(),
};
let function: syn::ItemFn = match syn::parse(s.clone()) {
Ok(f) => f,
// Returning the original input stream in the case of a parsing
// error helps IDEs and rust-analyzer with auto-completion.
Err(_) => return s,
};
let ItemFn {
attrs,
vis,
Expand Down

0 comments on commit 3a63fd5

Please sign in to comment.