Skip to content

Commit ce6856f

Browse files
authored
Merge branch 'master' into fix-windows-path
2 parents 8d26f40 + bd48816 commit ce6856f

File tree

16 files changed

+311
-144
lines changed

16 files changed

+311
-144
lines changed

doc/nvim-tree-lua.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,18 @@ Takes the `BufEnter` event as an argument. see |autocmd-events|
11981198

11991199
Open a file or directory in your preferred application.
12001200

1201+
|vim.ui.open| was introduced in neovim 0.10 and is the default.
1202+
1203+
Once nvim-tree minimum neovim version is updated to 0.10, these options will
1204+
no longer be necessary and will be removed.
1205+
12011206
*nvim-tree.system_open.cmd*
12021207
The open command itself.
12031208
Type: `string`, Default: `""`
12041209

1205-
Leave empty for OS specific default:
1210+
neovim >= 0.10 defaults to |vim.ui.open|
1211+
1212+
neovim < 0.10 defaults to:
12061213
UNIX: `"xdg-open"`
12071214
macOS: `"open"`
12081215
Windows: `"cmd"`
@@ -1569,7 +1576,7 @@ Specify minimum notification level, uses the values from |vim.log.levels|
15691576
`ERROR`: hard errors e.g. failure to read from the file system.
15701577
`WARNING`: non-fatal errors e.g. unable to system open a file.
15711578
`INFO:` information only e.g. file copy path confirmation.
1572-
`DEBUG:` not used.
1579+
`DEBUG:` information for troubleshooting, e.g. failures in some window closing operations.
15731580

15741581
*nvim-tree.notify.absolute_path*
15751582
Whether to use absolute paths or item names in fs action notifications.

lua/nvim-tree.lua

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ local function setup_autocommands(opts)
201201
create_nvim_tree_autocmd("BufWritePost", {
202202
callback = function()
203203
if opts.auto_reload_on_write and not opts.filesystem_watchers.enable then
204-
actions.reloaders.reload_explorer()
204+
local explorer = core.get_explorer()
205+
if explorer then
206+
explorer:reload_explorer()
207+
end
205208
end
206209
end,
207210
})
@@ -217,7 +220,7 @@ local function setup_autocommands(opts)
217220
(explorer.filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == ""
218221
then
219222
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
220-
actions.reloaders.reload_explorer()
223+
explorer:reload_explorer()
221224
end)
222225
end
223226
end,
@@ -234,7 +237,7 @@ local function setup_autocommands(opts)
234237
(explorer.filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == ""
235238
then
236239
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
237-
actions.reloaders.reload_explorer()
240+
explorer:reload_explorer()
238241
end)
239242
end
240243
end,
@@ -244,7 +247,10 @@ local function setup_autocommands(opts)
244247
pattern = { "FugitiveChanged", "NeogitStatusRefreshed" },
245248
callback = function()
246249
if not opts.filesystem_watchers.enable and opts.git.enable then
247-
actions.reloaders.reload_git()
250+
local explorer = core.get_explorer()
251+
if explorer then
252+
explorer:reload_git()
253+
end
248254
end
249255
end,
250256
})
@@ -292,7 +298,10 @@ local function setup_autocommands(opts)
292298
callback = function()
293299
if utils.is_nvim_tree_buf(0) then
294300
if vim.fn.getcwd() ~= core.get_cwd() or (opts.reload_on_bufenter and not opts.filesystem_watchers.enable) then
295-
actions.reloaders.reload_explorer()
301+
local explorer = core.get_explorer()
302+
if explorer then
303+
explorer:reload_explorer()
304+
end
296305
end
297306
end
298307
end,
@@ -343,7 +352,10 @@ local function setup_autocommands(opts)
343352
callback = function()
344353
utils.debounce("Buf:modified", opts.view.debounce_delay, function()
345354
buffers.reload_modified()
346-
actions.reloaders.reload_explorer()
355+
local explorer = core.get_explorer()
356+
if explorer then
357+
explorer:reload_explorer()
358+
end
347359
end)
348360
end,
349361
})

lua/nvim-tree/actions/fs/clipboard.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local core = require "nvim-tree.core"
55
local events = require "nvim-tree.events"
66
local notify = require "nvim-tree.notify"
77
local renderer = require "nvim-tree.renderer"
8-
local reloaders = require "nvim-tree.actions.reloaders"
98

109
local find_file = require("nvim-tree.actions.finders.find-file").fn
1110

@@ -248,7 +247,7 @@ function Clipboard:do_paste(node, action, action_fn)
248247

249248
self.data[action] = {}
250249
if not self.config.filesystem_watchers.enable then
251-
reloaders.reload_explorer()
250+
self.explorer:reload_explorer()
252251
end
253252
end
254253

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local core = require "nvim-tree.core"
12
local utils = require "nvim-tree.utils"
23
local events = require "nvim-tree.events"
34
local view = require "nvim-tree.view"
@@ -116,8 +117,9 @@ function M.fn(node)
116117

117118
local function do_remove()
118119
M.remove(node)
119-
if not M.config.filesystem_watchers.enable then
120-
require("nvim-tree.actions.reloaders").reload_explorer()
120+
local explorer = core.get_explorer()
121+
if not M.config.filesystem_watchers.enable and explorer then
122+
explorer:reload_explorer()
121123
end
122124
end
123125

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local core = require "nvim-tree.core"
12
local lib = require "nvim-tree.lib"
23
local utils = require "nvim-tree.utils"
34
local events = require "nvim-tree.events"
@@ -155,7 +156,10 @@ function M.fn(default_modifier)
155156

156157
M.rename(node, prepend .. new_file_path .. append)
157158
if not M.config.filesystem_watchers.enable then
158-
require("nvim-tree.actions.reloaders").reload_explorer()
159+
local explorer = core.get_explorer()
160+
if explorer then
161+
explorer:reload_explorer()
162+
end
159163
end
160164

161165
find_file(utils.path_remove_trailing(new_file_path))

lua/nvim-tree/actions/fs/trash.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
local core = require "nvim-tree.core"
12
local lib = require "nvim-tree.lib"
23
local notify = require "nvim-tree.notify"
3-
local reloaders = require "nvim-tree.actions.reloaders"
44

55
local M = {
66
config = {},
@@ -52,15 +52,17 @@ function M.remove(node)
5252
end
5353
end
5454

55+
local explorer = core.get_explorer()
56+
5557
if node.nodes ~= nil and not node.link_to then
5658
trash_path(function(_, rc)
5759
if rc ~= 0 then
5860
notify.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash")
5961
return
6062
end
6163
events._dispatch_folder_removed(node.absolute_path)
62-
if not M.config.filesystem_watchers.enable then
63-
reloaders.reload_explorer()
64+
if not M.config.filesystem_watchers.enable and explorer then
65+
explorer:reload_explorer()
6466
end
6567
end)
6668
else
@@ -72,8 +74,8 @@ function M.remove(node)
7274
end
7375
events._dispatch_file_removed(node.absolute_path)
7476
clear_buffer(node.absolute_path)
75-
if not M.config.filesystem_watchers.enable then
76-
reloaders.reload_explorer()
77+
if not M.config.filesystem_watchers.enable and explorer then
78+
explorer:reload_explorer()
7779
end
7880
end)
7981
end

lua/nvim-tree/actions/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ M.finders = require "nvim-tree.actions.finders"
44
M.fs = require "nvim-tree.actions.fs"
55
M.moves = require "nvim-tree.actions.moves"
66
M.node = require "nvim-tree.actions.node"
7-
M.reloaders = require "nvim-tree.actions.reloaders"
87
M.root = require "nvim-tree.actions.root"
98
M.tree = require "nvim-tree.actions.tree"
109

lua/nvim-tree/actions/node/system-open.lua

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local utils = require "nvim-tree.utils"
44
local M = {}
55

66
---@param node Node
7-
function M.fn(node)
7+
local function user(node)
88
if #M.config.system_open.cmd == 0 then
99
require("nvim-tree.utils").notify.warn "Cannot open file with system application. Unrecognized platform."
1010
return
@@ -49,20 +49,41 @@ function M.fn(node)
4949
vim.loop.unref(process.handle)
5050
end
5151

52+
---@param node Node
53+
local function native(node)
54+
local _, err = vim.ui.open(node.link_to or node.absolute_path)
55+
56+
-- err only provided on opener executable not found hence logging path is not useful
57+
if err then
58+
notify.warn(err)
59+
end
60+
end
61+
62+
---@param node Node
63+
function M.fn(node)
64+
M.open(node)
65+
end
66+
67+
-- TODO always use native once 0.10 is the minimum neovim version
5268
function M.setup(opts)
5369
M.config = {}
5470
M.config.system_open = opts.system_open or {}
5571

56-
if #M.config.system_open.cmd == 0 then
57-
if utils.is_windows then
58-
M.config.system_open = {
59-
cmd = "cmd",
60-
args = { "/c", "start", '""' },
61-
}
62-
elseif utils.is_macos then
63-
M.config.system_open.cmd = "open"
64-
elseif utils.is_unix then
65-
M.config.system_open.cmd = "xdg-open"
72+
if vim.fn.has "nvim-0.10" == 1 and #M.config.system_open.cmd == 0 then
73+
M.open = native
74+
else
75+
M.open = user
76+
if #M.config.system_open.cmd == 0 then
77+
if utils.is_windows then
78+
M.config.system_open = {
79+
cmd = "cmd",
80+
args = { "/c", "start", '""' },
81+
}
82+
elseif utils.is_macos then
83+
M.config.system_open.cmd = "open"
84+
elseif utils.is_unix then
85+
M.config.system_open.cmd = "xdg-open"
86+
end
6687
end
6788
end
6889
end

lua/nvim-tree/actions/reloaders.lua

Lines changed: 0 additions & 72 deletions
This file was deleted.

lua/nvim-tree/actions/tree/modifiers/toggles.lua

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
local lib = require "nvim-tree.lib"
22
local utils = require "nvim-tree.utils"
3-
local reloaders = require "nvim-tree.actions.reloaders"
43
local core = require "nvim-tree.core"
54
local M = {}
65

7-
local function reload()
6+
---@param explorer Explorer
7+
local function reload(explorer)
88
local node = lib.get_node_at_cursor()
9-
reloaders.reload_explorer()
9+
explorer:reload_explorer()
1010
utils.focus_node_or_parent(node)
1111
end
1212

@@ -19,39 +19,46 @@ local function wrap_explorer(fn)
1919
end
2020
end
2121

22+
---@param explorer Explorer
2223
local function custom(explorer)
2324
explorer.filters.config.filter_custom = not explorer.filters.config.filter_custom
24-
reload()
25+
reload(explorer)
2526
end
2627

28+
---@param explorer Explorer
2729
local function git_ignored(explorer)
2830
explorer.filters.config.filter_git_ignored = not explorer.filters.config.filter_git_ignored
29-
reload()
31+
reload(explorer)
3032
end
3133

34+
---@param explorer Explorer
3235
local function git_clean(explorer)
3336
explorer.filters.config.filter_git_clean = not explorer.filters.config.filter_git_clean
34-
reload()
37+
reload(explorer)
3538
end
3639

40+
---@param explorer Explorer
3741
local function no_buffer(explorer)
3842
explorer.filters.config.filter_no_buffer = not explorer.filters.config.filter_no_buffer
39-
reload()
43+
reload(explorer)
4044
end
4145

46+
---@param explorer Explorer
4247
local function no_bookmark(explorer)
4348
explorer.filters.config.filter_no_bookmark = not explorer.filters.config.filter_no_bookmark
44-
reload()
49+
reload(explorer)
4550
end
4651

52+
---@param explorer Explorer
4753
local function dotfiles(explorer)
4854
explorer.filters.config.filter_dotfiles = not explorer.filters.config.filter_dotfiles
49-
reload()
55+
reload(explorer)
5056
end
5157

58+
---@param explorer Explorer
5259
local function enable(explorer)
5360
explorer.filters.config.enable = not explorer.filters.config.enable
54-
reload()
61+
reload(explorer)
5562
end
5663

5764
M.custom = wrap_explorer(custom)

0 commit comments

Comments
 (0)