Skip to content

Commit e104ddd

Browse files
committed
refactor: standardize explorer action wrapping and fix module requires
- Use wrap_explorer for change_root_to_parent to match other API methods - Fix incorrect require paths in dir-up.lua (remove "lua." prefix) - Remove unused explorer variable in change-dir.lua - Move change_dir assignment in Explorer:new before _load call - Add find_file require to explorer/init.lua for dir_up method
1 parent d9124d7 commit e104ddd

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

.luarc.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
33
"workspace": {
4-
"library": [
5-
"$VIMRUNTIME/lua/vim",
6-
"${3rd}/luv/library"
7-
]
4+
"library": ["$VIMRUNTIME/lua/vim", "${3rd}/luv/library"]
85
},
96
"format": {
107
"defaultConfig": {

lua/nvim-tree/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Api.tree.change_root_to_node = wrap_node(function(node)
170170
end)
171171

172172

173-
Api.tree.change_root_to_parent = wrap_node(Explorer.dir_up)
173+
Api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
174174
Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
175175
Api.tree.get_nodes = wrap_explorer("get_nodes")
176176

lua/nvim-tree/explorer/change-dir.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ end
6666

6767
---@return boolean
6868
local function should_change_dir()
69-
local explorer = core.get_explorer()
7069
return M.options.enable and vim.tbl_isempty(vim.v.event)
7170
end
7271

lua/nvim-tree/explorer/dir-up.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
local utils = require("nvim-tree.utils")
22
local core = require("nvim-tree.core")
3+
local change_dir = require("nvim-tree.explorer.change-dir")
4+
local find_file = require("nvim-tree.actions.finders.find-file")
35

46
local M = {}
57

68
function M.fn(node)
79
if not node or node.name == ".." then
8-
require("lua.nvim-tree.explorer.change-dir").fn("..")
10+
change_dir.fn("..")
911
else
1012
local cwd = core.get_cwd()
1113
if cwd == nil then
1214
return
1315
end
1416

1517
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h")
16-
require("lua.nvim-tree.explorer.change-dir").fn(newdir)
17-
require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
18+
change_dir.fn(newdir)
19+
find_file.fn(node.absolute_path)
1820
end
1921
end
2022

lua/nvim-tree/explorer/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ local Renderer = require("nvim-tree.renderer")
2424
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
2525

2626
local change_dir = require("nvim-tree.explorer.change-dir")
27+
local find_file = require("nvim-tree.actions.finders.find-file")
2728

2829

2930
local config
@@ -70,6 +71,7 @@ function Explorer:new(args)
7071
self.clipboard = Clipboard({ explorer = self })
7172

7273
self:create_autocmds()
74+
self.change_dir = change_dir
7375

7476
self:_load(self)
7577
end
@@ -672,20 +674,18 @@ end
672674
---@param node Node
673675
function Explorer:dir_up(node)
674676
if not node or node.name == ".." then
675-
require("nvim-tree.explorer.change-dir").fn("..")
677+
change_dir.fn("..")
676678
else
677679
local cwd = core.get_cwd()
678680
if cwd == nil then
679681
return
680682
end
681683
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h")
682-
require("nvim-tree.explorer.change-dir").fn(newdir)
683-
require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
684+
change_dir.fn(newdir)
685+
find_file.fn(node.absolute_path)
684686
end
685687
end
686688

687-
Explorer.change_dir = change_dir
688-
689689
function Explorer:setup(opts)
690690
config = opts
691691
change_dir.setup(opts)

lua/nvim-tree/lib.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local view = require("nvim-tree.view")
22
local core = require("nvim-tree.core")
33
local notify = require("nvim-tree.notify")
4+
local change_dir = require("nvim-tree.explorer.change-dir")
45

56
---@class LibOpenOpts
67
---@field path string|nil path
@@ -25,7 +26,7 @@ end
2526
---@param cwd string
2627
local function handle_buf_cwd(cwd)
2728
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
28-
require("lua.nvim-tree.explorer.change-dir").fn(cwd)
29+
change_dir.fn(cwd)
2930
end
3031
end
3132

0 commit comments

Comments
 (0)