Skip to content

feat(conflict): detect and resolve inline merge conflict markers#96

Open
barrettruth wants to merge 6 commits intomainfrom
feat/conflict
Open

feat(conflict): detect and resolve inline merge conflict markers#96
barrettruth wants to merge 6 commits intomainfrom
feat/conflict

Conversation

@barrettruth
Copy link
Owner

Problem

When git hits a merge conflict, users stare at raw <<<<<<</=======/>>>>>>> markers with broken treesitter and noisy LSP diagnostics. Existing solutions like git-conflict.nvim use their own highlighting rather than integrating with diffs.nvim's color blending pipeline.

Solution

Add a conflict.lua module that detects inline merge conflict markers and provides a native resolution experience. Supports both standard and diff3 (|||||||) formats.

Highlights ours/theirs/base regions with blended DiffsConflict* highlight groups derived from DiffAdd/DiffChange/DiffText backgrounds, matching the existing color pipeline. Provides resolution keymaps (doo/dot/dob/don) and navigation (]x/[x), all configurable or individually disableable. Suppresses LSP diagnostics while markers are present and re-enables them on resolution. Fires a DiffsConflictResolved user event when the last conflict in a buffer is resolved.

Detection runs on BufReadPost and re-scans on TextChanged. The entire feature is behind conflict.enabled (default true) and adds no overhead to buffers without markers.

Problem: when git hits a merge conflict, users stare at raw <<<<<<<
markers with broken treesitter and noisy LSP diagnostics. Existing
solutions (git-conflict.nvim) use their own highlighting rather than
integrating with diffs.nvim's color blending pipeline.

Solution: add conflict.lua module that detects <<<<<<</=======/>>>>>>>
markers (with diff3 ||||||| support), highlights ours/theirs/base
regions with blended DiffsConflict* highlight groups, provides
resolution keymaps (doo/dot/dob/don) and navigation (]x/[x),
suppresses diagnostics while markers are present, and auto-detaches
when all conflicts are resolved. Fires DiffsConflictResolved user
event on last resolution.
Problem: lua-language-server reports duplicate @Class definitions for
ConflictKeymaps and ConflictConfig (defined in both init.lua and
conflict.lua), and inject-field errors for the untyped parser table.

Solution: remove duplicate @Class annotations from conflict.lua
(init.lua is the canonical source), and annotate the parser's current
variable as diffs.ConflictRegion? so LuaLS knows its shape.
Problem: LuaLS reports missing-fields errors because the parser builds
ConflictRegion tables incrementally, but the variable is typed as
diffs.ConflictRegion? which expects all required fields at construction.

Solution: type the work-in-progress variable as table? and cast to
diffs.ConflictRegion on insertion into the results array.
Problem: virtual text showed generic "current"/"incoming" labels with
no indication of which branch each side came from.

Solution: extract the branch name from the marker line itself
(e.g. <<<<<<< HEAD, >>>>>>> feature) and display as
"HEAD (current)" / "feature (incoming)".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant