How wilfred/difftastic works
Difftastic is a command-line structural diff tool: users provide two files or directories, the program identifies their content and language, parses supported syntax, computes syntax-aware changes, and renders a human-readable or JSON result. It also supports plain-text fallback, merge-conflict inputs, check-only comparisons, and multiple display formats. The graph follows relationships visible in excerpts or documented by the README; where routing to a substantial but unsampled component is documented only indirectly, the graph omits that edge rather than assuming a call.
Main entry points: main.rs CLI entry · hunks.rs Hunk rendering · tree_sitter_parser.rs Tree-sitter parsing · line_parser.rs Text fallback
Components 24
CLI and inputs
- CLI entry
src/main.rs - Options
src/options.rs - File inputs
src/files.rs - Conflict inputs
src/conflicts.rs
Language parsing
- Language detection
src/parse/guess_language.rs - Tree-sitter parsing
src/parse/tree_sitter_parser.rs - Syntax model
src/parse/syntax.rs - Text fallback
src/line_parser.rs - Line positions
src/lines.rs
Diff engine
- Unchanged matching
src/diff/unchanged.rs - Structural graph diff
src/diff/graph.rs - Path search
src/diff/shortest_path.rs - Change metadata
src/diff/changes.rs - Change refinement
src/diff/sliders.rs - Line sequence diff
src/diff/lcs_diff.rs - Word highlighting
src/words.rs
Results and display
- Display context
src/display/context.rs - Hunk rendering
src/display/hunks.rs - Side-by-side output
src/display/side_by_side.rs - Inline output
src/display/inline.rs - JSON output
src/display/json.rs - Terminal styling
src/display/style.rs
Other components
- User
- Diff result
Connections 29
- User → CLI entry: invokes
src/main.rs - CLI entry → Options: parses options
src/main.rs - CLI entry → File inputs: reads files
src/main.rs - CLI entry → Conflict inputs: loads conflicts
src/main.rs - CLI entry → Language detection: detects language
src/main.rs - CLI entry → Tree-sitter parsing: parses syntax
src/main.rs - CLI entry → Text fallback: falls back
src/main.rs - Language detection → Tree-sitter parsing: selects language
src/parse/tree_sitter_parser.rs - Tree-sitter parsing → Syntax model: builds tree
src/parse/tree_sitter_parser.rs - Tree-sitter parsing → Line positions: uses positions
src/parse/tree_sitter_parser.rs - Text fallback → Line sequence diff: aligns lines
src/line_parser.rs - Text fallback → Syntax model: emits matches
src/line_parser.rs - CLI entry → Unchanged matching: finds unchanged
src/main.rs - CLI entry → Path search: computes diff
src/main.rs - Unchanged matching → Change metadata: marks matches
src/diff/unchanged.rs - Unchanged matching → Line sequence diff: aligns nodes
src/diff/unchanged.rs - Path search → Structural graph diff: searches graph
src/diff/shortest_path.rs - Structural graph diff → Change metadata: records changes
src/diff/graph.rs - Structural graph diff → Syntax model: compares nodes
src/diff/graph.rs - CLI entry → Change refinement: refines changes
src/main.rs - CLI entry → Display context: selects context
src/main.rs - CLI entry → Hunk rendering: renders hunks
src/main.rs - Hunk rendering → Display context: uses context
src/display/hunks.rs - Hunk rendering → Side-by-side output: formats columns
src/display/hunks.rs - CLI entry → Inline output: renders inline
- CLI entry → JSON output: renders JSON
- CLI entry → Terminal styling: configures styling
src/main.rs - Hunk rendering → Terminal styling: styles output
- CLI entry → Diff result: writes result