Skip to content

refactor(tasks): improve terminal diff output with context lines#18437

Merged
graphite-app[bot] merged 1 commit intomainfrom
refactor/improve-diff-terminal-output
Jan 23, 2026
Merged

refactor(tasks): improve terminal diff output with context lines#18437
graphite-app[bot] merged 1 commit intomainfrom
refactor/improve-diff-terminal-output

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Jan 23, 2026

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

  • cargo check -p oxc_tasks_common passes
  • Clippy passes
  • Verified output with just test-transform --filter "plugins-integration/class-features-node-12/input.js"

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 23, 2026 08:11
@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Jan 23, 2026
@Dunqing Dunqing force-pushed the refactor/improve-diff-terminal-output branch from f8ee621 to 0ef3996 Compare January 23, 2026 08:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Dunqing Dunqing force-pushed the refactor/improve-diff-terminal-output branch 3 times, most recently from 7bef827 to 92562bd Compare January 23, 2026 08:19
@Dunqing Dunqing requested review from Boshen and leaysgur January 23, 2026 08:20
@Dunqing
Copy link
Member Author

Dunqing commented Jan 23, 2026

I really like using AI to improve the debugging experience.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 23, 2026

Merging this PR will not alter performance

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing refactor/improve-diff-terminal-output (92562bd) with main (85ab400)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (b8a371d) during the generation of this report, so 85ab400 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Member Author

Dunqing commented Jan 23, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@leaysgur
Copy link
Member

I've just remembered I tried to apply https://github.com/mitsuhiko/similar/blob/main/examples/terminal-inline.rs once and forget…🫢

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Jan 23, 2026
@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 23, 2026

Merge activity

graphite-app bot pushed a commit that referenced this pull request Jan 23, 2026
)

## 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)
@graphite-app graphite-app bot force-pushed the refactor/improve-diff-terminal-output branch from 92562bd to 7f070db Compare January 23, 2026 08:48
@Dunqing
Copy link
Member Author

Dunqing commented Jan 23, 2026

I've just remembered I tried to apply https://github.com/mitsuhiko/similar/blob/main/examples/terminal-inline.rs once and forget…🫢

TIL, it looks good too!

@Dunqing Dunqing force-pushed the refactor/improve-diff-terminal-output branch from 7f070db to 5125f3a Compare January 23, 2026 08:52
@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler A-formatter Area - Formatter labels Jan 23, 2026
)

## 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)
@graphite-app graphite-app bot force-pushed the refactor/improve-diff-terminal-output branch from 5125f3a to 7ba9fa1 Compare January 23, 2026 08:53
@graphite-app graphite-app bot merged commit 7ba9fa1 into main Jan 23, 2026
22 checks passed
@graphite-app graphite-app bot deleted the refactor/improve-diff-terminal-output branch January 23, 2026 08:59
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants