refactor(tasks): improve terminal diff output with context lines#18437
refactor(tasks): improve terminal diff output with context lines#18437graphite-app[bot] merged 1 commit intomainfrom
Conversation
f8ee621 to
0ef3996
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the print_diff_in_terminal function to improve the readability of diff output by adding context lines (like git diff), line numbers with a gutter separator, and gap separators between change hunks. The implementation uses a streaming algorithm with a fixed-size buffer to avoid collecting all lines in memory.
Changes:
- Added context line support showing 3 lines before and after each change
- Added line numbers with
│gutter separator and improved formatting - Implemented streaming algorithm using VecDeque buffer for efficient memory usage
- Added comprehensive documentation with example output
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7bef827 to
92562bd
Compare
|
I really like using AI to improve the debugging experience. |
Merging this PR will not alter performance
Comparing Footnotes
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
I've just remembered I tried to apply https://github.com/mitsuhiko/similar/blob/main/examples/terminal-inline.rs once and forget…🫢 |
Merge activity
|
) ## Summary Improves the `print_diff_in_terminal` function with better readability: - Show 3 lines of context above and below each change - Add line numbers with gutter separator (`│`) - Add blank line between adjacent hunks for visual separation - Add `...` separator when lines are skipped between hunks - Use single-pass streaming algorithm with small fixed-size buffer - Colors: red (`-`) for deletions, green (`+`) for insertions, dim for context Example output: ``` 1 │class A { 2 │ #x; 3 │} - 4 │var _x = /* @__PURE__ */ new WeakMap(); - 5 │var _B_brand = /* @__PURE__ */ new WeakSet(); 4 │class B { - 7 │ constructor() { - 8 │ babelHelpers.classPrivateMethodInitSpec(this, _B_brand); - 9 │ babelHelpers.classPrivateFieldInitSpec(this, _x, void 0); + 5 │ #x; + 6 │ #y() { + 7 │ this.#x; 8 │ } - 11 │} - 12 │function _y() { - 13 │ babelHelpers.classPrivateFieldGet2(_x, this); 9 │} ``` ## Test plan - [x] `cargo check -p oxc_tasks_common` passes - [x] Clippy passes - [x] Verified output with `just test-transform --filter "plugins-integration/class-features-node-12/input.js"` 🤖 Generated with [Claude Code](https://claude.ai/code)
92562bd to
7f070db
Compare
TIL, it looks good too! |
7f070db to
5125f3a
Compare
) ## Summary Improves the `print_diff_in_terminal` function with better readability and a simpler API: **API Changes:** - `print_diff_in_terminal(expected, result)` - Simple API that takes two strings - `print_text_diff(diff)` - For when you already have a `TextDiff` (e.g., to use `diff.ratio()`) **Features:** - Show 3 lines of context above and below each change - Add line numbers with gutter separator (`│`) - Add blank line between adjacent hunks for visual separation - Add `...` separator when lines are skipped between hunks - Use single-pass streaming algorithm with small fixed-size buffer - Colors: red (`-`) for deletions, green (`+`) for insertions, dim for context **Formatter Example:** - Added `--diff` flag to show diff between original and formatted code Example output: ``` 1 │class A { 2 │ #x; 3 │} - 4 │var _x = /* @__PURE__ */ new WeakMap(); - 5 │var _B_brand = /* @__PURE__ */ new WeakSet(); 4 │class B { - 7 │ constructor() { - 8 │ babelHelpers.classPrivateMethodInitSpec(this, _B_brand); - 9 │ babelHelpers.classPrivateFieldInitSpec(this, _x, void 0); + 5 │ #x; + 6 │ #y() { + 7 │ this.#x; 8 │ } - 11 │} - 12 │function _y() { - 13 │ babelHelpers.classPrivateFieldGet2(_x, this); 9 │} ``` ## Test plan - [x] `cargo check -p oxc_tasks_common` passes - [x] Clippy passes - [x] Verified output with `just test-transform --filter "plugins-integration/class-features-node-12/input.js"` 🤖 Generated with [Claude Code](https://claude.ai/code)
5125f3a to
7ba9fa1
Compare

Summary
Improves the
print_diff_in_terminalfunction with better readability and a simpler API:API Changes:
print_diff_in_terminal(expected, result)- Simple API that takes two stringsprint_text_diff(diff)- For when you already have aTextDiff(e.g., to usediff.ratio())Features:
│)...separator when lines are skipped between hunks-) for deletions, green (+) for insertions, dim for contextFormatter Example:
--diffflag to show diff between original and formatted codeExample output:
Test plan
cargo check -p oxc_tasks_commonpassesjust test-transform --filter "plugins-integration/class-features-node-12/input.js"🤖 Generated with Claude Code