mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-24 20:45:56 +03:00
[GH-ISSUE #771] Diff split view: syntax highlighting fails on side with few lines (tree-sitter gets fragmented code) #981
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#981
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rsbmk on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/771
Problem
In split diff view, syntax highlighting often fails on the side that has fewer lines (typically the "old" / removed side), while the other side with more lines highlights correctly.
Root Cause
The
DiffRenderable.buildSplitView()method reconstructs two separate content strings for the left and rightCodeRenderableinstances:Each
CodeRenderableruns tree-sitter independently on its fragment. When one side has very few lines (e.g., 3-4 removed lines), tree-sitter receives incomplete/invalid code like:This isn't valid TSX — there's a closing tag without an opening tag, standalone components without a
returnstatement or function wrapper. Tree-sitter can't parse it correctly, so no syntax tokens are emitted and the text renders unstyled.Meanwhile, the other side might have 30+ lines of complete JSX that tree-sitter can successfully parse.
Expected Behavior
Both sides of a split diff should have correct syntax highlighting, regardless of how many lines each side has.
Suggested Fix
Instead of passing only the diff-visible lines to tree-sitter, the
DiffRenderablecould:This is how editors like VS Code handle diff syntax highlighting — they highlight the full file and then render only the relevant lines in the diff view.
An alternative (simpler but less complete) approach would be to pad the tree-sitter input with additional context beyond what's shown in the diff, to give the parser more syntactic structure to work with.
Environment
<diff>component in Solid.js withview="split",filetype="tsx", and aSyntaxStyle-U3)Reproduction
Any diff where one side has significantly fewer lines than the other, especially when the removed/added code is a small fragment (like closing tags, short component declarations) without enough surrounding structure for tree-sitter to identify the language.