Skip to content

Commit 0c1b440

Browse files
committed
feat: support tonic::include_proto! and prost::include_proto! macros
Recognize tonic::include_proto! and prost::include_proto! in visit_item_macro, mapping them to OUT_DIR/pkg.rs for indexing. This lets rspeek find types generated by protobuf/gRPC codegen.
1 parent 0862471 commit 0c1b440

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/index.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,14 @@ fn doc_start(attrs: &[syn::Attribute], item_start: usize) -> usize {
505505
.unwrap_or(item_start)
506506
}
507507

508+
/// Check if a macro path is `include_proto`, `tonic::include_proto`, or `prost::include_proto`.
509+
fn is_include_proto(path: &syn::Path) -> bool {
510+
let segs: Vec<_> = path.segments.iter().map(|s| s.ident.to_string()).collect();
511+
segs == ["include_proto"]
512+
|| segs == ["tonic", "include_proto"]
513+
|| segs == ["prost", "include_proto"]
514+
}
515+
508516
impl<'ast> Visit<'ast> for ItemVisitor<'_> {
509517
fn visit_item_struct(&mut self, node: &'ast syn::ItemStruct) {
510518
let start = doc_start(&node.attrs, node.span().start().line);
@@ -623,6 +631,18 @@ impl<'ast> Visit<'ast> for ItemVisitor<'_> {
623631
}
624632
}
625633
}
634+
// Handle tonic::include_proto!("package.name") → OUT_DIR/package.name.rs
635+
if is_include_proto(&node.mac.path) {
636+
if let Some(out_dir) = &self.out_dir {
637+
if let Ok(lit) = syn::parse2::<syn::LitStr>(node.mac.tokens.clone()) {
638+
let path = out_dir.join(format!("{}.rs", lit.value()));
639+
if path.exists() {
640+
self.included_files.push((path, self.module_path.clone()));
641+
return;
642+
}
643+
}
644+
}
645+
}
626646
// Try to parse the macro body as Rust items.
627647
// Handles patterns like: ast_struct! { pub struct Foo { ... } }
628648
let tokens = node.mac.tokens.clone();

0 commit comments

Comments
 (0)