diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-06 04:52:50 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-06 04:52:50 +0800 |
| commit | 66a32a8584cf34a881ec45f47d379fb3b1637033 (patch) | |
| tree | 04691c6d604859dc6da3c1634d7dfbfc29019d3d | |
| parent | 4a32781c096f30cb39e16c745076e6b7537929cd (diff) | |
| parent | 2cf0239d3fd738d9e82909c94b41062c4765c375 (diff) | |
Merge pull request #18 from JustEnoughVCS/jvcs_dev
Jvcs dev
| -rw-r--r-- | crates/system_action/action_macros/src/lib.rs | 36 | ||||
| -rw-r--r-- | rust-analyzer.toml | 4 |
2 files changed, 31 insertions, 9 deletions
diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs index 2c2e4a8..5d274ad 100644 --- a/crates/system_action/action_macros/src/lib.rs +++ b/crates/system_action/action_macros/src/lib.rs @@ -30,7 +30,8 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok validate_function_signature(fn_sig); - let (arg_type, return_type) = extract_types(fn_sig); + let (context_param_name, arg_param_name, arg_type, return_type) = + extract_parameters_and_types(fn_sig); let struct_name = quote::format_ident!("{}", convert_to_pascal_case(&fn_name.to_string())); @@ -40,7 +41,7 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok #[derive(Debug, Clone, Default)] #fn_vis struct #struct_name; - impl vcs_service::action::Action<#arg_type, #return_type> for #struct_name { + impl action_system::action::Action<#arg_type, #return_type> for #struct_name { fn action_name() -> &'static str { Box::leak(string_proc::snake_case!(stringify!(#action_name_ident)).into_boxed_str()) } @@ -49,7 +50,7 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok !#_is_local } - async fn process(context: vcs_service::action::ActionContext, args: #arg_type) -> Result<#return_type, tcp_connection::error::TcpTargetError> { + async fn process(#context_param_name: action_system::action::ActionContext, #arg_param_name: #arg_type) -> Result<#return_type, tcp_connection::error::TcpTargetError> { #fn_block } } @@ -57,7 +58,6 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok #[deprecated = "This function is used by #[action_gen] as a template."] #[doc = " This function is used by #[action_gen] as a template to generate the struct. "] #[doc = " It is forbidden to call it anywhere."] - #[doc = " You should use the generated struct to register this function in `ActionPool`"] #[doc = " and call it using the function name."] #fn_vis #fn_sig #fn_block } @@ -109,21 +109,39 @@ fn convert_to_pascal_case(s: &str) -> String { .collect() } -fn extract_types(fn_sig: &syn::Signature) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) { +fn extract_parameters_and_types( + fn_sig: &syn::Signature, +) -> ( + proc_macro2::TokenStream, + proc_macro2::TokenStream, + proc_macro2::TokenStream, + proc_macro2::TokenStream, +) { let mut inputs = fn_sig.inputs.iter(); - let _ = inputs.next(); + let context_param = match inputs.next() { + Some(syn::FnArg::Typed(pat_type)) => { + let pat = &pat_type.pat; + quote::quote!(#pat) + } + _ => { + panic!("Expected the first argument to be a typed parameter, but found something else") + } + }; - let arg_type = match inputs.next() { + let arg_param = match inputs.next() { Some(syn::FnArg::Typed(pat_type)) => { + let pat = &pat_type.pat; let ty = &pat_type.ty; - quote::quote!(#ty) + (quote::quote!(#pat), quote::quote!(#ty)) } _ => { panic!("Expected the second argument to be a typed parameter, but found something else") } }; + let (arg_param_name, arg_type) = arg_param; + let return_type = match &fn_sig.output { syn::ReturnType::Type(_, ty) => { if let syn::Type::Path(type_path) = ty.as_ref() { @@ -145,5 +163,5 @@ fn extract_types(fn_sig: &syn::Signature) -> (proc_macro2::TokenStream, proc_mac _ => panic!("Expected function to have return type, but found none"), }; - (arg_type, return_type) + (context_param, arg_param_name, arg_type, return_type) } diff --git a/rust-analyzer.toml b/rust-analyzer.toml index d108da8..0a09afa 100644 --- a/rust-analyzer.toml +++ b/rust-analyzer.toml @@ -8,6 +8,7 @@ runBuildScripts = true [rust-analyzer] procMacro.enable = true +procMacro.attributes.enable = true diagnostics.disabled = ["unresolved-proc-macro"] @@ -28,6 +29,8 @@ check.extraArgs = ["--all-features"] files.watcher = "client" macroExpansion.mode = "hir" +macroExpansion.maxDepth = 32 +macroExpansion.engines = { hir = true, tt = true } workspace.symbol.search.scope = "workspace" @@ -45,3 +48,4 @@ callInfo.full = true linkedProjects = ["Cargo.toml"] experimental.procAttrMacros = true +experimental.procMacro.server = true |
