Files
nvim-tree.lua/lua/nvim-tree/node/file.lua
Alexander Courtis 5ad87620ec fix(#2945): stack overflow on api.git.reload or fugitive event with watchers disabled (#2949)
* Reapply "refactor(#2871, #2886): multi instance: node classes created (#2916)"

This reverts commit 50e919426a.

* fix(#2945): stack overflow on api.git.reload or fugitive event
2024-10-11 13:47:01 +11:00

50 lines
1.1 KiB
Lua

local utils = require("nvim-tree.utils")
local BaseNode = require("nvim-tree.node")
---@class (exact) FileNode: BaseNode
---@field extension string
local FileNode = BaseNode:new()
---Static factory method
---@param explorer Explorer
---@param parent Node
---@param absolute_path string
---@param name string
---@param fs_stat uv.fs_stat.result?
---@return FileNode
function FileNode:create(explorer, parent, absolute_path, name, fs_stat)
---@type FileNode
local o = {
type = "file",
explorer = explorer,
absolute_path = absolute_path,
executable = utils.is_executable(absolute_path),
fs_stat = fs_stat,
git_status = nil,
hidden = false,
is_dot = false,
name = name,
parent = parent,
watcher = nil,
diag_status = nil,
extension = string.match(name, ".?[^.]+%.(.*)") or "",
}
o = self:new(o) --[[@as FileNode]]
return o
end
---Create a sanitized partial copy of a node, populating children recursively.
---@return FileNode cloned
function FileNode:clone()
local clone = BaseNode.clone(self) --[[@as FileNode]]
clone.extension = self.extension
return clone
end
return FileNode