Skip to content

Commit 60d37f7

Browse files
committed
chore: Update type annotations
1 parent e91110d commit 60d37f7

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

lua/diffview/debounce.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local M = {}
88
---@field close fun() # Perform cleanup and release the associated handle.
99

1010
---@class ManagedFn : Closeable
11+
---@operator call : unknown ...
1112

1213
---@param ... uv_handle_t
1314
function M.try_close(...)

lua/diffview/renderer.lua

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ M.last_draw_time = 0
1414
---@field first integer 0 indexed, inclusive
1515
---@field last integer Exclusive
1616

17-
---@class renderer.HlList : { [integer]: renderer.HlData }
17+
---@class renderer.HlList
1818
---@field offset integer
19+
---@field [integer] renderer.HlData
1920

20-
---@class CompStruct : { [integer|string]: CompStruct }
21+
---@class CompStruct
2122
---@field _name string
2223
---@field comp RenderComponent
24+
---@field [integer|string] CompStruct
2325

24-
---@class CompSchema : { [integer]: CompSchema }
26+
---@class CompSchema
2527
---@field name? string
2628
---@field context? table
29+
---@field [integer] CompSchema
2730

2831
---@class RenderComponent : diffview.Object
2932
---@field name string
@@ -36,7 +39,6 @@ M.last_draw_time = 0
3639
---@field lstart integer 0 indexed, Inclusive
3740
---@field lend integer Exclusive
3841
---@field height integer
39-
---@field leaf boolean
4042
---@field data_root RenderData
4143
local RenderComponent = oop.create_class("RenderComponent")
4244

@@ -50,7 +52,6 @@ function RenderComponent:init(name)
5052
self.lstart = -1
5153
self.lend = -1
5254
self.height = 0
53-
self.leaf = false
5455
end
5556

5657
---@param parent RenderComponent
@@ -71,8 +72,6 @@ local function create_subcomponents(parent, comp_struct, schema)
7172
comp_struct[v.name] = comp_struct[i]
7273
if #v > 0 then
7374
create_subcomponents(sub_comp, comp_struct[i], v)
74-
else
75-
sub_comp.leaf = true
7675
end
7776
end
7877
end
@@ -199,28 +198,24 @@ function RenderComponent:destroy()
199198
self.components = nil
200199
end
201200

201+
function RenderComponent:isleaf()
202+
return (not next(self.components))
203+
end
204+
202205
---@param line integer
203206
---@return RenderComponent?
204207
function RenderComponent:get_comp_on_line(line)
205208
line = line - 1
209+
local ret
206210

207-
local function recurse(child)
208-
if line >= child.lstart and line < child.lend then
209-
-- print(child.name, line, child.lstart, child.lend)
210-
if #child.components > 0 then
211-
for _, v in ipairs(child.components) do
212-
local target = recurse(v)
213-
if target then
214-
return target
215-
end
216-
end
217-
else
218-
return child
219-
end
211+
self:deep_some(function(child)
212+
if line >= child.lstart and line < child.lend and child:isleaf() then
213+
ret = child
214+
return true
220215
end
221-
end
216+
end)
222217

223-
return recurse(self)
218+
return ret
224219
end
225220

226221
---@param callback fun(comp: RenderComponent, i: integer, parent: RenderComponent): boolean?

lua/diffview/scene/views/diff/render.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ return function(panel)
140140
local conf = config.get_config()
141141
local width = panel:infer_width()
142142

143-
---@type RenderComponent
144143
local comp = panel.components.path.comp
145144

146145
comp:add_line(

lua/diffview/scene/views/file_history/render.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local function render_entries(panel, parent, entries, updating)
8282
end
8383

8484
local entry_struct = parent[i]
85-
local comp = entry_struct.commit.comp --[[@as RenderComponent ]]
85+
local comp = entry_struct.commit.comp
8686

8787
if not entry.single_file then
8888
comp:add_text((entry.folded and c.signs.fold_closed or c.signs.fold_open) .. " ", "CursorLineNr")
@@ -272,14 +272,12 @@ return {
272272

273273
panel.render_data:clear()
274274

275-
---@type RenderComponent
276275
local comp = panel.components.switches.title.comp
277276
local log_options = panel.parent:get_log_options()
278277

279278
comp:add_line("Switches", "DiffviewFilePanelTitle")
280279

281280
for _, item in ipairs(panel.components.switches.items) do
282-
---@type RenderComponent
283281
comp = item.comp
284282
local option = comp.context.option --[[@as FlagOption ]]
285283
local enabled = log_options[option.key] --[[@as boolean ]]
@@ -296,9 +294,7 @@ return {
296294
comp:add_line("Options", "DiffviewFilePanelTitle")
297295

298296
for _, item in ipairs(panel.components.options.items) do
299-
---@type RenderComponent
300297
comp = item.comp
301-
---@type FlagOption
302298
local option = comp.context.option --[[@as FlagOption ]]
303299
local value = log_options[option.key] or ""
304300

0 commit comments

Comments
 (0)