Skip to content

Commit

Permalink
Add item type to a generated file name
Browse files Browse the repository at this point in the history
  • Loading branch information
missingdays committed Sep 24, 2024
1 parent ac46231 commit 8d48113
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
20 changes: 17 additions & 3 deletions pilota-build/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use traits::CodegenBackend;

use self::workspace::Workspace;
use crate::rir::{Item, NodeKind};
use crate::{
db::RirDatabase,
dedup::def_id_equal,
Expand Down Expand Up @@ -481,7 +482,21 @@ where
if this.split {
let mut item_stream = String::new();
let node = this.db.node(def_id.def_id).unwrap();
let file_name = format!("{}.rs", node.name());
let name_prefix = match node.kind {
NodeKind::Item(ref item) => match item.as_ref() {
Item::Message(_) => "message",
Item::Enum(_) => "enum",
Item::Service(_) => "service",
Item::NewType(_) => "new_type",
Item::Const(_) => "const",
Item::Mod(_) => "mod",
},
NodeKind::Variant(_) => "variant",
NodeKind::Field(_) => "field",
NodeKind::Method(_) => "method",
NodeKind::Arg(_) => "arg",
};
let file_name = format!("{}_{}.rs", name_prefix, node.name());
this.write_item(&mut item_stream, *def_id, &mut dup);

let full_path = base_dir.join(file_name.clone());
Expand All @@ -495,8 +510,7 @@ where
let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap();

stream.push_str(
format!("\ninclude!(\"{}/{}\");\n", base_dir_local_path, file_name)
.as_str(),
format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(),
);
} else {
this.write_item(&mut stream, *def_id, &mut dup)
Expand Down
21 changes: 7 additions & 14 deletions pilota-build/test_data/thrift_with_split/wrapper_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ pub mod wrapper_arc {
#![allow(warnings, clippy::all)]

pub mod wrapper_arc {

include!("wrapper_arc/A.rs");

include!("wrapper_arc/TestService.rs");

include!("wrapper_arc/TestServiceTestResultRecv.rs");

include!("wrapper_arc/TestServiceTestArgsRecv.rs");

include!("wrapper_arc/TestServiceTestResultSend.rs");

include!("wrapper_arc/TEST.rs");

include!("wrapper_arc/TestServiceTestArgsSend.rs");
include!("wrapper_arc/message_A.rs");
include!("wrapper_arc/service_TestService.rs");
include!("wrapper_arc/enum_TestServiceTestResultRecv.rs");
include!("wrapper_arc/message_TestServiceTestArgsRecv.rs");
include!("wrapper_arc/enum_TestServiceTestResultSend.rs");
include!("wrapper_arc/message_TEST.rs");
include!("wrapper_arc/message_TestServiceTestArgsSend.rs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl ::pilota::thrift::Message for Test {
) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> {
#[allow(unused_imports)]
use ::pilota::thrift::TOutputProtocolExt;
let struct_ident = ::pilota::thrift::TStructIdentifier { name: "TEST" };
let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Test" };

__protocol.write_struct_begin(&struct_ident)?;
__protocol.write_faststr_field(1, (&self.id).clone())?;
Expand Down Expand Up @@ -150,7 +150,7 @@ impl ::pilota::thrift::Message for Test {
})() {
if let Some(field_id) = __pilota_decoding_field_id {
err.prepend_msg(&format!(
"decode struct `TEST` field(#{}) failed, caused by: ",
"decode struct `Test` field(#{}) failed, caused by: ",
field_id
));
}
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ::pilota::thrift::Message for Test {
{
if let Some(field_id) = __pilota_decoding_field_id {
err.prepend_msg(&format!(
"decode struct `TEST` field(#{}) failed, caused by: ",
"decode struct `Test` field(#{}) failed, caused by: ",
field_id
));
}
Expand Down Expand Up @@ -315,7 +315,7 @@ impl ::pilota::thrift::Message for Test {
fn size<T: ::pilota::thrift::TLengthProtocol>(&self, __protocol: &mut T) -> usize {
#[allow(unused_imports)]
use ::pilota::thrift::TLengthProtocolExt;
__protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "TEST" })
__protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Test" })
+ __protocol.faststr_field_len(Some(1), &self.id)
+ __protocol.list_field_len(
Some(2),
Expand Down

0 comments on commit 8d48113

Please sign in to comment.