fix: replace vim.* "requires" with explicit calls to vim functions (#1701)
This commit is contained in:
committed by
GitHub
parent
6d6a44626d
commit
8cc369695b
@@ -1,5 +1,4 @@
|
||||
local log = require "nvim-tree.log"
|
||||
local uv = vim.loop
|
||||
local view = require "nvim-tree.view"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
@@ -18,7 +17,7 @@ function M.fn(fname)
|
||||
end
|
||||
|
||||
-- always match against the real path
|
||||
local fname_real = uv.fs_realpath(fname)
|
||||
local fname_real = vim.loop.fs_realpath(fname)
|
||||
if not fname_real then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
local api = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local core = require "nvim-tree.core"
|
||||
local filters = require "nvim-tree.explorer.filters"
|
||||
local find_file = require("nvim-tree.actions.finders.find-file").fn
|
||||
@@ -17,22 +14,22 @@ local function search(search_dir, input_path)
|
||||
local function iter(dir)
|
||||
local realpath, path, name, stat, handle, _
|
||||
|
||||
handle, _ = uv.fs_scandir(dir)
|
||||
handle, _ = vim.loop.fs_scandir(dir)
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
|
||||
realpath, _ = uv.fs_realpath(dir)
|
||||
realpath, _ = vim.loop.fs_realpath(dir)
|
||||
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
|
||||
return
|
||||
end
|
||||
table.insert(realpaths_searched, realpath)
|
||||
|
||||
name, _ = uv.fs_scandir_next(handle)
|
||||
name, _ = vim.loop.fs_scandir_next(handle)
|
||||
while name do
|
||||
path = dir .. "/" .. name
|
||||
|
||||
stat, _ = uv.fs_stat(path)
|
||||
stat, _ = vim.loop.fs_stat(path)
|
||||
if not stat then
|
||||
break
|
||||
end
|
||||
@@ -50,7 +47,7 @@ local function search(search_dir, input_path)
|
||||
end
|
||||
end
|
||||
|
||||
name, _ = uv.fs_scandir_next(handle)
|
||||
name, _ = vim.loop.fs_scandir_next(handle)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,9 +60,9 @@ function M.fn()
|
||||
end
|
||||
|
||||
-- temporarily set &path
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local path_existed, path_opt = pcall(api.nvim_buf_get_option, bufnr, "path")
|
||||
api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path")
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")
|
||||
|
||||
vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path)
|
||||
if not input_path or input_path == "" then
|
||||
@@ -73,9 +70,9 @@ function M.fn()
|
||||
end
|
||||
-- reset &path
|
||||
if path_existed then
|
||||
api.nvim_buf_set_option(bufnr, "path", path_opt)
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", path_opt)
|
||||
else
|
||||
api.nvim_buf_set_option(bufnr, "path", nil)
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", nil)
|
||||
end
|
||||
|
||||
-- strip trailing slash
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
@@ -17,7 +15,7 @@ local function do_copy(source, destination)
|
||||
local source_stats, handle
|
||||
local success, errmsg
|
||||
|
||||
source_stats, errmsg = uv.fs_stat(source)
|
||||
source_stats, errmsg = vim.loop.fs_stat(source)
|
||||
if not source_stats then
|
||||
log.line("copy_paste", "do_copy fs_stat '%s' failed '%s'", source, errmsg)
|
||||
return false, errmsg
|
||||
@@ -31,14 +29,14 @@ local function do_copy(source, destination)
|
||||
end
|
||||
|
||||
if source_stats.type == "file" then
|
||||
success, errmsg = uv.fs_copyfile(source, destination)
|
||||
success, errmsg = vim.loop.fs_copyfile(source, destination)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_copy fs_copyfile failed '%s'", errmsg)
|
||||
return false, errmsg
|
||||
end
|
||||
return true
|
||||
elseif source_stats.type == "directory" then
|
||||
handle, errmsg = uv.fs_scandir(source)
|
||||
handle, errmsg = vim.loop.fs_scandir(source)
|
||||
if type(handle) == "string" then
|
||||
return false, handle
|
||||
elseif not handle then
|
||||
@@ -46,14 +44,14 @@ local function do_copy(source, destination)
|
||||
return false, errmsg
|
||||
end
|
||||
|
||||
success, errmsg = uv.fs_mkdir(destination, source_stats.mode)
|
||||
success, errmsg = vim.loop.fs_mkdir(destination, source_stats.mode)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_copy fs_mkdir '%s' failed '%s'", destination, errmsg)
|
||||
return false, errmsg
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, _ = uv.fs_scandir_next(handle)
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -80,7 +78,7 @@ local function do_single_paste(source, dest, action_type, action_fn)
|
||||
|
||||
log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest)
|
||||
|
||||
dest_stats, errmsg, errcode = uv.fs_stat(dest)
|
||||
dest_stats, errmsg, errcode = vim.loop.fs_stat(dest)
|
||||
if not dest_stats and errcode ~= "ENOENT" then
|
||||
notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???"))
|
||||
return false, errmsg
|
||||
@@ -155,7 +153,7 @@ local function do_paste(node, action_type, action_fn)
|
||||
end
|
||||
|
||||
local destination = node.absolute_path
|
||||
local stats, errmsg, errcode = uv.fs_stat(destination)
|
||||
local stats, errmsg, errcode = vim.loop.fs_stat(destination)
|
||||
if not stats and errcode ~= "ENOENT" then
|
||||
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
|
||||
notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???"))
|
||||
@@ -188,7 +186,7 @@ local function do_cut(source, destination)
|
||||
return true
|
||||
end
|
||||
|
||||
local success, errmsg = uv.fs_rename(source, destination)
|
||||
local success, errmsg = vim.loop.fs_rename(source, destination)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_cut fs_rename failed '%s'", errmsg)
|
||||
return false, errmsg
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
local lib = require "nvim-tree.lib"
|
||||
@@ -9,12 +7,12 @@ local notify = require "nvim-tree.notify"
|
||||
local M = {}
|
||||
|
||||
local function create_and_notify(file)
|
||||
local ok, fd = pcall(uv.fs_open, file, "w", 420)
|
||||
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
|
||||
if not ok then
|
||||
notify.error("Couldn't create file " .. file)
|
||||
return
|
||||
end
|
||||
uv.fs_close(fd)
|
||||
vim.loop.fs_close(fd)
|
||||
events._dispatch_file_created(file)
|
||||
end
|
||||
|
||||
@@ -94,7 +92,7 @@ function M.fn(node)
|
||||
if is_last_path_file and idx == num_nodes then
|
||||
create_file(path_to_create)
|
||||
elseif not utils.file_exists(path_to_create) then
|
||||
local success = uv.fs_mkdir(path_to_create, 493)
|
||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||
if not success then
|
||||
notify.error("Could not create folder " .. path_to_create)
|
||||
is_error = true
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
local a = vim.api
|
||||
local luv = vim.loop
|
||||
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
local view = require "nvim-tree.view"
|
||||
@@ -10,13 +7,13 @@ local notify = require "nvim-tree.notify"
|
||||
local M = {}
|
||||
|
||||
local function close_windows(windows)
|
||||
if view.View.float.enable and #a.nvim_list_wins() == 1 then
|
||||
if view.View.float.enable and #vim.api.nvim_list_wins() == 1 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, window in ipairs(windows) do
|
||||
if a.nvim_win_is_valid(window) then
|
||||
a.nvim_win_close(window, true)
|
||||
if vim.api.nvim_win_is_valid(window) then
|
||||
vim.api.nvim_win_close(window, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,14 +23,14 @@ local function clear_buffer(absolute_path)
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then
|
||||
local winnr = a.nvim_get_current_win()
|
||||
a.nvim_set_current_win(buf.windows[1])
|
||||
local winnr = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd ":bn"
|
||||
if not view.View.float.enable then
|
||||
a.nvim_set_current_win(winnr)
|
||||
vim.api.nvim_set_current_win(winnr)
|
||||
end
|
||||
end
|
||||
a.nvim_buf_delete(buf.bufnr, { force = true })
|
||||
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
||||
if M.close_window then
|
||||
close_windows(buf.windows)
|
||||
end
|
||||
@@ -43,13 +40,13 @@ local function clear_buffer(absolute_path)
|
||||
end
|
||||
|
||||
local function remove_dir(cwd)
|
||||
local handle = luv.fs_scandir(cwd)
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
if type(handle) == "string" then
|
||||
return notify.error(handle)
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, t = luv.fs_scandir_next(handle)
|
||||
local name, t = vim.loop.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -61,7 +58,7 @@ local function remove_dir(cwd)
|
||||
return false
|
||||
end
|
||||
else
|
||||
local success = luv.fs_unlink(new_cwd)
|
||||
local success = vim.loop.fs_unlink(new_cwd)
|
||||
if not success then
|
||||
return false
|
||||
end
|
||||
@@ -69,7 +66,7 @@ local function remove_dir(cwd)
|
||||
end
|
||||
end
|
||||
|
||||
return luv.fs_rmdir(cwd)
|
||||
return vim.loop.fs_rmdir(cwd)
|
||||
end
|
||||
|
||||
function M.fn(node)
|
||||
@@ -88,7 +85,7 @@ function M.fn(node)
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
local success = luv.fs_unlink(node.absolute_path)
|
||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
@@ -17,7 +15,7 @@ function M.rename(node, to)
|
||||
return
|
||||
end
|
||||
|
||||
local success, err = uv.fs_rename(node.absolute_path, to)
|
||||
local success, err = vim.loop.fs_rename(node.absolute_path, to)
|
||||
if not success then
|
||||
return notify.warn(err_fmt(node.absolute_path, to, err))
|
||||
end
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local a = vim.api
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
@@ -19,10 +17,10 @@ local function clear_buffer(absolute_path)
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
if buf.hidden == 0 and #bufs > 1 then
|
||||
local winnr = a.nvim_get_current_win()
|
||||
a.nvim_set_current_win(buf.windows[1])
|
||||
local winnr = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd ":bn"
|
||||
a.nvim_set_current_win(winnr)
|
||||
vim.api.nvim_set_current_win(winnr)
|
||||
end
|
||||
vim.api.nvim_buf_delete(buf.bufnr, {})
|
||||
return
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
-- @deprecated: new implementation in nvim-tree.keymap. Please do not edit this file.
|
||||
|
||||
local a = vim.api
|
||||
|
||||
local log = require "nvim-tree.log"
|
||||
local view = require "nvim-tree.view"
|
||||
local notify = require "nvim-tree.notify"
|
||||
@@ -350,7 +348,7 @@ end
|
||||
|
||||
local function cleanup_existing_mappings()
|
||||
local bufnr = view.get_bufnr()
|
||||
if bufnr == nil or not a.nvim_buf_is_valid(bufnr) then
|
||||
if bufnr == nil or not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local utils = require "nvim-tree.utils"
|
||||
local a = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -34,19 +33,19 @@ local function setup_window(node)
|
||||
noautocmd = true,
|
||||
zindex = 60,
|
||||
})
|
||||
local winnr = a.nvim_open_win(0, false, open_win_config)
|
||||
local winnr = vim.api.nvim_open_win(0, false, open_win_config)
|
||||
current_popup = {
|
||||
winnr = winnr,
|
||||
file_path = node.absolute_path,
|
||||
}
|
||||
local bufnr = a.nvim_create_buf(false, true)
|
||||
a.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
a.nvim_win_set_buf(winnr, bufnr)
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_buf(winnr, bufnr)
|
||||
end
|
||||
|
||||
function M.close_popup()
|
||||
if current_popup ~= nil then
|
||||
a.nvim_win_close(current_popup.winnr, { force = true })
|
||||
vim.api.nvim_win_close(current_popup.winnr, { force = true })
|
||||
vim.cmd "augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END"
|
||||
|
||||
current_popup = nil
|
||||
@@ -69,8 +68,8 @@ function M.toggle_file_info(node)
|
||||
|
||||
setup_window(node)
|
||||
|
||||
a.nvim_create_autocmd("CursorMoved", {
|
||||
group = a.nvim_create_augroup("NvimTreeRemoveFilePopup", {}),
|
||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||
group = vim.api.nvim_create_augroup("NvimTreeRemoveFilePopup", {}),
|
||||
callback = M.close_popup,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- Copyright 2019 Yazdani Kiyan under MIT License
|
||||
local api = vim.api
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
@@ -18,20 +16,20 @@ end
|
||||
---Get all windows in the current tabpage that aren't NvimTree.
|
||||
---@return table with valid win_ids
|
||||
local function usable_win_ids()
|
||||
local tabpage = api.nvim_get_current_tabpage()
|
||||
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
local tree_winid = view.get_winnr(tabpage)
|
||||
|
||||
return vim.tbl_filter(function(id)
|
||||
local bufid = api.nvim_win_get_buf(id)
|
||||
local bufid = vim.api.nvim_win_get_buf(id)
|
||||
for option, v in pairs(M.window_picker.exclude) do
|
||||
local ok, option_value = pcall(api.nvim_buf_get_option, bufid, option)
|
||||
local ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option)
|
||||
if ok and vim.tbl_contains(v, option_value) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local win_config = api.nvim_win_get_config(id)
|
||||
local win_config = vim.api.nvim_win_get_config(id)
|
||||
return id ~= tree_winid and win_config.focusable and not win_config.external
|
||||
end, win_ids)
|
||||
end
|
||||
@@ -68,8 +66,8 @@ local function pick_win_id()
|
||||
local laststatus = vim.o.laststatus
|
||||
vim.o.laststatus = 2
|
||||
|
||||
local tabpage = api.nvim_get_current_tabpage()
|
||||
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
|
||||
local not_selectable = vim.tbl_filter(function(id)
|
||||
return not vim.tbl_contains(selectable, id)
|
||||
@@ -77,8 +75,8 @@ local function pick_win_id()
|
||||
|
||||
if laststatus == 3 then
|
||||
for _, win_id in ipairs(not_selectable) do
|
||||
local ok_status, statusline = pcall(api.nvim_win_get_option, win_id, "statusline")
|
||||
local ok_hl, winhl = pcall(api.nvim_win_get_option, win_id, "winhl")
|
||||
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline")
|
||||
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, win_id, "winhl")
|
||||
|
||||
win_opts[win_id] = {
|
||||
statusline = ok_status and statusline or "",
|
||||
@@ -86,15 +84,15 @@ local function pick_win_id()
|
||||
}
|
||||
|
||||
-- Clear statusline for windows not selectable
|
||||
api.nvim_win_set_option(win_id, "statusline", " ")
|
||||
vim.api.nvim_win_set_option(win_id, "statusline", " ")
|
||||
end
|
||||
end
|
||||
|
||||
-- Setup UI
|
||||
for _, id in ipairs(selectable) do
|
||||
local char = M.window_picker.chars:sub(i, i)
|
||||
local ok_status, statusline = pcall(api.nvim_win_get_option, id, "statusline")
|
||||
local ok_hl, winhl = pcall(api.nvim_win_get_option, id, "winhl")
|
||||
local ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline")
|
||||
local ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl")
|
||||
|
||||
win_opts[id] = {
|
||||
statusline = ok_status and statusline or "",
|
||||
@@ -102,8 +100,8 @@ local function pick_win_id()
|
||||
}
|
||||
win_map[char] = id
|
||||
|
||||
api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=")
|
||||
api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker")
|
||||
vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=")
|
||||
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker")
|
||||
|
||||
i = i + 1
|
||||
if i > #M.window_picker.chars then
|
||||
@@ -122,14 +120,14 @@ local function pick_win_id()
|
||||
-- Restore window options
|
||||
for _, id in ipairs(selectable) do
|
||||
for opt, value in pairs(win_opts[id]) do
|
||||
api.nvim_win_set_option(id, opt, value)
|
||||
vim.api.nvim_win_set_option(id, opt, value)
|
||||
end
|
||||
end
|
||||
|
||||
if laststatus == 3 then
|
||||
for _, id in ipairs(not_selectable) do
|
||||
for opt, value in pairs(win_opts[id]) do
|
||||
api.nvim_win_set_option(id, opt, value)
|
||||
vim.api.nvim_win_set_option(id, opt, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -154,9 +152,9 @@ local function on_preview(buf_loaded)
|
||||
if not buf_loaded then
|
||||
vim.bo.bufhidden = "delete"
|
||||
|
||||
api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
|
||||
group = api.nvim_create_augroup("RemoveBufHidden", {}),
|
||||
buffer = api.nvim_get_current_buf(),
|
||||
vim.api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
|
||||
group = vim.api.nvim_create_augroup("RemoveBufHidden", {}),
|
||||
buffer = vim.api.nvim_get_current_buf(),
|
||||
callback = function()
|
||||
vim.bo.bufhidden = ""
|
||||
end,
|
||||
@@ -195,7 +193,7 @@ end
|
||||
local function set_current_win_no_autocmd(winid, autocmd)
|
||||
local eventignore = vim.opt.eventignore:get()
|
||||
vim.opt.eventignore:append(autocmd)
|
||||
api.nvim_set_current_win(winid)
|
||||
vim.api.nvim_set_current_win(winid)
|
||||
vim.opt.eventignore = eventignore
|
||||
end
|
||||
|
||||
@@ -209,13 +207,13 @@ local function open_in_new_window(filename, mode, win_ids)
|
||||
return
|
||||
end
|
||||
|
||||
local create_new_window = #api.nvim_list_wins() == 1
|
||||
local create_new_window = #vim.api.nvim_list_wins() == 1
|
||||
local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
||||
|
||||
-- Target is invalid or window does not exist in current tabpage: create new window
|
||||
if not vim.tbl_contains(win_ids, target_winid) then
|
||||
vim.cmd(new_window_side .. " vsplit")
|
||||
target_winid = api.nvim_get_current_win()
|
||||
target_winid = vim.api.nvim_get_current_win()
|
||||
lib.target_winid = target_winid
|
||||
|
||||
-- No need to split, as we created a new window.
|
||||
@@ -226,8 +224,8 @@ local function open_in_new_window(filename, mode, win_ids)
|
||||
elseif not vim.o.hidden then
|
||||
-- If `hidden` is not enabled, check if buffer in target window is
|
||||
-- modified, and create new split if it is.
|
||||
local target_bufid = api.nvim_win_get_buf(target_winid)
|
||||
if api.nvim_buf_get_option(target_bufid, "modified") then
|
||||
local target_bufid = vim.api.nvim_win_get_buf(target_winid)
|
||||
if vim.api.nvim_buf_get_option(target_bufid, "modified") then
|
||||
mode = "vsplit"
|
||||
end
|
||||
end
|
||||
@@ -257,8 +255,8 @@ local function open_in_new_window(filename, mode, win_ids)
|
||||
end
|
||||
|
||||
local function is_already_loaded(filename)
|
||||
for _, buf_id in ipairs(api.nvim_list_bufs()) do
|
||||
if api.nvim_buf_is_loaded(buf_id) and filename == api.nvim_buf_get_name(buf_id) then
|
||||
for _, buf_id in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(buf_id) and filename == vim.api.nvim_buf_get_name(buf_id) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -283,8 +281,8 @@ function M.fn(mode, filename)
|
||||
return edit_in_current_buf(filename)
|
||||
end
|
||||
|
||||
local tabpage = api.nvim_get_current_tabpage()
|
||||
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
local buf_loaded = is_already_loaded(filename)
|
||||
|
||||
local found_win = utils.get_win_buf_from_path(filename)
|
||||
@@ -295,7 +293,7 @@ function M.fn(mode, filename)
|
||||
if not found_win then
|
||||
open_in_new_window(filename, mode, win_ids)
|
||||
else
|
||||
api.nvim_set_current_win(found_win)
|
||||
vim.api.nvim_set_current_win(found_win)
|
||||
vim.bo.bufhidden = ""
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local M = {
|
||||
config = {
|
||||
is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1,
|
||||
@@ -18,10 +16,10 @@ function M.fn(node)
|
||||
cmd = M.config.system_open.cmd,
|
||||
args = M.config.system_open.args,
|
||||
errors = "\n",
|
||||
stderr = uv.new_pipe(false),
|
||||
stderr = vim.loop.new_pipe(false),
|
||||
}
|
||||
table.insert(process.args, node.link_to or node.absolute_path)
|
||||
process.handle, process.pid = uv.spawn(
|
||||
process.handle, process.pid = vim.loop.spawn(
|
||||
process.cmd,
|
||||
{ args = process.args, stdio = { nil, nil, process.stderr }, detached = true },
|
||||
function(code)
|
||||
@@ -39,7 +37,7 @@ function M.fn(node)
|
||||
error("\n" .. process.pid .. "\nNvimTree system_open: failed to spawn process using '" .. process.cmd .. "'.")
|
||||
return
|
||||
end
|
||||
uv.read_start(process.stderr, function(err, data)
|
||||
vim.loop.read_start(process.stderr, function(err, data)
|
||||
if err then
|
||||
return
|
||||
end
|
||||
@@ -47,7 +45,7 @@ function M.fn(node)
|
||||
process.errors = process.errors .. data
|
||||
end
|
||||
end)
|
||||
uv.unref(process.handle)
|
||||
vim.loop.unref(process.handle)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
local a = vim.api
|
||||
|
||||
local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local core = require "nvim-tree.core"
|
||||
|
||||
local M = {
|
||||
current_tab = a.nvim_get_current_tabpage(),
|
||||
current_tab = vim.api.nvim_get_current_tabpage(),
|
||||
}
|
||||
|
||||
local function clean_input_cwd(name)
|
||||
@@ -33,7 +31,7 @@ function M.fn(input_cwd, with_open)
|
||||
return
|
||||
end
|
||||
|
||||
local new_tabpage = a.nvim_get_current_tabpage()
|
||||
local new_tabpage = vim.api.nvim_get_current_tabpage()
|
||||
if is_window_event(new_tabpage) then
|
||||
return
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user