Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit22eea90

Browse files
committed
feat(picker.diff): new fancy diff renderer
1 parent41712e3 commit22eea90

File tree

4 files changed

+398
-25
lines changed

4 files changed

+398
-25
lines changed

‎lua/snacks/picker/config/init.lua‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,7 @@ end
112112

113113
--- Fixes old config options
114114
---@paramoptssnacks.picker.Config
115-
functionM.fix_old(opts)
116-
ifopts.previewers.diff.native~=nilthen
117-
opts.previewers.diff.builtin=notopts.previewers.diff.native
118-
end
119-
ifopts.previewers.git.native~=nilthen
120-
opts.previewers.git.builtin=notopts.previewers.git.native
121-
end
122-
end
115+
functionM.fix_old(opts)end
123116

124117
---@paramoptssnacks.picker.Config
125118
functionM.multi(opts)

‎lua/snacks/picker/source/diff.lua‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ local M = {}
55
---@fieldgroup?boolean Group hunks by file
66
---@fielddiff?string|number diff string or buffer number
77

8+
---@classsnacks.picker.diff.hunk.Pos
9+
---@fieldlinenumber
10+
---@fieldcountnumber
11+
12+
---@classsnacks.picker.Diff
13+
---@fieldheaderstring[]
14+
---@fieldblockssnacks.picker.diff.Block[]
15+
816
---@classsnacks.picker.diff.Hunk
917
---@fielddiffstring[]
1018
---@fieldlinenumber
1119
---@fieldcontext?string
12-
---@fieldleft{line:number,count:number}old(normal) /ours(merge)
13-
---@fieldright{line:number,count:number}new(normal) /working(merge)
14-
---@fieldparents?{line:number,count:number}[] theirs(merge)
20+
---@fieldleftsnacks.picker.diff.hunk.Pos old(normal) /ours(merge)
21+
---@fieldrightsnacks.picker.diff.hunk.Pos new(normal) /working(merge)
22+
---@fieldparents?snacks.picker.diff.hunk.Pos[] theirs(merge)
1523

1624
---@classsnacks.picker.diff.Block
1725
---@fieldunmerged?boolean
@@ -80,19 +88,19 @@ function M.diff(opts, ctx)
8088
})
8189
end
8290

83-
localblocks=M.parse(lines)
84-
for_,blockinipairs(blocks)do
85-
localdiff= {}---@typestring[]
91+
localdiff=M.parse(lines)
92+
for_,blockinipairs(diff.blocks)do
93+
localdiffs= {}---@typestring[]
8694
for_,hinipairs(block.hunks)do
8795
ifopts.groupthen
88-
vim.list_extend(diff,h.diff)
96+
vim.list_extend(diffs,h.diff)
8997
else
9098
add(block.file,h.line,vim.list_extend(vim.deepcopy(block.header),h.diff),block)
9199
end
92100
end
93101
ifopts.groupor#block.hunks==0then
94102
localline=block.hunks[1]andblock.hunks[1].lineor1
95-
add(block.file,line,vim.list_extend(vim.deepcopy(block.header),diff),block)
103+
add(block.file,line,vim.list_extend(vim.deepcopy(block.header),diffs),block)
96104
end
97105
end
98106
end
@@ -103,6 +111,7 @@ function M.parse(lines)
103111
localhunk---@typesnacks.picker.diff.Hunk?
104112
localblock---@typesnacks.picker.diff.Block?
105113
localret= {}---@typesnacks.picker.diff.Block[]
114+
localheader= {}---@typestring[]
106115

107116
---@paramfile?string
108117
---@paramstrip_prefix?boolean
@@ -209,12 +218,13 @@ function M.parse(lines)
209218
block=nil
210219
end
211220

212-
localwith_diff_header=vim.trim(table.concat(lines,"\n")):find("^diff")~=nil
221+
localwith_diff_header=false
213222

214223
for_,textinipairs(lines)do
215224
ifnotblockandtext:find("^%s*$")then
216225
-- Ignore empty lines before a diff block
217226
elseiftext:find("^diff")or (notwith_diff_headerandtext:find("^%-%-%-")and (notblockorhunk))then
227+
with_diff_header=with_diff_headerortext:find("^diff")==1
218228
emit()
219229
block= {
220230
file="",--file or "unknown",
@@ -235,12 +245,15 @@ function M.parse(lines)
235245
hunk.diff[#hunk.diff+1]=text
236246
elseifblockthen
237247
block.header[#block.header+1]=text
248+
elseif#ret==0then
249+
header[#header+1]=text
238250
else
239251
Snacks.notify.error("Unexpected line:"..text, {title="Snacks Picker Diff"})
240252
end
241253
end
242254
emit()
243-
returnret
255+
---@typesnacks.picker.Diff
256+
return {blocks=ret,header=header }
244257
end
245258

246259
---@paramlinestring

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp