@@ -4,7 +4,7 @@ local utils = require "nvim-tree.utils"
44local 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 )
5050end
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
5268function 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
6889end
0 commit comments