chore: migrate to classic (#2991)
* add classic, migrating nodes classes
* add mixins to classic
* typechecked optargs constructors for nodes
* typechecked optargs constructors for watcher and event
* luacheck
* typechecked optargs constructors for GitRunner
* typechecked optargs constructors for Sorter
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators
* remove class
* replace enums with named maps
* Renderer and Builder use classic, tidy opts
* LiveFilter uses classic, tidy opts
* Filter uses classic, tidy opts
* add FilterTypes named map
* move toggles into filters
* Marks uses classic, tidy opts
* Sorter uses classic, tidy opts
* Clipboard uses classic, tidy opts
* use supers for node methods
* HighlightDisplay uses classic
* protected :new
* Watcher tidy
* Revert "use supers for node methods"
This reverts commit 9fc7a866ec.
* Watcher tidy
* format
* format
* Filters private methods
* format
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* tidy Runner
* tidy hi-test name
This commit is contained in:
committed by
GitHub
parent
610a1c189b
commit
3fc8de198c
@@ -7,38 +7,38 @@ local Watcher = require("nvim-tree.watcher")
|
||||
local M = {}
|
||||
|
||||
---Factory function to create the appropriate Node
|
||||
---@param explorer Explorer
|
||||
---@param parent DirectoryNode
|
||||
---@param absolute_path string
|
||||
---@param stat uv.fs_stat.result? -- on nil stat return nil Node
|
||||
---@param name string
|
||||
---nil on invalid stat or invalid link target stat
|
||||
---@param args NodeArgs
|
||||
---@return Node?
|
||||
function M.create_node(explorer, parent, absolute_path, stat, name)
|
||||
if not stat then
|
||||
function M.create(args)
|
||||
if not args.fs_stat then
|
||||
return nil
|
||||
end
|
||||
|
||||
if stat.type == "directory" then
|
||||
if args.fs_stat.type == "directory" then
|
||||
-- directory must be readable and enumerable
|
||||
if vim.loop.fs_access(absolute_path, "R") and Watcher.is_fs_event_capable(absolute_path) then
|
||||
return DirectoryNode:create(explorer, parent, absolute_path, name, stat)
|
||||
if vim.loop.fs_access(args.absolute_path, "R") and Watcher.is_fs_event_capable(args.absolute_path) then
|
||||
return DirectoryNode(args)
|
||||
end
|
||||
elseif stat.type == "file" then
|
||||
-- any file
|
||||
return FileNode:create(explorer, parent, absolute_path, name, stat)
|
||||
elseif stat.type == "link" then
|
||||
elseif args.fs_stat.type == "file" then
|
||||
return FileNode(args)
|
||||
elseif args.fs_stat.type == "link" then
|
||||
-- link target path and stat must resolve
|
||||
local link_to = vim.loop.fs_realpath(absolute_path)
|
||||
local link_to = vim.loop.fs_realpath(args.absolute_path)
|
||||
local link_to_stat = link_to and vim.loop.fs_stat(link_to)
|
||||
if not link_to or not link_to_stat then
|
||||
return
|
||||
end
|
||||
|
||||
---@cast args LinkNodeArgs
|
||||
args.link_to = link_to
|
||||
args.fs_stat_target = link_to_stat
|
||||
|
||||
-- choose directory or file
|
||||
if link_to_stat.type == "directory" then
|
||||
return DirectoryLinkNode:create(explorer, parent, absolute_path, link_to, name, stat, link_to_stat)
|
||||
return DirectoryLinkNode(args)
|
||||
else
|
||||
return FileLinkNode:create(explorer, parent, absolute_path, link_to, name, stat, link_to_stat)
|
||||
return FileLinkNode(args)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user