Skip to content

Commit

Permalink
fix(pilota-build): keep the leading underscore in idl method name (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ggiggle authored Nov 5, 2024
1 parent 34d6fd4 commit 765a699
Show file tree
Hide file tree
Showing 5 changed files with 608 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pilota-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pilota-build"
version = "0.11.22"
version = "0.11.23"
edition = "2021"
description = "Compile thrift and protobuf idl into rust code at compile-time."
documentation = "https://docs.rs/pilota-build"
Expand Down
31 changes: 18 additions & 13 deletions pilota-build/src/parser/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use thrift_parser::Annotations;

use crate::{
index::Idx,
ir,
ir::{Arg, Enum, EnumVariant, FieldKind, File, Item, ItemKind, Path},
ir::{self, Arg, Enum, EnumVariant, FieldKind, File, Item, ItemKind, Path},
symbol::{EnumRepr, FileId, Ident},
tags::{Annotation, PilotaName, RustWrapperArc, Tags},
util::error_abort,
IdentName,
};

#[salsa::query_group(SourceDatabaseStorage)]
Expand Down Expand Up @@ -133,15 +133,16 @@ impl ThriftLower {
.get::<PilotaName>()
.map(|name| name.0.to_string())
.unwrap_or_else(|| func.name.to_string());
let ident = Ident::from(name.clone());
function_names
.entry(name.to_upper_camel_case())
.entry(ident.to_upper_camel_case())
.or_default()
.push(name);
});
let function_name_duplicates = function_names
.iter()
.filter(|(_, v)| v.len() > 1)
.map(|(k, _)| k)
.map(|(k, _)| k.as_str())
.collect::<FxHashSet<_>>();

let kind = ir::ItemKind::Service(ir::Service {
Expand Down Expand Up @@ -188,12 +189,14 @@ impl ThriftLower {
let tags = self.extract_tags(&f.annotations);
let name = tags
.get::<PilotaName>()
.map(|name| name.0.to_string())
.unwrap_or_else(|| f.name.to_string());
let method_name = if function_name_duplicates.contains(&name.to_upper_camel_case()) {
.map(|name| name.0.clone())
.unwrap_or_else(|| FastStr::new(f.name.0.clone()));

let upper_camel_ident = f.name.as_str().upper_camel_ident();
let method_name = if function_name_duplicates.contains(upper_camel_ident.as_str()) {
name
} else {
name.to_upper_camel_case()
upper_camel_ident
};

let name: Ident = format!("{}{}ResultRecv", service_name, method_name).into();
Expand Down Expand Up @@ -292,17 +295,19 @@ impl ThriftLower {
&self,
service_name: &String,
method: &thrift_parser::Function,
function_name_duplicates: &FxHashSet<&String>,
function_name_duplicates: &FxHashSet<&str>,
) -> ir::Method {
let tags = self.extract_tags(&method.annotations);
let name = tags
.get::<PilotaName>()
.map(|name| name.0.to_string())
.unwrap_or_else(|| method.name.to_string());
let method_name = if function_name_duplicates.contains(&name.to_upper_camel_case()) {
.map(|name| name.0.clone())
.unwrap_or_else(|| FastStr::new(method.name.0.clone()));

let upper_camel_ident = method.name.as_str().upper_camel_ident();
let method_name = if function_name_duplicates.contains(upper_camel_ident.as_str()) {
name
} else {
name.to_upper_camel_case()
upper_camel_ident
};

ir::Method {
Expand Down
Loading

0 comments on commit 765a699

Please sign in to comment.