Skip to content

Commit 5d5688e

Browse files
committed
Merge branch 'main' of github.com:opensensor/codediff
2 parents 2f5c2c0 + 408f69a commit 5d5688e

File tree

5 files changed

+56
-71
lines changed

5 files changed

+56
-71
lines changed

crates/cli/src/commands/analyze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use tracing::{info, warn, debug};
1616

1717
pub async fn run(cli: Cli) -> Result<()> {
1818
if let Commands::Analyze {
19-
path,
20-
format,
19+
ref path,
20+
ref format,
2121
recursive,
2222
ref language,
2323
complexity,

crates/cli/src/commands/compare.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@ use smart_diff_engine::{
1313
SimilarityScorer, ChangeClassifier, CrossFileTracker
1414
};
1515
use std::collections::HashMap;
16-
use std::fs;
1716
use std::path::{Path, PathBuf};
1817
use std::time::{Instant, Duration};
1918
use tokio::fs as async_fs;
20-
use tracing::{info, warn, error, debug};
19+
use tracing::{info, warn, debug};
2120

2221
pub async fn run(cli: Cli) -> Result<()> {
2322
if let Commands::Compare {
24-
source,
25-
target,
26-
format,
23+
ref source,
24+
ref target,
25+
ref format,
2726
recursive,
2827
ignore_whitespace,
2928
ignore_case,
3029
threshold,
31-
output,
32-
language,
30+
ref output,
31+
ref language,
3332
detect_refactoring,
3433
track_moves,
3534
show_similarity,
@@ -403,10 +402,10 @@ async fn process_file_pair(
403402
.with_context(|| format!("Failed to analyze target file: {}", target_file.display()))?;
404403

405404
// Initialize diff engine components
406-
let mut diff_engine = DiffEngine::new();
405+
let diff_engine = DiffEngine::new();
407406

408407
// Configure similarity scorer
409-
let mut similarity_scorer = SimilarityScorer::new(detected_language, smart_diff_engine::SimilarityScoringConfig::default());
408+
let similarity_scorer = SimilarityScorer::new(detected_language, smart_diff_engine::SimilarityScoringConfig::default());
410409
if ignore_whitespace {
411410
// Configure to ignore whitespace - would need to add this to SimilarityScorer
412411
debug!("Ignoring whitespace in similarity calculation");
@@ -460,6 +459,8 @@ async fn process_file_pair(
460459
description: "Change detected".to_string(),
461460
alternatives: Vec::new(),
462461
complexity_score: 0.5,
462+
characteristics: Vec::new(),
463+
evidence: Vec::new(),
463464
},
464465
secondary_types: Vec::new(),
465466
similarity_metrics: None,
@@ -544,7 +545,7 @@ fn calculate_function_similarities(
544545
target_symbols: &SymbolTable,
545546
similarity_scorer: &SimilarityScorer,
546547
) -> Result<HashMap<String, f64>> {
547-
let mut similarities = HashMap::new();
548+
let similarities: HashMap<String, f64> = HashMap::new();
548549

549550
// Would need to iterate over functions from symbol table - simplified for now
550551
let similarities = HashMap::new();
@@ -641,7 +642,7 @@ fn display_summary(
641642

642643
let status = if result.diff_result.match_result.changes.is_empty() {
643644
"No changes".green()
644-
} else if result.diff_result.changes.len() < 5 {
645+
} else if result.diff_result.match_result.changes.len() < 5 {
645646
"Minor changes".yellow()
646647
} else {
647648
"Major changes".red()
@@ -650,7 +651,7 @@ fn display_summary(
650651
term.write_line(&format!(" {} - {} ({} changes, {:.1}% similar)",
651652
file_name,
652653
status,
653-
result.diff_result.changes.len(),
654+
result.diff_result.match_result.changes.len(),
654655
result.stats.similarity_score * 100.0
655656
))?;
656657
}
@@ -702,7 +703,7 @@ fn format_duration(duration: Duration) -> String {
702703

703704
/// Extract functions from AST for comparison
704705
fn extract_functions_from_ast(ast: &smart_diff_parser::ASTNode) -> Vec<smart_diff_parser::Function> {
705-
use smart_diff_parser::{Function, FunctionSignature, Parameter, Type, NodeType};
706+
use smart_diff_parser::{Function, FunctionSignature, NodeType};
706707

707708
let mut functions = Vec::new();
708709

@@ -717,7 +718,7 @@ fn extract_functions_from_ast(ast: &smart_diff_parser::ASTNode) -> Vec<smart_dif
717718
let signature = FunctionSignature {
718719
name: name.clone(),
719720
parameters: Vec::new(), // Simplified for now
720-
return_type: smart_diff_parser::Type::Primitive("void".to_string()),
721+
return_type: Some(smart_diff_parser::Type::new("void".to_string())),
721722
modifiers: Vec::new(),
722723
generic_parameters: Vec::new(),
723724
};
@@ -733,7 +734,7 @@ fn extract_functions_from_ast(ast: &smart_diff_parser::ASTNode) -> Vec<smart_dif
733734
end_column: node.metadata.column,
734735
},
735736
dependencies: Vec::new(),
736-
hash: 0, // Simplified for now
737+
hash: "0".to_string(), // Simplified for now
737738
};
738739

739740
functions.push(function);

crates/cli/src/commands/config.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
//! Config command implementation
22
33
use crate::cli::{Cli, Commands, ConfigAction};
4-
use anyhow::{Result, Context, bail};
4+
use anyhow::{Result, bail};
55
use colored::*;
66
use console::Term;
77
use serde::{Deserialize, Serialize};
8-
use smart_diff_engine::RefactoringDetectionConfig;
9-
use std::collections::HashMap;
10-
use std::fs;
11-
use std::path::{Path, PathBuf};
12-
use tracing::{info, warn};
8+
use std::path::PathBuf;
139

1410
/// Application configuration structure
1511
#[derive(Debug, Clone, Serialize, Deserialize)]

crates/cli/src/commands/doctor.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
//! Doctor command implementation for system validation
22
33
use crate::cli::{Cli, Commands};
4-
use anyhow::{Result, Context};
4+
use anyhow::Result;
55
use colored::*;
66
use console::Term;
77
use smart_diff_parser::{tree_sitter::TreeSitterParser, Parser, LanguageDetector, Language};
88
use smart_diff_semantic::SemanticAnalyzer;
99
use smart_diff_engine::{DiffEngine, RefactoringDetector, SimilarityScorer};
10-
use std::collections::HashMap;
11-
use tracing::{info, warn, error};
1210

1311
pub async fn run(cli: Cli) -> Result<()> {
1412
if let Commands::Doctor { component, fix } = cli.command {
@@ -95,22 +93,22 @@ async fn check_parser_system(term: &Term, fix: bool, quiet: bool) -> Result<(usi
9593
}
9694

9795
let mut issues = 0;
98-
let mut fixes = 0;
96+
let fixes = 0;
9997

10098
// Test language detector
10199
let language_detector = LanguageDetector;
102100

103101
// Test basic language detection
104102
let test_cases = vec![
105-
("test.java", Some(Language::Java)),
106-
("test.py", Some(Language::Python)),
107-
("test.js", Some(Language::JavaScript)),
108-
("test.cpp", Some(Language::Cpp)),
109-
("test.c", Some(Language::C)),
103+
("test.java", Language::Java),
104+
("test.py", Language::Python),
105+
("test.js", Language::JavaScript),
106+
("test.cpp", Language::Cpp),
107+
("test.c", Language::C),
110108
];
111109

112110
for (filename, expected) in test_cases {
113-
let detected = language_detector.detect_from_path(std::path::Path::new(filename));
111+
let detected = LanguageDetector::detect_from_path(std::path::Path::new(filename));
114112
if detected != expected {
115113
issues += 1;
116114
if !quiet {
@@ -119,7 +117,7 @@ async fn check_parser_system(term: &Term, fix: bool, quiet: bool) -> Result<(usi
119117
}
120118
} else if !quiet {
121119
term.write_line(&format!(" {} Language detection for {}: {:?}",
122-
"✓".green(), filename, detected.unwrap()))?;
120+
"✓".green(), filename, detected))?;
123121
}
124122
}
125123

@@ -170,7 +168,7 @@ async fn check_semantic_system(term: &Term, fix: bool, quiet: bool) -> Result<(u
170168
}
171169

172170
let mut issues = 0;
173-
let mut fixes = 0;
171+
let fixes = 0;
174172

175173
// Test semantic analyzer creation
176174
let languages = vec![Language::Java, Language::Python, Language::JavaScript, Language::Cpp, Language::C];
@@ -230,12 +228,12 @@ async fn check_diff_engine(term: &Term, fix: bool, quiet: bool) -> Result<(usize
230228
}
231229

232230
let mut issues = 0;
233-
let mut fixes = 0;
231+
let fixes = 0;
234232

235233
// Test diff engine creation
236234
let languages = vec![Language::Java, Language::Python, Language::JavaScript, Language::Cpp, Language::C];
237235

238-
for lang in languages {
236+
for lang in &languages {
239237
match std::panic::catch_unwind(|| DiffEngine::new()) {
240238
Ok(_engine) => {
241239
if !quiet {
@@ -294,8 +292,8 @@ async fn check_language_support(term: &Term, fix: bool, quiet: bool) -> Result<(
294292
term.write_line(&format!("{}", "Checking Language Support...".bold()))?;
295293
}
296294

297-
let mut issues = 0;
298-
let mut fixes = 0;
295+
let issues = 0;
296+
let fixes = 0;
299297

300298
let supported_languages = vec![
301299
(Language::Java, vec!["java"]),
@@ -322,7 +320,7 @@ async fn check_configuration(term: &Term, fix: bool, quiet: bool) -> Result<(usi
322320
}
323321

324322
let mut issues = 0;
325-
let mut fixes = 0;
323+
let fixes = 0;
326324

327325
// Check if we can create default configurations
328326
let config_tests = vec![

crates/cli/src/output.rs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Output formatting utilities
22
33
use crate::cli::OutputFormat;
4-
use anyhow::{Result, Context};
4+
use anyhow::Result;
55
use colored::*;
6-
use serde::{Deserialize, Serialize};
6+
use serde::Serialize;
77
use smart_diff_parser::{Language, ASTNode};
88
use smart_diff_engine::{
99
DiffResult, RefactoringPattern, DetailedChangeClassification, FunctionMove
@@ -167,21 +167,15 @@ impl OutputFormatter {
167167
}
168168

169169
/// Format analysis results as JSON
170-
fn format_analysis_json(results: &[AnalysisResult]) -> Result<String> {
171-
let output = serde_json::json!({
172-
"analysis_results": results,
173-
"format_version": "1.0",
174-
"generated_at": chrono::Utc::now().to_rfc3339()
175-
});
176-
177-
serde_json::to_string_pretty(&output)
178-
.context("Failed to serialize analysis results to JSON")
170+
fn format_analysis_json(_results: &[AnalysisResult]) -> Result<String> {
171+
// JSON serialization disabled due to non-serializable types
172+
Ok("JSON output not yet supported for analysis results".to_string())
179173
}
180174

181175
/// Format analysis results as compact JSON
182-
fn format_analysis_json_compact(results: &[AnalysisResult]) -> Result<String> {
183-
serde_json::to_string(results)
184-
.context("Failed to serialize analysis results to compact JSON")
176+
fn format_analysis_json_compact(_results: &[AnalysisResult]) -> Result<String> {
177+
// JSON serialization disabled due to non-serializable types
178+
Ok("JSON output not yet supported for analysis results".to_string())
185179
}
186180

187181
/// Format analysis results as HTML
@@ -341,6 +335,8 @@ impl OutputFormatter {
341335
smart_diff_parser::ChangeType::Rename => change_desc.blue(),
342336
smart_diff_parser::ChangeType::Move => change_desc.magenta(),
343337
smart_diff_parser::ChangeType::CrossFileMove => change_desc.cyan(),
338+
smart_diff_parser::ChangeType::Split => change_desc.purple(),
339+
smart_diff_parser::ChangeType::Merge => change_desc.purple(),
344340
};
345341
output.push_str(&format!("{}\n", colored_desc));
346342
}
@@ -442,26 +438,16 @@ impl OutputFormatter {
442438

443439
/// Format as JSON
444440
fn format_json(results: &[ComparisonResult], stats: Option<&ComparisonStats>) -> Result<String> {
445-
let output = serde_json::json!({
446-
"results": results,
447-
"stats": stats,
448-
"format_version": "1.0",
449-
"generated_at": chrono::Utc::now().to_rfc3339()
450-
});
451-
452-
serde_json::to_string_pretty(&output)
453-
.context("Failed to serialize results to JSON")
441+
// JSON serialization disabled due to non-serializable types
442+
let _output = "JSON output not yet supported for comparison results";
443+
444+
Ok("JSON output not yet supported for comparison results".to_string())
454445
}
455446

456447
/// Format as compact JSON
457-
fn format_json_compact(results: &[ComparisonResult], stats: Option<&ComparisonStats>) -> Result<String> {
458-
let output = serde_json::json!({
459-
"results": results,
460-
"stats": stats
461-
});
462-
463-
serde_json::to_string(&output)
464-
.context("Failed to serialize results to compact JSON")
448+
fn format_json_compact(_results: &[ComparisonResult], _stats: Option<&ComparisonStats>) -> Result<String> {
449+
// JSON serialization disabled due to non-serializable types
450+
Ok("JSON output not yet supported for comparison results".to_string())
465451
}
466452

467453
/// Format as HTML
@@ -515,6 +501,8 @@ impl OutputFormatter {
515501
smart_diff_parser::ChangeType::Rename => "rename",
516502
smart_diff_parser::ChangeType::Move => "move",
517503
smart_diff_parser::ChangeType::CrossFileMove => "cross-file-move",
504+
smart_diff_parser::ChangeType::Split => "split",
505+
smart_diff_parser::ChangeType::Merge => "merge",
518506
};
519507

520508
html.push_str(&format!(" <li class=\"change-item {}\">\n", class_name));
@@ -696,6 +684,8 @@ impl OutputFormatter {
696684
smart_diff_parser::ChangeType::Rename => "🏷️",
697685
smart_diff_parser::ChangeType::Move => "📦",
698686
smart_diff_parser::ChangeType::CrossFileMove => "🔄",
687+
smart_diff_parser::ChangeType::Split => "🔀",
688+
smart_diff_parser::ChangeType::Merge => "🔗",
699689
};
700690

701691
md.push_str(&format!("{}. {} **{:?}**: {}\n",

0 commit comments

Comments
 (0)