This session focused on three major improvements to the Smart Code Diff tool:
- Adding "Ignore Whitespace" functionality
- Fixing the fundamentally broken AST diff algorithm
- Cleaning up the UI and improving default settings
Users needed the ability to ignore whitespace changes when comparing code, as formatting differences often obscure meaningful changes.
Added a toggle in the diff viewer that allows users to ignore whitespace when comparing lines.
Frontend (BeyondCompareFunctionDiff.tsx):
- Added
ignoreWhitespacestate variable - Added checkbox UI control in diff viewer header
- Passes option to Rust backend API
Backend (crates/web-ui/):
- Added
ignore_whitespace: boolfield toASTDiffOptionsstruct - Updated
compute_lcs_table()to conditionally trim lines - Updated
compute_diff_operations()to respect the flag
Created test_ignore_whitespace.sh which verified:
- ✅ With flag OFF: Whitespace changes detected (1 modified line)
- ✅ With flag ON: Whitespace changes ignored (0 modified lines)
The AST diff was completely broken, showing:
- Duplicate line numbers (same line repeated multiple times)
- Missing lines (most of the actual diff not shown)
- Incorrect mappings (lines matched to wrong counterparts)
- Completely unusable output
The AST diff tried to map only the start_line of each AST node, causing:
- Multiple nodes starting on same line → duplicate mappings
- Multi-line nodes only showing first line → missing lines
- No proper line-by-line correspondence → wrong mappings
Completely rewrote AST diff to use LCS as foundation + AST metadata:
fn generate_ast_aware_line_mappings(...) -> Vec<ASTLineMapping> {
// Step 1: Get reliable LCS line mappings
let base_mappings = generate_lcs_line_mappings(...);
// Step 2: Build AST node lookup by line number
let source_line_to_node = build_lookup(&source_nodes);
let target_line_to_node = build_lookup(&target_nodes);
// Step 3: Enhance LCS mappings with AST information
base_mappings.map(|mapping| {
// Add AST node type if available
// Add semantic change detection
mapping
})
}- ✅ Correct line-by-line mapping (uses proven LCS algorithm)
- ✅ All lines present (no missing content)
- ✅ Still has AST metadata (node types, semantic changes)
- ✅ Faster (removed complex Hungarian matching)
- ✅ Respects ignore_whitespace option
Created test_ast_diff_fix.sh which verified:
- ✅ Both LCS and AST show same line count (4 lines)
- ✅ Sequential line numbers (1, 2, 3, 4) - no duplicates
- ✅ AST version includes node type metadata
- Too many redundant diff viewer components
- Overwhelming default view (all functions shown)
- Poor prioritization (arbitrary order)
- Confusing buttons ("Details" vs "AST Diff")
- ❌
ModernASTDiffViewer.tsx- Old broken AST viewer - ❌
InteractiveDiffViewer.tsx- Unused component - ❌ "AST Diff" buttons - Redundant with unified viewer
-
Filter: Changed from
'all'to'modified'- Only modified functions shown by default
- Reduces noise, focuses on what changed
-
Sorting: Added sort by similarity (most different first)
- Biggest changes appear at top
- Helps prioritize review effort
-
File Filtering: Hide files with no matching functions
- When viewing "Modified", files with only unchanged functions are hidden
- Cleaner, more focused view
-
Button Labels: Changed "AST Diff" to "View Diff"
- Simpler, more intuitive
- Algorithm choice is in the viewer itself
- Removed ~500 lines of redundant code
- Single unified diff viewer
- Clearer architecture
-
nextjs-frontend/src/components/diff/BeyondCompareFunctionDiff.tsx- Added ignore whitespace toggle
- Removed ModernASTDiffViewer integration
- Changed default filter to 'modified'
- Added sorting by similarity
- Added empty file filtering
- Simplified button labels
-
nextjs-frontend/src/app/page.tsx- Removed InteractiveDiffViewer import
-
nextjs-frontend/src/components/ui/Dialog.tsx- Fixed to respect custom width classes
-
crates/web-ui/src/models.rs- Added
ignore_whitespacefield toASTDiffOptions
- Added
-
crates/web-ui/src/handlers.rs- Completely rewrote
generate_ast_aware_line_mappings() - Updated
generate_lcs_line_mappings()to acceptignore_whitespace - Updated
compute_diff_operations()to conditionally trim - Updated
compute_lcs_table()to conditionally trim
- Completely rewrote
nextjs-frontend/src/components/diff/ModernASTDiffViewer.tsxnextjs-frontend/src/components/diff/InteractiveDiffViewer.tsx
IGNORE_WHITESPACE_FEATURE.md- Feature documentationAST_DIFF_FIX.md- Technical explanation of the fixUI_CLEANUP_AND_DEFAULTS.md- UI changes documentationtest_ignore_whitespace.sh- Test scripttest_ast_diff_fix.sh- Test script
- 😵 Overwhelming: All functions shown (including unchanged)
- 🗂️ Cluttered: All files shown even if empty
- 🤔 Confusing: Two diff buttons with unclear difference
- 🎲 Random: Functions in arbitrary order
- 🐛 Broken: AST diff completely unusable
- ⚙️ Limited: No whitespace ignore option
- ✨ Focused: Only modified functions by default
- 🎯 Clean: Only relevant files shown
- 👍 Simple: Single "View Diff" button
- 📊 Smart: Most different changes first
- ✅ Working: AST diff produces correct results
- 🔧 Flexible: Ignore whitespace toggle available
All features tested and verified:
-
✅ Ignore Whitespace
- Backend correctly handles flag
- Frontend toggle works
- Diff refreshes on change
-
✅ AST Diff Fix
- No duplicate line numbers
- All lines present
- Correct mappings
- AST metadata included
-
✅ UI Defaults
- Modified filter active by default
- Functions sorted by difference
- Empty files hidden
- No TypeScript errors
- ✅ Faster AST diff (removed O(n²) Hungarian matching)
- ✅ Less rendering (fewer files/functions shown by default)
- ✅ Smaller bundle (removed unused components)
- LCS algorithm unchanged (still O(n²) but necessary)
- Sorting is O(n log n) on already filtered set
- Empty file filtering is O(n) - negligible
Potential improvements for future sessions:
-
User Preferences
- Save filter/sort settings in localStorage
- Remember last used algorithm choice
-
Advanced Sorting
- UI to toggle sort order
- Sort by file name, function name, complexity
-
Keyboard Navigation
- Shortcuts to jump between functions
- Quick filter toggles
-
Smart Expansion
- Auto-expand files with most changes
- Collapse files with minor changes
-
Diff Presets
- Save common filter/sort combinations
- Quick access to "Review Mode", "Audit Mode", etc.
This session delivered three major improvements that significantly enhance the usability and reliability of the Smart Code Diff tool:
- Ignore Whitespace - Essential feature for practical code review
- Fixed AST Diff - Transformed from broken to functional
- Better Defaults - Focused, prioritized, and streamlined UI
The tool is now production-ready with a clean, intuitive interface and reliable diff algorithms.