[GH-ISSUE #589] feat: Show parent function/class context in diff hunk headers #160

Closed
opened 2026-03-02 23:44:59 +03:00 by kerem · 0 comments
Owner

Originally created by @remorses on GitHub (Jan 25, 2026).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/589

Similar to GitHub's diff view, it would be helpful to see which function/method/class a diff hunk belongs to. This provides immediate context about where changes are happening.

Example

Current:

  6    return a + b;
  7  }
  8
  9 -  subtract(a, b) {
    +  subtract(a, b, c = 0) {
 10 -    return a - b;
    +    return a - b - c;
 11    }

With parent context:

 @@  class Calculator
  6    return a + b;
  7  }
  8
  9 -  subtract(a, b) {
    +  subtract(a, b, c = 0) {
 10 -    return a - b;
    +    return a - b - c;
 11    }

 @@  multiply(a, b)
 18    return a * b;
 19  }
 20 +
    +  divide(a, b) {
    +    return a / b;
    +  }

The @@ lines would be styled like dimmed context lines, showing the enclosing scope for each hunk.

Implementation idea

Use tree-sitter to query for scope-defining nodes (functions, methods, classes) and find the enclosing scope for each hunk's starting line.

Originally created by @remorses on GitHub (Jan 25, 2026). Original GitHub issue: https://github.com/anomalyco/opentui/issues/589 Similar to GitHub's diff view, it would be helpful to see which function/method/class a diff hunk belongs to. This provides immediate context about where changes are happening. **Example** Current: ``` 6 return a + b; 7 } 8 9 - subtract(a, b) { + subtract(a, b, c = 0) { 10 - return a - b; + return a - b - c; 11 } ``` With parent context: ``` @@ class Calculator 6 return a + b; 7 } 8 9 - subtract(a, b) { + subtract(a, b, c = 0) { 10 - return a - b; + return a - b - c; 11 } @@ multiply(a, b) 18 return a * b; 19 } 20 + + divide(a, b) { + return a / b; + } ``` The `@@` lines would be styled like dimmed context lines, showing the enclosing scope for each hunk. **Implementation idea** Use tree-sitter to query for scope-defining nodes (functions, methods, classes) and find the enclosing scope for each hunk's starting line.
kerem closed this issue 2026-03-02 23:44:59 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#160
No description provided.