Skip to content

Commit 2557443

Browse files
committed
Improve WEB UI
1 parent 5e62bd7 commit 2557443

File tree

12 files changed

+4139
-1095
lines changed

12 files changed

+4139
-1095
lines changed

crates/web-ui/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ chrono = { version = "0.4", features = ["serde"] }
3535
walkdir = "2.4"
3636
regex = "1.10"
3737
dirs = "5.0"
38+
edit-distance = "2.1"
3839

3940
[dev-dependencies]
4041
tokio = { workspace = true, features = ["test-util"] }

crates/web-ui/src/handlers.rs

Lines changed: 1132 additions & 54 deletions
Large diffs are not rendered by default.

crates/web-ui/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ async fn main() -> Result<()> {
3333
.route("/api/filesystem/home", get(handlers::get_home_directory))
3434
// Directory comparison endpoint
3535
.route("/api/comparison/analyze", post(handlers::compare_directories))
36+
// AST diff endpoint
37+
.route("/api/ast/diff", post(handlers::ast_diff))
3638
// Static files and SPA fallback
3739
.nest_service("/", ServeDir::new("static"))
3840
.fallback(handlers::spa_fallback)

crates/web-ui/src/models.rs

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ pub struct FunctionAnalysis {
118118
#[derive(Debug, Serialize)]
119119
pub struct FunctionMatch {
120120
pub id: String,
121-
pub source_function: FunctionInfo,
121+
pub source_function: Option<FunctionInfo>,
122122
pub target_function: Option<FunctionInfo>,
123123
pub similarity: SimilarityScore,
124-
pub change_type: String,
124+
pub match_type: String,
125125
pub refactoring_pattern: Option<RefactoringPattern>,
126126
}
127127

@@ -135,6 +135,8 @@ pub struct FunctionInfo {
135135
pub complexity: usize,
136136
pub parameters: Vec<String>,
137137
pub return_type: String,
138+
pub content: String,
139+
pub file_path: String,
138140
}
139141

140142
/// Change analysis
@@ -635,3 +637,74 @@ pub struct WatchFilesResponse {
635637
pub paths: Vec<String>,
636638
pub message: String,
637639
}
640+
641+
// AST Diff Models
642+
#[derive(Debug, Serialize, Deserialize)]
643+
pub struct ASTDiffRequest {
644+
pub source_content: String,
645+
pub target_content: String,
646+
pub source_file_path: String,
647+
pub target_file_path: String,
648+
pub language: String,
649+
pub options: ASTDiffOptions,
650+
}
651+
652+
#[derive(Debug, Serialize, Deserialize)]
653+
pub struct ASTDiffOptions {
654+
pub enable_semantic_analysis: bool,
655+
pub enable_structural_analysis: bool,
656+
pub generate_line_mapping: bool,
657+
/// Diff algorithm: "lcs" (fast, line-based) or "ast" (slow, structure-aware)
658+
#[serde(default = "default_diff_algorithm")]
659+
pub diff_algorithm: String,
660+
/// Use Zhang-Shasha tree edit distance for AST comparison
661+
#[serde(default)]
662+
pub use_tree_edit_distance: bool,
663+
/// Use Hungarian algorithm for optimal node matching
664+
#[serde(default)]
665+
pub use_hungarian_matching: bool,
666+
}
667+
668+
fn default_diff_algorithm() -> String {
669+
"lcs".to_string()
670+
}
671+
672+
#[derive(Debug, Serialize, Deserialize)]
673+
pub struct ASTDiffResponse {
674+
pub line_mappings: Vec<ASTLineMapping>,
675+
pub ast_operations: Vec<ASTOperation>,
676+
pub summary: ASTDiffSummary,
677+
}
678+
679+
#[derive(Debug, Serialize, Deserialize)]
680+
pub struct ASTLineMapping {
681+
pub change_type: String, // "unchanged", "added", "deleted", "modified"
682+
pub source_line: Option<usize>,
683+
pub target_line: Option<usize>,
684+
pub source_content: Option<String>,
685+
pub target_content: Option<String>,
686+
pub ast_node_type: Option<String>,
687+
pub similarity: Option<f64>,
688+
pub is_structural_change: bool,
689+
pub semantic_changes: Vec<String>,
690+
}
691+
692+
#[derive(Debug, Serialize, Deserialize)]
693+
pub struct ASTOperation {
694+
pub operation_type: String, // "insert", "delete", "update", "move"
695+
pub node_type: String,
696+
pub position: usize,
697+
pub description: String,
698+
pub impact_level: String, // "low", "medium", "high"
699+
}
700+
701+
#[derive(Debug, Serialize, Deserialize)]
702+
pub struct ASTDiffSummary {
703+
pub total_lines: usize,
704+
pub added_lines: usize,
705+
pub deleted_lines: usize,
706+
pub modified_lines: usize,
707+
pub unchanged_lines: usize,
708+
pub structural_changes: usize,
709+
pub semantic_changes: usize,
710+
}

0 commit comments

Comments
 (0)