feat: add treesitter syntax highlighting and word-level diff to split view - #22
Open
KEY60228 wants to merge 2 commits into
Open
feat: add treesitter syntax highlighting and word-level diff to split view#22KEY60228 wants to merge 2 commits into
KEY60228 wants to merge 2 commits into
Conversation
… view - Strip the "+"/"-"/" " prefix from rendered diff lines so buffers contain pure code; add/remove state is already conveyed by line highlights and colored inline line numbers - Attach a treesitter highlighter per file via vim.filetype.match + vim.treesitter.start, guarded with pcall so it degrades silently when no parser is installed (zero-dependency), and stopped before re-rendering a different file - Highlight the changed span within positionally paired remove/add lines (common prefix/suffix scan, UTF-8 boundary safe) using new ReviewThemWordAdd / ReviewThemWordDelete groups linked to DiffText - Add word_diff config option (default true) to disable word-level highlighting; document it in README and :help Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The word diff extmark used priority 110 to sit above treesitter highlights (100), but the add/remove line highlight it competes with is a `line_hl_group` extmark. Neovim ignores `priority` for `line_hl_group` and lets it hide any `hl_group` extmark on the same line, so the changed span was never visible: every line it targets is an add or remove line. - Paint the add/remove line background as a character range spanning the EOL with `hl_eol` instead of `line_hl_group`, at priority 90. Priorities now order as intended: line background (90) below treesitter (100) below the word diff span (200), so syntax foreground colors and the changed span are both visible. - Skip word-level highlighting when the changed span covers more than 60% of both sides. Remove/add lines are paired by position within a hunk, so an unrelated pair would otherwise be highlighted almost end to end, which is noise on top of the line highlight. - Stop the outgoing treesitter highlighter before replacing buffer content rather than after, so it does not parse lines it is about to lose. - Initialize config options from the defaults so they are populated when setup() was never called. - Note in README and :help that the diff buffer holds hunks rather than whole files, so treesitter highlighting can be imperfect. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AwFzEL9QFsBdzj97JD8HRz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
+/-/prefix from rendered diff lines so the split buffers contain pure code — the add/remove state is already conveyed by the line highlights and the colored inline line numbersvim.filetype.match+vim.treesitter.language.get_lang) and the highlighter is attached withpcall(vim.treesitter.start, ...), falling back silently to no highlighting when no parser is installed (keeps the plugin zero-dependency); the highlighter is stopped before re-rendering a different file to avoid stale parsersReviewThemWordAdd/ReviewThemWordDeletegroups (linked toDiffText, theme-friendly)word_diff = trueconfig option to disable word-level highlighting; documented in README and:help reviewthem-configurationImplementation notes
build_split_content()and carried through the line map (entry.word_diff = {start_col, end_col}), then applied ashl_groupextmarks withend_colinapply_split_decorations()(priority 110, above treesitter's 100)line_hl_grouponly contributes the backgroundTest plan
nvim --headless -c "set rtp+=." -c "lua require('reviewthem').setup()" -c "q"nvim --headless -l): fed a fakeDiffFilethroughrender_fileand asserted prefix-free buffer lines, empty padding lines, expected word diff spans (including ahéllo→hállocase verifying spans don't split multibyte chars), no span on unpaired removes, active treesitter highlighter on both buffers, working cursor context, and thatword_diff = falseremoves the marks🤖 Generated with Claude Code