Fix rust connection for graph

This commit is contained in:
2025-11-14 18:30:56 +00:00
parent 304227c5f3
commit a37516c530
2 changed files with 79 additions and 15 deletions
+32 -11
View File
@@ -4,8 +4,8 @@ use std::env;
use std::fs;
use std::process;
use syn::{
spanned::Spanned, FnArg, Item, ItemEnum, ItemFn, ItemImpl, ItemMod, ItemStruct, ItemTrait, Pat,
Type, Visibility,
spanned::Spanned, FnArg, Item, ItemEnum, ItemFn, ItemImpl, ItemMod, ItemStruct, ItemTrait,
ItemUse, Pat, Type, Visibility,
};
#[derive(Serialize)]
@@ -88,6 +88,27 @@ fn main() {
}
}
for item in &syntax.items {
if let Item::Use(item_use) = item {
let path = path_to_string(&item_use.tree);
decls.push(RustDecl {
name: path.clone(),
type_: "import".to_string(),
start_line: 0,
end_line: 0,
visibility: "".to_string(),
is_async: false,
is_unsafe: false,
generics: vec![],
traits: vec![],
fields: vec![],
methods: vec![],
return_type: None,
parameters: vec![path],
});
}
}
let output = serde_json::to_string(&decls).unwrap_or_else(|_| "[]".to_string());
println!("{}", output);
}
@@ -106,13 +127,13 @@ fn parse_function(item_fn: &ItemFn) -> Option<RustDecl> {
let mut parameters = Vec::new();
for input in &item_fn.sig.inputs {
if let FnArg::Typed(pat_type) = input {
// pat_type.pat is Box<Pat>
if let Pat::Ident(pat_ident) = &*pat_type.pat {
parameters.push(pat_ident.ident.to_string());
let name = if let Pat::Ident(pat_ident) = &*pat_type.pat {
pat_ident.ident.to_string()
} else {
// fallback: try to stringify the pattern
parameters.push(format!("{}", quote::ToTokens::to_token_stream(&pat_type.pat)));
}
format!("{}", quote::ToTokens::to_token_stream(&pat_type.pat))
};
let ty = type_to_string(&*pat_type.ty);
parameters.push(format!("{}: {}", name, ty));
} else if let FnArg::Receiver(_) = input {
parameters.push("self".to_string());
}
@@ -263,12 +284,12 @@ fn parse_impl(item_impl: &ItemImpl) -> Option<RustDecl> {
.collect();
// If this impl implements a trait, extract its path
let traits: Vec<String> = item_impl
let implements = item_impl
.trait_
.as_ref()
.map(|(_, path, _)| path_to_string(path))
.into_iter()
.collect();
.collect::<Vec<_>>();
Some(RustDecl {
name: format!("impl_{}", target),
@@ -284,7 +305,7 @@ fn parse_impl(item_impl: &ItemImpl) -> Option<RustDecl> {
.iter()
.map(generic_param_to_string)
.collect(),
traits,
traits: implements.clone(),
fields: Vec::new(),
methods,
return_type: None,