Skip to content

Commit 2a688c5

Browse files
committed
Fixing test errors
1 parent 4740ef2 commit 2a688c5

15 files changed

+97
-230
lines changed

crates/parser/src/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ pub enum NodeType {
8181
Unknown,
8282
}
8383

84+
impl std::fmt::Display for NodeType {
85+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86+
write!(f, "{:?}", self)
87+
}
88+
}
89+
8490
/// Metadata associated with an AST node
8591
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8692
pub struct NodeMetadata {

crates/parser/src/ast_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub struct Symbol {
439439
}
440440

441441
/// Types of symbols
442-
#[derive(Debug, Clone, PartialEq)]
442+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
443443
pub enum SymbolType {
444444
Function,
445445
Class,

crates/semantic-analysis/src/analyzer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ pub enum AnalysisError {
3939
AnalysisFailed(String),
4040
}
4141

42+
impl Default for SemanticAnalyzer {
43+
fn default() -> Self {
44+
Self::new()
45+
}
46+
}
47+
4248
impl SemanticAnalyzer {
4349
pub fn new() -> Self {
4450
Self {

crates/semantic-analysis/src/comprehensive_dependency_graph.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl ComprehensiveDependencyGraphBuilder {
239239
) -> Result<FileAnalysisContext> {
240240
let mut context = FileAnalysisContext {
241241
file_path: file_path.to_string(),
242-
language: parse_result.language.clone(),
242+
language: parse_result.language,
243243
functions: Vec::new(),
244244
classes: Vec::new(),
245245
variables: Vec::new(),
@@ -520,6 +520,7 @@ impl ComprehensiveDependencyGraphBuilder {
520520
calls
521521
}
522522

523+
#[allow(clippy::only_used_in_recursion)]
523524
fn collect_function_calls_recursive(&self, node: &ASTNode, calls: &mut Vec<String>) {
524525
if node.node_type == NodeType::CallExpression {
525526
if let Some(function_name) = node.metadata.attributes.get("function_name") {
@@ -538,6 +539,7 @@ impl ComprehensiveDependencyGraphBuilder {
538539
accesses
539540
}
540541

542+
#[allow(clippy::only_used_in_recursion)]
541543
fn collect_variable_accesses_recursive(&self, node: &ASTNode, accesses: &mut Vec<String>) {
542544
if matches!(
543545
node.node_type,
@@ -705,7 +707,7 @@ impl ComprehensiveDependencyGraphBuilder {
705707

706708
/// Create type dependency edges
707709
fn create_type_dependency_edges(&mut self) -> Result<()> {
708-
for (_file_path, type_result) in &self.type_extraction_results {
710+
for type_result in self.type_extraction_results.values() {
709711
for extracted_type in &type_result.types {
710712
let type_name = &extracted_type.type_info.name;
711713

@@ -735,18 +737,17 @@ impl ComprehensiveDependencyGraphBuilder {
735737

736738
// Field type dependencies
737739
for field in &extracted_type.type_info.fields {
738-
if !self.is_primitive_type(&field.type_name) {
739-
if self.node_map.contains_key(type_name)
740-
&& self.node_map.contains_key(&field.type_name)
741-
{
742-
let strength = if field.is_static { 0.6 } else { 0.8 };
743-
let edge = DependencyEdge {
744-
edge_type: DependencyEdgeType::Uses,
745-
strength,
746-
};
747-
self.dependency_graph
748-
.add_edge(type_name, &field.type_name, edge);
749-
}
740+
if !self.is_primitive_type(&field.type_name)
741+
&& self.node_map.contains_key(type_name)
742+
&& self.node_map.contains_key(&field.type_name)
743+
{
744+
let strength = if field.is_static { 0.6 } else { 0.8 };
745+
let edge = DependencyEdge {
746+
edge_type: DependencyEdgeType::Uses,
747+
strength,
748+
};
749+
self.dependency_graph
750+
.add_edge(type_name, &field.type_name, edge);
750751
}
751752
}
752753
}
@@ -1016,15 +1017,11 @@ impl ComprehensiveDependencyGraphBuilder {
10161017
.iter()
10171018
.filter(|dep| {
10181019
// Check if dependency is a variable or field
1019-
if let Some(_context) = self.file_contexts.values().find(|ctx| {
1020+
matches!(self.file_contexts.values().find(|ctx| {
10201021
ctx.variables
10211022
.iter()
1022-
.any(|var| &var.qualified_name == &dep.id)
1023-
}) {
1024-
true
1025-
} else {
1026-
false
1027-
}
1023+
.any(|var| var.qualified_name == dep.id)
1024+
}), Some(_context))
10281025
})
10291026
.count()
10301027
}

crates/semantic-analysis/src/dependency_graph.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ pub enum DependencyEdgeType {
5050
Contains,
5151
}
5252

53+
impl Default for DependencyGraph {
54+
fn default() -> Self {
55+
Self::new()
56+
}
57+
}
58+
5359
impl DependencyGraph {
5460
pub fn new() -> Self {
5561
Self {

crates/semantic-analysis/src/function_signature_extractor.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl FunctionSignatureExtractor {
222222
// Group overloaded functions
223223
overloaded_functions
224224
.entry(signature.name.clone())
225-
.or_insert_with(Vec::new)
225+
.or_default()
226226
.push(signature.clone());
227227
}
228228

@@ -262,7 +262,7 @@ impl FunctionSignatureExtractor {
262262
for (name, overloads) in file_result.overloaded_functions {
263263
overloaded_functions
264264
.entry(name)
265-
.or_insert_with(Vec::new)
265+
.or_default()
266266
.extend(overloads);
267267
}
268268

@@ -449,8 +449,8 @@ impl FunctionSignatureExtractor {
449449

450450
// Check if optional or varargs
451451
let is_optional =
452-
node.metadata.attributes.get("optional").is_some() || default_value.is_some();
453-
let is_varargs = node.metadata.attributes.get("varargs").is_some();
452+
node.metadata.attributes.contains_key("optional") || default_value.is_some();
453+
let is_varargs = node.metadata.attributes.contains_key("varargs");
454454

455455
// Extract annotations
456456
let annotations = self.extract_parameter_annotations(node);
@@ -588,7 +588,7 @@ impl FunctionSignatureExtractor {
588588
match node.node_type {
589589
NodeType::Constructor => FunctionType::Constructor,
590590
NodeType::Method => {
591-
if node.metadata.attributes.get("static").is_some() {
591+
if node.metadata.attributes.contains_key("static") {
592592
FunctionType::StaticMethod
593593
} else if name.starts_with("get") && name.len() > 3 {
594594
FunctionType::Getter
@@ -659,6 +659,8 @@ impl FunctionSignatureExtractor {
659659
}
660660

661661
/// Recursively calculate complexity metrics
662+
#[allow(clippy::too_many_arguments)]
663+
#[allow(clippy::only_used_in_recursion)]
662664
fn calculate_complexity_recursive(
663665
&self,
664666
node: &ASTNode,
@@ -748,6 +750,7 @@ impl FunctionSignatureExtractor {
748750
}
749751

750752
/// Recursively extract function call dependencies
753+
#[allow(clippy::only_used_in_recursion)]
751754
fn extract_dependencies_recursive(&self, node: &ASTNode, dependencies: &mut Vec<String>) {
752755
if node.node_type == NodeType::CallExpression {
753756
if let Some(function_name) = node.metadata.attributes.get("function_name") {
@@ -876,7 +879,7 @@ impl FunctionSignatureExtractor {
876879

877880
class_functions
878881
.entry(class_name)
879-
.or_insert_with(Vec::new)
882+
.or_default()
880883
.push(signature);
881884
}
882885

crates/semantic-analysis/src/scope_manager.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ impl ScopeManager {
245245

246246
/// Analyze scope structure
247247
pub fn analyze_scopes(&self) -> ScopeAnalysis {
248-
let mut analysis = ScopeAnalysis::default();
249-
analysis.total_scopes = self.scopes.len();
248+
let mut analysis = ScopeAnalysis {
249+
total_scopes: self.scopes.len(),
250+
..Default::default()
251+
};
250252

251253
let mut total_symbols = 0;
252254
let mut max_depth = 0;

crates/semantic-analysis/src/symbol_resolver.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl SymbolResolver {
9292
pub fn process_file(&mut self, file_path: &str, parse_result: &ParseResult) -> Result<()> {
9393
let mut file_context = FileContext {
9494
file_path: file_path.to_string(),
95-
language: parse_result.language.clone(),
95+
language: parse_result.language,
9696
imports: Vec::new(),
9797
exports: Vec::new(),
9898
local_scope_stack: Vec::new(),
@@ -138,18 +138,15 @@ impl SymbolResolver {
138138

139139
/// Extract import statements from AST
140140
fn extract_imports(&mut self, node: &ASTNode, file_context: &mut FileContext) -> Result<()> {
141-
match node.node_type {
142-
NodeType::Module => {
143-
// Handle different import patterns based on language
144-
match file_context.language {
145-
Language::Java => self.extract_java_imports(node, file_context)?,
146-
Language::Python => self.extract_python_imports(node, file_context)?,
147-
Language::JavaScript => self.extract_js_imports(node, file_context)?,
148-
Language::Cpp | Language::C => self.extract_c_includes(node, file_context)?,
149-
_ => {}
150-
}
141+
if node.node_type == NodeType::Module {
142+
// Handle different import patterns based on language
143+
match file_context.language {
144+
Language::Java => self.extract_java_imports(node, file_context)?,
145+
Language::Python => self.extract_python_imports(node, file_context)?,
146+
Language::JavaScript => self.extract_js_imports(node, file_context)?,
147+
Language::Cpp | Language::C => self.extract_c_includes(node, file_context)?,
148+
_ => {}
151149
}
152-
_ => {}
153150
}
154151

155152
// Recursively process children
@@ -503,7 +500,6 @@ impl SymbolResolver {
503500
// Try to extract variable name
504501
let var_name = if let Some(eq_pos) = trimmed.find('=') {
505502
trimmed[..eq_pos]
506-
.trim()
507503
.split_whitespace()
508504
.last()
509505
.unwrap_or("unknown")
@@ -539,8 +535,8 @@ impl SymbolResolver {
539535
) -> Result<ImportInfo> {
540536
let trimmed = include_text.trim();
541537

542-
if trimmed.starts_with("#include") {
543-
let include_part = trimmed[8..].trim(); // Skip "#include"
538+
if let Some(stripped) = trimmed.strip_prefix("#include") {
539+
let include_part = stripped.trim();
544540

545541
let (header_name, is_system) =
546542
if include_part.starts_with('<') && include_part.ends_with('>') {

crates/semantic-analysis/src/symbol_table.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ pub enum ReferenceType {
9090
Assignment,
9191
}
9292

93+
impl Default for SymbolTable {
94+
fn default() -> Self {
95+
Self::new()
96+
}
97+
}
98+
9399
impl SymbolTable {
94100
pub fn new() -> Self {
95101
Self {
@@ -139,7 +145,7 @@ impl SymbolTable {
139145
// Add to file symbols
140146
self.file_symbols
141147
.entry(symbol.file_path.clone())
142-
.or_insert_with(HashMap::new)
148+
.or_default()
143149
.insert(name.clone(), symbol.clone());
144150

145151
// Add to global symbols if it's a global symbol

0 commit comments

Comments
 (0)