diff --git a/Cargo.lock b/Cargo.lock index af427499..7cf5df40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -784,7 +784,7 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.11.0" +version = "0.11.1" dependencies = [ "ahash", "anyhow", diff --git a/pilota-build/Cargo.toml b/pilota-build/Cargo.toml index 8d426610..12396f99 100644 --- a/pilota-build/Cargo.toml +++ b/pilota-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota-build" -version = "0.11.0" +version = "0.11.1" edition = "2021" description = "Compile thrift and protobuf idl into rust code at compile-time." documentation = "https://docs.rs/pilota-build" diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 94da4833..bcd1407b 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -338,25 +338,27 @@ where /// get service information for volo-cli init, return path of service and /// methods pub fn get_init_service(&self, def_id: DefId) -> (String, String) { - let service_name = self.rust_name(def_id); - let mod_prefix = self.mod_path(def_id); - let service_path = format!( - "{}::{}", - mod_prefix.iter().map(|item| item.to_string()).join("::"), - service_name - ); - tracing::debug!("service_path: {}", service_path); - let methods = self.service_methods(def_id); - - let methods = methods - .iter() - .map(|m| { - self.backend - .codegen_service_method_with_global_path(def_id, m) - }) - .join("\n"); + CUR_ITEM.set(&def_id, || { + let service_name = self.rust_name(def_id); + let mod_prefix = self.mod_path(def_id); + let service_path = format!( + "{}::{}", + mod_prefix.iter().map(|item| item.to_string()).join("::"), + service_name + ); + tracing::debug!("service_path: {}", service_path); + let methods = self.service_methods(def_id); + + let methods = methods + .iter() + .map(|m| { + self.backend + .codegen_service_method_with_global_path(def_id, m) + }) + .join("\n"); - (service_path, methods) + (service_path, methods) + }) } // pick first service as init service from idlservice @@ -414,7 +416,7 @@ where Self(v) }} }} - + "# }); self.backend.codegen_newtype_impl(def_id, stream, t);