* feat(#2430): use vim.ui.open as default system_open, for neovim 0.10+ * feat(#2430): use vim.ui.open as default system_open, for neovim 0.10+
This commit is contained in:
parent
a4dd5ad5c8
commit
03f737e574
@ -1198,11 +1198,18 @@ Takes the `BufEnter` event as an argument. see |autocmd-events|
|
||||
|
||||
Open a file or directory in your preferred application.
|
||||
|
||||
|vim.ui.open| was introduced in neovim 0.10 and is the default.
|
||||
|
||||
Once nvim-tree minimum neovim version is updated to 0.10, these options will
|
||||
no longer be necessary and will be removed.
|
||||
|
||||
*nvim-tree.system_open.cmd*
|
||||
The open command itself.
|
||||
Type: `string`, Default: `""`
|
||||
|
||||
Leave empty for OS specific default:
|
||||
neovim >= 0.10 defaults to |vim.ui.open|
|
||||
|
||||
neovim < 0.10 defaults to:
|
||||
UNIX: `"xdg-open"`
|
||||
macOS: `"open"`
|
||||
Windows: `"cmd"`
|
||||
|
||||
@ -4,7 +4,7 @@ local utils = require "nvim-tree.utils"
|
||||
local M = {}
|
||||
|
||||
---@param node Node
|
||||
function M.fn(node)
|
||||
local function user(node)
|
||||
if #M.config.system_open.cmd == 0 then
|
||||
require("nvim-tree.utils").notify.warn "Cannot open file with system application. Unrecognized platform."
|
||||
return
|
||||
@ -49,10 +49,30 @@ function M.fn(node)
|
||||
vim.loop.unref(process.handle)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
local function native(node)
|
||||
local _, err = vim.ui.open(node.link_to or node.absolute_path)
|
||||
|
||||
-- err only provided on opener executable not found hence logging path is not useful
|
||||
if err then
|
||||
notify.warn(err)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.fn(node)
|
||||
M.open(node)
|
||||
end
|
||||
|
||||
-- TODO always use native once 0.10 is the minimum neovim version
|
||||
function M.setup(opts)
|
||||
M.config = {}
|
||||
M.config.system_open = opts.system_open or {}
|
||||
|
||||
if vim.fn.has "nvim-0.10" == 1 and #M.config.system_open.cmd == 0 then
|
||||
M.open = native
|
||||
else
|
||||
M.open = user
|
||||
if #M.config.system_open.cmd == 0 then
|
||||
if utils.is_windows then
|
||||
M.config.system_open = {
|
||||
@ -66,5 +86,6 @@ function M.setup(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Loading…
Reference in New Issue
Block a user