Skip to content

Commit 8a0f795

Browse files
committed
refactor: cleanup type annotations and name of human_size function
1 parent 38e8717 commit 8a0f795

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lua/neo-tree/sources/common/commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ M.show_file_details = function (state)
518518
table.insert(right, node.type)
519519
if stat.size then
520520
table.insert(left, "Size")
521-
table.insert(right, utils.filesize(stat.size))
521+
table.insert(right, utils.human_size(stat.size))
522522
table.insert(left, "Created")
523523
table.insert(right, os.date("%Y-%m-%d %I:%M %p", stat.birthtime.sec))
524524
table.insert(left, "Modified")

lua/neo-tree/sources/common/components.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ M.file_size = function (config, node, state)
456456
local stat = utils.get_stat(node)
457457
local size = stat and stat.size or nil
458458
if size then
459-
local success, human = pcall(utils.filesize, size)
459+
local success, human = pcall(utils.human_size, size)
460460
if success then
461461
text = human or text
462462
end

lua/neo-tree/utils/init.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ table.pack = table.pack or function(...)
1818
end
1919
table.unpack = table.unpack or unpack
2020

21-
local M = { filesize = filesize }
21+
local M = {}
2222

2323
local diag_severity_to_string = function(severity)
2424
if severity == vim.diagnostic.severity.ERROR then
@@ -205,6 +205,15 @@ M.find_buffer_by_name = function(name)
205205
return -1
206206
end
207207

208+
---Converts a filesize from libuv.stats into a human readable string with appropriate units.
209+
---@param size any
210+
---@return string
211+
M.human_size = function (size)
212+
local human = filesize(size, { output = "string" })
213+
---@cast human string
214+
return human
215+
end
216+
208217
---Gets diagnostic severity counts for all files
209218
---@return table table { file_path = { Error = int, Warning = int, Information = int, Hint = int, Unknown = int } }
210219
M.get_diagnostic_counts = function()

0 commit comments

Comments
 (0)