clean up
Some checks failed
CI / Check / Test (push) Successful in 3m6s
Architecture Docs / Generate diagrams (push) Has been cancelled

This commit is contained in:
2026-06-17 11:28:54 +02:00
parent 0e77ee623a
commit a7e466011b
35 changed files with 174 additions and 2131 deletions

View File

@@ -36,7 +36,8 @@ impl ExtractionContext {
}
pub fn add_relationship(&mut self, rel: Relationship) {
self.relationships.push(rel.with_source_file(self.file_path.clone()));
self.relationships
.push(rel.with_source_file(self.file_path.clone()));
}
pub fn add_warning(&mut self, file_path: FilePath, line: usize, message: &str) {
@@ -51,6 +52,10 @@ impl ExtractionContext {
/// Consumes the context and returns the completed `AnalysisResult`.
pub fn into_result(self) -> Result<AnalysisResult, DomainError> {
Ok(AnalysisResult::new(self.elements, self.relationships, self.warnings))
Ok(AnalysisResult::new(
self.elements,
self.relationships,
self.warnings,
))
}
}

View File

@@ -303,7 +303,12 @@ fn extract_python_params(params_node: &Node, source: &str) -> String {
parts.join(", ")
}
fn collect_constructor_params(body: &Node, source: &str, class_name: &str, ctx: &mut ExtractionContext) {
fn collect_constructor_params(
body: &Node,
source: &str,
class_name: &str,
ctx: &mut ExtractionContext,
) {
let mut cursor = body.walk();
for child in body.children(&mut cursor) {
if child.kind() != "function_definition" {
@@ -342,7 +347,12 @@ fn collect_typed_fields(body: &Node, source: &str, class_name: &str, ctx: &mut E
collect_typed_fields_recursive(body, source, class_name, ctx);
}
fn collect_typed_fields_recursive(node: &Node, source: &str, class_name: &str, ctx: &mut ExtractionContext) {
fn collect_typed_fields_recursive(
node: &Node,
source: &str,
class_name: &str,
ctx: &mut ExtractionContext,
) {
let mut cursor = node.walk();
for child in node.children(&mut cursor) {
if (child.kind() == "assignment" || child.kind() == "typed_assignment")

View File

@@ -1,9 +1,38 @@
use tree_sitter::{Node, Parser};
const RUST_PRIMITIVES: &[&str] = &[
"bool", "char", "str", "String", "u8", "u16", "u32", "u64", "u128", "usize", "i8", "i16",
"i32", "i64", "i128", "isize", "f32", "f64", "Vec", "Option", "Result", "Box", "Rc", "Arc",
"HashMap", "HashSet", "BTreeMap", "BTreeSet", "PhantomData", "Pin", "Cow", "Self",
"bool",
"char",
"str",
"String",
"u8",
"u16",
"u32",
"u64",
"u128",
"usize",
"i8",
"i16",
"i32",
"i64",
"i128",
"isize",
"f32",
"f64",
"Vec",
"Option",
"Result",
"Box",
"Rc",
"Arc",
"HashMap",
"HashSet",
"BTreeMap",
"BTreeSet",
"PhantomData",
"Pin",
"Cow",
"Self",
];
use archlens_domain::{
@@ -143,8 +172,12 @@ fn extract_fields(node: &Node, source: &str) -> Vec<String> {
let mut cursor = body.walk();
for child in body.children(&mut cursor) {
if child.kind() == "field_declaration" {
let name = child.child_by_field_name("name").map(|n| &source[n.byte_range()]);
let ty = child.child_by_field_name("type").map(|n| extract_base_type(&n, source));
let name = child
.child_by_field_name("name")
.map(|n| &source[n.byte_range()]);
let ty = child
.child_by_field_name("type")
.map(|n| extract_base_type(&n, source));
if let (Some(name), Some(ty)) = (name, ty) {
fields.push(format!("{name}: {ty}"));
}
@@ -174,7 +207,11 @@ fn extract_methods(root: &Node, source: &str, type_name: &str) -> Vec<String> {
&& let Some(name_node) = item.child_by_field_name("name")
{
let fn_name = &source[name_node.byte_range()];
let vis = if detect_visibility(&item, source) == Visibility::Public { "+" } else { "-" };
let vis = if detect_visibility(&item, source) == Visibility::Public {
"+"
} else {
"-"
};
let params = extract_fn_params(&item, source);
let ret = extract_fn_return(&item, source);
let sig = if ret.is_empty() {
@@ -258,7 +295,11 @@ fn collect_use_imports(node: &Node, source: &str, ctx: &mut ExtractionContext) {
}
if let Some(arg) = child.child_by_field_name("argument") {
let text = &source[arg.byte_range()];
let path = text.split('{').next().unwrap_or(text).trim_end_matches("::");
let path = text
.split('{')
.next()
.unwrap_or(text)
.trim_end_matches("::");
if (path.starts_with("crate::") || path.starts_with("super::"))
&& let Ok(rel) = Relationship::new(&file_name, path, RelationshipKind::Import)