Skip to content

refactor(#2871, #2886): multi instance: node classes created #2916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
71c519b
refactor(#2875): multi instance renderer
alex-courtis Sep 9, 2024
760b1bc
refactor(#2875): multi instance renderer
alex-courtis Sep 14, 2024
2ce5f69
refactor(#2875): multi instance renderer
alex-courtis Sep 14, 2024
15e65ea
refactor(#2875): multi instance renderer
alex-courtis Sep 15, 2024
646ce63
node classes and constructors
alex-courtis Sep 15, 2024
9193ec9
node methods
alex-courtis Sep 15, 2024
d3946a1
refactor(#2875): multi instance renderer
alex-courtis Sep 16, 2024
69663ff
node classes and constructors
alex-courtis Sep 16, 2024
5ae0a90
explorer is a directory node
alex-courtis Sep 16, 2024
0f222ff
extract methods from explore_node
alex-courtis Sep 16, 2024
f5f58ff
extract methods from explore_node
alex-courtis Sep 16, 2024
d097705
extract methods from explore_node
alex-courtis Sep 16, 2024
16bbe89
extract methods from lib
alex-courtis Sep 16, 2024
91f477d
use .. name for root node for compatibility
alex-courtis Sep 21, 2024
6c274dd
use node.explorer
alex-courtis Sep 21, 2024
739d1e4
extract node factory, remove unused code
alex-courtis Sep 21, 2024
b1d9655
factories for all nodes, add RootNode
alex-courtis Sep 22, 2024
47b1ccb
factories for all nodes, add RootNode
alex-courtis Sep 22, 2024
32431b6
use factory pattern for decorators
alex-courtis Sep 22, 2024
102847d
note regression and commit
alex-courtis Sep 22, 2024
e5d96f0
fix dir git status regression
alex-courtis Sep 23, 2024
abc21e0
destroy nodes, not explorer
alex-courtis Sep 23, 2024
2e1cc1a
add BaseNode:is
alex-courtis Sep 23, 2024
5a863b2
revert changes to create-file, handle in #2924
alex-courtis Sep 23, 2024
bb9df15
extract methods from explorer
alex-courtis Sep 23, 2024
6dd9af7
extract methods from explorer
alex-courtis Sep 23, 2024
448839f
extract methods from explorer
alex-courtis Sep 23, 2024
21ec9e1
use Node everywhere in luadoc
alex-courtis Sep 23, 2024
447efc9
extract methods from lib
alex-courtis Sep 23, 2024
b9704a4
extract methods from lib
alex-courtis Sep 23, 2024
be1d8b8
lint
alex-courtis Sep 29, 2024
9c1c201
remove unused code
alex-courtis Oct 5, 2024
f91975e
don't call methods on fake root node
alex-courtis Oct 6, 2024
fe466d3
get_node_at_cursor returns explorer (root) node instead of { name = '…
alex-courtis Oct 6, 2024
3a55b5d
remove unused inject_node
alex-courtis Oct 6, 2024
7ae7a53
refactor(#2875): multi instance renderer
alex-courtis Sep 14, 2024
a1dff3c
refactor(#2875): multi instance renderer
alex-courtis Sep 15, 2024
98debc7
refactor(#2875): multi instance renderer
alex-courtis Sep 16, 2024
966ef40
extract methods from lib
alex-courtis Sep 30, 2024
56ae381
node factory uses stat only
alex-courtis Sep 30, 2024
43282b8
temporary DirectoryNode casting until method extraction into child cl…
alex-courtis Oct 5, 2024
94ae821
lua-language-server 3.10.5 -> 3.11.0
alex-courtis Oct 7, 2024
a7ae7cc
explicitly call Explorer constructor
alex-courtis Oct 7, 2024
ea994a6
normalise explorer RootNode new call, tidy annotations
alex-courtis Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
strategy:
matrix:
nvim_version: [ stable, nightly ]
luals_version: [ 3.10.5 ]
luals_version: [ 3.11.0 ]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function M.place_cursor_on_node()
if not node or node.name == ".." then
return
end
node = utils.get_parent_of_group(node)
node = node:get_parent_of_group()

local line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(0)
Expand Down Expand Up @@ -849,7 +849,7 @@ function M.setup(conf)
require("nvim-tree.keymap").setup(opts)
require("nvim-tree.appearance").setup()
require("nvim-tree.diagnostics").setup(opts)
require("nvim-tree.explorer").setup(opts)
require("nvim-tree.explorer"):setup(opts)
require("nvim-tree.git").setup(opts)
require("nvim-tree.git.utils").setup(opts)
require("nvim-tree.view").setup(opts)
Expand Down
8 changes: 4 additions & 4 deletions lua/nvim-tree/actions/fs/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ end
---@param action ACTION
---@param action_fn fun(source: string, dest: string)
function Clipboard:do_paste(node, action, action_fn)
node = lib.get_last_group_node(node)
local explorer = core.get_explorer()
if node.name == ".." and explorer then
node = explorer
if node.name == ".." then
node = self.explorer
else
node = node:last_group_node()
end
local clip = self.data[action]
if #clip == 0 then
Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local utils = require("nvim-tree.utils")
local events = require("nvim-tree.events")
local lib = require("nvim-tree.lib")
local core = require("nvim-tree.core")
local notify = require("nvim-tree.notify")

Expand Down Expand Up @@ -40,21 +39,22 @@ local function get_containing_folder(node)
return node.absolute_path:sub(0, -node_name_size - 1)
end

---@param node Node|nil
---@param node Node?
function M.fn(node)
local cwd = core.get_cwd()
if cwd == nil then
return
end

node = node and lib.get_last_group_node(node)
if not node or node.name == ".." then
node = {
absolute_path = cwd,
name = "",
nodes = core.get_explorer().nodes,
open = true,
}
else
node = node:last_group_node()
end

local containing_folder = get_containing_folder(node)
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/fs/rename-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function M.fn(default_modifier)
return
end

node = lib.get_last_group_node(node)
node = node:last_group_node()
if node.name == ".." then
return
end
Expand Down
7 changes: 3 additions & 4 deletions lua/nvim-tree/actions/moves/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local utils = require("nvim-tree.utils")
local view = require("nvim-tree.view")
local core = require("nvim-tree.core")
local lib = require("nvim-tree.lib")
local explorer_node = require("nvim-tree.explorer.node")
local diagnostics = require("nvim-tree.diagnostics")

local M = {}
Expand All @@ -16,7 +15,7 @@ local MAX_DEPTH = 100
---@return boolean
local function status_is_valid(node, what, skip_gitignored)
if what == "git" then
local git_status = explorer_node.get_git_status(node)
local git_status = node:get_git_status()
return git_status ~= nil and (not skip_gitignored or git_status[1] ~= "!!")
elseif what == "diag" then
local diag_status = diagnostics.get_diag_status(node)
Expand Down Expand Up @@ -75,7 +74,7 @@ local function expand_node(node)
if not node.open then
-- Expand the node.
-- Should never collapse since we checked open.
lib.expand_or_collapse(node)
node:expand_or_collapse()
end
end

Expand All @@ -98,7 +97,7 @@ local function move_next_recursive(what, skip_gitignored)
valid = status_is_valid(node_init, what, skip_gitignored)
end
if node_init.nodes ~= nil and valid and not node_init.open then
lib.expand_or_collapse(node_init)
node_init:expand_or_collapse()
end

move("next", what, skip_gitignored)
Expand Down
5 changes: 2 additions & 3 deletions lua/nvim-tree/actions/moves/parent.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local view = require("nvim-tree.view")
local utils = require("nvim-tree.utils")
local core = require("nvim-tree.core")
local lib = require("nvim-tree.lib")

local M = {}

Expand All @@ -12,7 +11,7 @@ function M.fn(should_close)

return function(node)
local explorer = core.get_explorer()
node = lib.get_last_group_node(node)
node = node:last_group_node()
if should_close and node.open then
node.open = false
if explorer then
Expand All @@ -21,7 +20,7 @@ function M.fn(should_close)
return
end

local parent = utils.get_parent_of_group(node).parent
local parent = node:get_parent_of_group().parent

if not parent or not parent.parent then
return view.set_cursor({ 1, 0 })
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/moves/sibling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function M.fn(direction)
local first, last, next, prev = nil, nil, nil, nil
local found = false
local parent = node.parent or core.get_explorer()
Iterator.builder(parent.nodes)
Iterator.builder(parent and parent.nodes or {})
:recursor(function()
return nil
end)
Expand Down
9 changes: 4 additions & 5 deletions lua/nvim-tree/actions/tree/modifiers/expand-all.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local core = require("nvim-tree.core")
local Iterator = require("nvim-tree.iterators.node-iterator")
local notify = require("nvim-tree.notify")
local lib = require("nvim-tree.lib")

local M = {}

Expand All @@ -18,7 +17,7 @@ end

---@param node Node
local function expand(node)
node = lib.get_last_group_node(node)
node = node:last_group_node()
node.open = true
if #node.nodes == 0 then
core.get_explorer():expand(node)
Expand Down Expand Up @@ -62,10 +61,10 @@ local function gen_iterator()
end
end

---@param base_node table
function M.fn(base_node)
---@param node Node
function M.fn(node)
local explorer = core.get_explorer()
local node = base_node.nodes and base_node or explorer
node = node.nodes and node or explorer
if gen_iterator()(node) then
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
end
Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Api.tree.change_root_to_node = wrap_node(function(node)
if node.name == ".." then
actions.root.change_dir.fn("..")
elseif node.nodes ~= nil then
actions.root.change_dir.fn(lib.get_last_group_node(node).absolute_path)
actions.root.change_dir.fn(node:last_group_node().absolute_path)
end
end)

Expand Down Expand Up @@ -198,7 +198,7 @@ Api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basenam
Api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))

---@param mode string
---@param node table
---@param node Node
local function edit(mode, node)
local path = node.absolute_path
if node.link_to and not node.nodes then
Expand All @@ -214,7 +214,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
if node.name == ".." then
actions.root.change_dir.fn("..")
elseif node.nodes then
lib.expand_or_collapse(node, toggle_group)
node:expand_or_collapse(toggle_group)
elseif not toggle_group then
edit(mode, node)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function M.reload_modified()
end
end

---@param node table
---@param node Node
---@return boolean
function M.is_modified(node)
return node
Expand All @@ -32,7 +32,7 @@ function M.is_modified(node)
end

---A buffer exists for the node's absolute path
---@param node table
---@param node Node
---@return boolean
function M.is_opened(node)
return node and vim.fn.bufloaded(node.absolute_path) > 0
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function M.init(foldername)
if TreeExplorer then
TreeExplorer:destroy()
end
TreeExplorer = require("nvim-tree.explorer"):new(foldername)
TreeExplorer = require("nvim-tree.explorer"):create(foldername)
if not first_init_done then
events._dispatch_ready()
first_init_done = true
Expand Down
8 changes: 8 additions & 0 deletions lua/nvim-tree/enum.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
local M = {}

---Must be synced with uv.fs_stat.result as it is compared with it
---@enum (key) NODE_TYPE
M.NODE_TYPE = {
directory = 1,
file = 2,
link = 4,
}

---Setup options for "highlight_*"
---@enum HL_POSITION
M.HL_POSITION = {
Expand Down
Loading
Loading