-
-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#2886): multi instance: node class refactoring: extract link…
…s, *_git_status (#2944) * extract DirectoryLinkNode and FileLinkNode, move Node methods to children * temporarily move DirectoryNode methods into BaseNode for easier reviewing * move mostly unchanged DirectoryNode methods back to BaseNode * tidy * git.git_status_file takes an array * update git status of links * luacheck hack
- Loading branch information
1 parent
8859bbb
commit 98ca98c
Showing
9 changed files
with
256 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local git = require("nvim-tree.git") | ||
|
||
local DirectoryNode = require("nvim-tree.node.directory") | ||
|
||
---@class (exact) DirectoryLinkNode: DirectoryNode | ||
---@field link_to string absolute path | ||
---@field fs_stat_target uv.fs_stat.result | ||
local DirectoryLinkNode = DirectoryNode:new() | ||
|
||
---Static factory method | ||
---@param explorer Explorer | ||
---@param parent Node | ||
---@param absolute_path string | ||
---@param link_to string | ||
---@param name string | ||
---@param fs_stat uv.fs_stat.result? | ||
---@param fs_stat_target uv.fs_stat.result | ||
---@return DirectoryLinkNode? nil on vim.loop.fs_realpath failure | ||
function DirectoryLinkNode:create(explorer, parent, absolute_path, link_to, name, fs_stat, fs_stat_target) | ||
-- create DirectoryNode with the target path for the watcher | ||
local o = DirectoryNode:create(explorer, parent, link_to, name, fs_stat) | ||
|
||
o = self:new(o) --[[@as DirectoryLinkNode]] | ||
|
||
-- reset absolute path to the link itself | ||
o.absolute_path = absolute_path | ||
|
||
o.type = "link" | ||
o.link_to = link_to | ||
o.fs_stat_target = fs_stat_target | ||
|
||
return o | ||
end | ||
|
||
-----Update the directory GitStatus of link target and the file status of the link itself | ||
-----@param parent_ignored boolean | ||
-----@param status table|nil | ||
function DirectoryLinkNode:update_git_status(parent_ignored, status) | ||
self.git_status = git.git_status_dir(parent_ignored, status, self.link_to, self.absolute_path) | ||
end | ||
|
||
---Create a sanitized partial copy of a node, populating children recursively. | ||
---@return DirectoryLinkNode cloned | ||
function DirectoryLinkNode:clone() | ||
local clone = DirectoryNode.clone(self) --[[@as DirectoryLinkNode]] | ||
|
||
clone.type = self.type | ||
clone.link_to = self.link_to | ||
clone.fs_stat_target = self.fs_stat_target | ||
|
||
return clone | ||
end | ||
|
||
return DirectoryLinkNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
local git = require("nvim-tree.git") | ||
|
||
local FileNode = require("nvim-tree.node.file") | ||
|
||
---@class (exact) FileLinkNode: FileNode | ||
---@field link_to string absolute path | ||
---@field fs_stat_target uv.fs_stat.result | ||
local FileLinkNode = FileNode:new() | ||
|
||
---Static factory method | ||
---@param explorer Explorer | ||
---@param parent Node | ||
---@param absolute_path string | ||
---@param link_to string | ||
---@param name string | ||
---@param fs_stat uv.fs_stat.result? | ||
---@param fs_stat_target uv.fs_stat.result | ||
---@return FileLinkNode? nil on vim.loop.fs_realpath failure | ||
function FileLinkNode:create(explorer, parent, absolute_path, link_to, name, fs_stat, fs_stat_target) | ||
local o = FileNode:create(explorer, parent, absolute_path, name, fs_stat) | ||
|
||
o = self:new(o) --[[@as FileLinkNode]] | ||
|
||
o.type = "link" | ||
o.link_to = link_to | ||
o.fs_stat_target = fs_stat_target | ||
|
||
return o | ||
end | ||
|
||
-----Update the GitStatus of the target otherwise the link itself | ||
-----@param parent_ignored boolean | ||
-----@param status table|nil | ||
function FileLinkNode:update_git_status(parent_ignored, status) | ||
self.git_status = git.git_status_file(parent_ignored, status, self.link_to, self.absolute_path) | ||
end | ||
|
||
---Create a sanitized partial copy of a node | ||
---@return FileLinkNode cloned | ||
function FileLinkNode:clone() | ||
local clone = FileNode.clone(self) --[[@as FileLinkNode]] | ||
|
||
clone.type = self.type | ||
clone.link_to = self.link_to | ||
clone.fs_stat_target = self.fs_stat_target | ||
|
||
return clone | ||
end | ||
|
||
return FileLinkNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.