Files
nvim-tree.lua/lua/nvim-tree/node/file.lua
Alexander Courtis 8331a24c77 refactor(#2886): multi instance: node group functions refactoring (#2959)
* move last_group_node to DirectoryNode

* move add BaseNode:as and more doc

* revert parameter name changes

* revert parameter name changes

* add Class

* move group methods into DN

* tidy group methods

* tidy group methods

* tidy group methods

* tidy group methods

* parent is DirectoryNode

* tidy expand all

* BaseNode -> Node

* move watcher to DirectoryNode

* last_group_node is DirectoryNode only

* simplify create-file

* simplify parent

* simplify collapse-all

* simplify live-filter

* style
2024-10-20 17:23:22 +11:00

66 lines
1.5 KiB
Lua

local git = require("nvim-tree.git")
local utils = require("nvim-tree.utils")
local Node = require("nvim-tree.node")
---@class (exact) FileNode: Node
---@field extension string
local FileNode = Node:new()
---Static factory method
---@param explorer Explorer
---@param parent DirectoryNode
---@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,
diag_status = nil,
extension = string.match(name, ".?[^.]+%.(.*)") or "",
}
o = self:new(o) --[[@as FileNode]]
return o
end
---Update the GitStatus of the file
---@param parent_ignored boolean
---@param status table|nil
function FileNode:update_git_status(parent_ignored, status)
self.git_status = git.git_status_file(parent_ignored, status, self.absolute_path, nil)
end
---@return GitStatus|nil
function FileNode:get_git_status()
if not self.git_status then
return nil
end
return self.git_status.file and { self.git_status.file }
end
---Create a sanitized partial copy of a node
---@return FileNode cloned
function FileNode:clone()
local clone = Node.clone(self) --[[@as FileNode]]
clone.extension = self.extension
return clone
end
return FileNode