Skip to content

Commit 6eb3fdd

Browse files
committed
perf(#3257): remove system-open setup
1 parent 56d95d0 commit 6eb3fdd

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

lua/nvim-tree/actions/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ M.node = require("nvim-tree.actions.node")
66
M.tree = require("nvim-tree.actions.tree")
77

88
function M.setup(opts)
9-
M.node.setup(opts)
109
M.tree.setup(opts)
1110
end
1211

lua/nvim-tree/actions/node/init.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@ M.run_command = require("nvim-tree.actions.node.run-command")
66
M.system_open = require("nvim-tree.actions.node.system-open")
77
M.buffer = require("nvim-tree.actions.node.buffer")
88

9-
function M.setup(opts)
10-
require("nvim-tree.actions.node.system-open").setup(opts)
11-
end
12-
139
return M

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
local notify = require("nvim-tree.notify")
22
local utils = require("nvim-tree.utils")
3+
local config = require("nvim-tree.config")
34

45
local M = {}
56

67
---@param node Node
78
local function user(node)
8-
if #M.config.system_open.cmd == 0 then
9-
require("nvim-tree.utils").notify.warn("Cannot open file with system application. Unrecognized platform.")
9+
local cmd = config.g.system_open.cmd
10+
local args = config.g.system_open.args
11+
12+
if #cmd == 0 then
13+
if utils.is_windows then
14+
cmd = "cmd"
15+
args = { "/c", "start", '""' }
16+
elseif utils.is_macos then
17+
cmd = "open"
18+
elseif utils.is_unix then
19+
cmd = "xdg-open"
20+
end
21+
end
22+
23+
if #cmd == 0 then
24+
notify.warn("Cannot open file with system application. Unrecognized platform.")
1025
return
1126
end
1227

1328
local process = {
14-
cmd = M.config.system_open.cmd,
15-
args = M.config.system_open.args,
29+
cmd = cmd,
30+
args = args,
1631
errors = "\n",
1732
stderr = vim.loop.new_pipe(false),
1833
}
@@ -61,30 +76,11 @@ end
6176

6277
---@param node Node
6378
function M.fn(node)
64-
M.open(node)
65-
end
66-
67-
-- TODO #2430 always use native once 0.10 is the minimum neovim version
68-
function M.setup(opts)
69-
M.config = {}
70-
M.config.system_open = opts.system_open or {}
71-
72-
if vim.fn.has("nvim-0.10") == 1 and #M.config.system_open.cmd == 0 then
73-
M.open = native
79+
-- TODO #2430 always use native once 0.10 is the minimum neovim version
80+
if vim.fn.has("nvim-0.19") == 1 and #config.g.system_open.cmd == 0 then
81+
native(node)
7482
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
87-
end
83+
user(node)
8884
end
8985
end
9086

lua/nvim-tree/config.lua

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,6 @@ M.d = { -- config-default-start
303303
},
304304
} -- config-default-end
305305

306-
-- Immediately apply OS specific localisations to defaults
307-
if utils.is_macos or utils.is_windows then
308-
M.d.trash.cmd = "trash"
309-
end
310-
if utils.is_windows then
311-
M.d.filesystem_watchers.max_events = 1000
312-
end
313-
314306
local FIELD_SKIP_VALIDATE = {
315307
open_win_config = true,
316308
}
@@ -486,11 +478,24 @@ local function validate_config(u)
486478
end
487479
end
488480

481+
---Localise the (default) config with OS specifics
482+
---@param d nvim_tree.config
483+
local function localise_config(d)
484+
-- Trash
485+
if utils.is_macos or utils.is_windows then
486+
d.trash.cmd = "trash"
487+
end
488+
489+
-- Watchers
490+
if utils.is_windows then
491+
d.filesystem_watchers.max_events = 1000
492+
end
493+
end
494+
489495
---Normalise the (user) config
490496
---@param u nvim_tree.config
491497
local function process_config(u)
492-
493-
---Always use upper case for window pickers
498+
-- Open
494499
if u.actions.open_file.window_picker.chars then
495500
u.actions.open_file.window_picker.chars = tostring(u.actions.open_file.window_picker.chars):upper()
496501
end
@@ -541,4 +546,7 @@ function M.g_clone()
541546
return vim.deepcopy(M.g)
542547
end
543548

549+
---Immediately localise the defaults once and once only
550+
localise_config(M.d)
551+
544552
return M

0 commit comments

Comments
 (0)