Skip to content

Commit dcd32cd

Browse files
authored
fix(filesystem): fixed call to debounce with wrong arguments (#1227)
1 parent 0f6e7ac commit dcd32cd

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

lua/neo-tree/git/status.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ M.status_async = function(path, base, opts)
237237
end
238238

239239
local job_complete_callback = function()
240-
utils.debounce(event_id, nil, nil, nil, utils.debounce_action.COMPLETE_ASYNC_JOB)
241240
vim.schedule(function()
242241
events.fire_event(events.GIT_STATUS_CHANGED, {
243242
git_root = context.git_root,

lua/neo-tree/sources/filesystem/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local glob = require("neo-tree.sources.filesystem.lib.globtopattern")
1313

1414
local M = {
1515
name = "filesystem",
16-
display_name = " 󰉓 Files "
16+
display_name = " 󰉓 Files ",
1717
}
1818

1919
local wrap = function(func)
@@ -174,7 +174,7 @@ M.navigate = function(state, path, path_to_reveal, callback, async)
174174
log.trace("navigate", path, path_to_reveal, async)
175175
utils.debounce("filesystem_navigate", function()
176176
M._navigate_internal(state, path, path_to_reveal, callback, async)
177-
end, utils.debounce_strategy.CALL_FIRST_AND_LAST, 100)
177+
end, 100, utils.debounce_strategy.CALL_FIRST_AND_LAST)
178178
end
179179

180180
M.reset_search = function(state, refresh, open_current_node)
@@ -423,13 +423,13 @@ M.toggle_directory = function(state, node, path_to_reveal, skip_redraw, recursiv
423423
end
424424

425425
M.prefetcher = {
426-
prefetch = function (state, node)
426+
prefetch = function(state, node)
427427
log.debug("Running fs prefetch for: " .. node:get_id())
428428
fs_scan.get_dir_items_async(state, node:get_id(), true)
429429
end,
430-
should_prefetch = function (node)
430+
should_prefetch = function(node)
431431
return not node.loaded
432-
end
432+
end,
433433
}
434434

435435
return M

lua/neo-tree/utils/init.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ local diag_severity_to_string = function(severity)
3535
end
3636

3737
local tracked_functions = {}
38+
---@enum NeotreeDebounceStrategy
3839
M.debounce_strategy = {
3940
CALL_FIRST_AND_LAST = 0,
4041
CALL_LAST_ONLY = 1,
4142
}
4243

44+
---@enum NeotreeDebounceAction
4345
M.debounce_action = {
4446
START_NORMAL = 0,
4547
START_ASYNC_JOB = 1,
4648
COMPLETE_ASYNC_JOB = 2,
4749
}
4850

49-
local defer_function
50-
-- Part of debounce. Moved out of the function to eliminate memory leaks.
51-
defer_function = function(id, frequency_in_ms, strategy, action)
51+
---Part of debounce. Moved out of the function to eliminate memory leaks.
52+
---@param id string Identifier for the debounce group, such as the function name.
53+
---@param frequency_in_ms number Miniumum amount of time between invocations of fn.
54+
---@param strategy NeotreeDebounceStrategy The debounce_strategy to use, determines which calls to fn are not dropped.
55+
---@param action NeotreeDebounceAction? The debounce_action to use, determines how the function is invoked
56+
local function defer_function(id, frequency_in_ms, strategy, action)
5257
tracked_functions[id].in_debounce_period = true
5358
vim.defer_fn(function()
5459
local current_data = tracked_functions[id]
@@ -72,7 +77,8 @@ end
7277
---@param id string Identifier for the debounce group, such as the function name.
7378
---@param fn function Function to be executed.
7479
---@param frequency_in_ms number Miniumum amount of time between invocations of fn.
75-
---@param strategy number The debounce_strategy to use, determines which calls to fn are not dropped.
80+
---@param strategy NeotreeDebounceStrategy The debounce_strategy to use, determines which calls to fn are not dropped.
81+
---@param action NeotreeDebounceAction? The debounce_action to use, determines how the function is invoked
7682
M.debounce = function(id, fn, frequency_in_ms, strategy, action)
7783
local fn_data = tracked_functions[id]
7884

@@ -119,8 +125,8 @@ M.debounce = function(id, fn, frequency_in_ms, strategy, action)
119125
if type(fn) == "function" then
120126
success, result = pcall(fn)
121127
end
122-
fn_data.fn = nil
123128
fn = nil
129+
fn_data.fn = fn
124130

125131
if not success then
126132
log.error("debounce ", id, " error: ", result)
@@ -208,7 +214,7 @@ end
208214
---Converts a filesize from libuv.stats into a human readable string with appropriate units.
209215
---@param size any
210216
---@return string
211-
M.human_size = function (size)
217+
M.human_size = function(size)
212218
local human = filesize(size, { output = "string" })
213219
---@cast human string
214220
return human
@@ -355,12 +361,12 @@ M.get_inner_win_width = function(winid)
355361
end
356362

357363
local stat_providers = {
358-
default = function (node)
364+
default = function(node)
359365
return vim.loop.fs_stat(node.path)
360366
end,
361367
}
362368

363-
--- Gets the statics for a node in the file system. The `stat` object will be cached
369+
--- Gets the statics for a node in the file system. The `stat` object will be cached
364370
--- for the lifetime of the node.
365371
---
366372
---@param node table The Nui TreeNode node to get the stats for.
@@ -373,7 +379,7 @@ local stat_providers = {
373379
--- @field birthtime StatTime
374380
--- @field mtime StatTime
375381
--- @field size number
376-
M.get_stat = function (node)
382+
M.get_stat = function(node)
377383
if node.stat == nil then
378384
local provider = stat_providers[node.stat_provider or "default"]
379385
local success, stat = pcall(provider, node)
@@ -385,7 +391,7 @@ end
385391
---Register a function to provide stats for a node.
386392
---@param name string The name of the stat provider.
387393
---@param func function The function to call to get the stats.
388-
M.register_stat_provider = function (name, func)
394+
M.register_stat_provider = function(name, func)
389395
stat_providers[name] = func
390396
log.debug("Registered stat provider", name)
391397
end
@@ -632,7 +638,7 @@ end
632638
---@param bufnr number|nil The buffer number to open
633639
M.open_file = function(state, path, open_cmd, bufnr)
634640
open_cmd = open_cmd or "edit"
635-
-- If the file is already open, switch to it.
641+
-- If the file is already open, switch to it.
636642
bufnr = bufnr or M.find_buffer_by_name(path)
637643
if bufnr <= 0 then
638644
bufnr = nil

0 commit comments

Comments
 (0)