clean up
This commit is contained in:
@@ -236,7 +236,10 @@ impl DiagramRenderer for MermaidRenderer {
|
||||
let content = if cross_deps.is_empty() {
|
||||
base
|
||||
} else {
|
||||
let src_id = format!("{}_module", module.as_str().to_lowercase().replace('-', "_"));
|
||||
let src_id = format!(
|
||||
"{}_module",
|
||||
module.as_str().to_lowercase().replace('-', "_")
|
||||
);
|
||||
let mut extra = format!(
|
||||
" class {src_id}[\"{}\"] {{\n <<module>>\n }}\n",
|
||||
module.as_str()
|
||||
@@ -250,7 +253,11 @@ impl DiagramRenderer for MermaidRenderer {
|
||||
" class {dep_id}[\"{}\"] {{\n <<module>>\n }}\n",
|
||||
dep_mod.as_str()
|
||||
));
|
||||
let label = if *count == 1 { "1 dep".to_string() } else { format!("{count} deps") };
|
||||
let label = if *count == 1 {
|
||||
"1 dep".to_string()
|
||||
} else {
|
||||
format!("{count} deps")
|
||||
};
|
||||
extra.push_str(&format!(" {src_id} --> {dep_id} : {label}\n"));
|
||||
}
|
||||
format!("{base}\n{extra}")
|
||||
|
||||
@@ -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,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user