Skip to content

Commit 1c4467e

Browse files
committed
wip
1 parent 72bdb6d commit 1c4467e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lua/codecompanion/diff/init.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ local CONSTANTS = {
4242
},
4343
}
4444

45+
---@diagnostic disable-next-line: deprecated
46+
local diff_fn = vim.text.diff or vim.diff
47+
4548
---@alias CodeCompanion.Text [string, string|string[]][]
4649

4750
---@class CC.DiffText
@@ -88,7 +91,7 @@ function M._diff(a, b, opts)
8891
opts = opts or CONSTANTS.DIFF_LINE_OPTS
8992
local txt_a = table.concat(a, "\n")
9093
local txt_b = table.concat(b, "\n")
91-
return vim.text.diff(txt_a, txt_b, opts)
94+
return diff_fn(txt_a, txt_b, opts)
9295
end
9396

9497
---Check if any hunk starts at row 0 and has deletions. This causes a problem
@@ -164,12 +167,10 @@ function M._diff_lines(diff)
164167
end
165168

166169
for row, data in pairs(adds) do
167-
-- Add word-level highlighting for "change" hunks FIRST with higher priority
168170
if data.hunk.kind == "change" then
169171
M._diff_words(diff, row, data)
170172
end
171173

172-
-- Add line background spanning to next row with lower priority
173174
table.insert(data.hunk.extmarks, {
174175
row = row,
175176
col = 0,
@@ -210,10 +211,10 @@ function M._diff_words(diff, row, data)
210211
"\n"
211212
)
212213

213-
local word_hunks = vim.text.diff(old_text, new_text, CONSTANTS.DIFF_WORD_OPTS)
214+
local hunks = diff_fn(old_text, new_text, CONSTANTS.DIFF_WORD_OPTS)
214215

215-
for _, word_hunk in ipairs(word_hunks) do
216-
local _, _, bi, bc = unpack(word_hunk)
216+
for _, hunk in ipairs(hunks) do
217+
local _, _, bi, bc = unpack(hunk)
217218

218219
-- Only highlight additions/changes in the new line
219220
if bc > 0 then

0 commit comments

Comments
 (0)