fix: replace vim.* "requires" with explicit calls to vim functions (#1701)
This commit is contained in:
parent
6d6a44626d
commit
8cc369695b
@ -1,6 +1,3 @@
|
||||
local luv = vim.loop
|
||||
local api = vim.api
|
||||
|
||||
local lib = require "nvim-tree.lib"
|
||||
local log = require "nvim-tree.log"
|
||||
local colors = require "nvim-tree.colors"
|
||||
@ -29,7 +26,7 @@ end
|
||||
|
||||
function M.change_root(filepath, bufnr)
|
||||
-- skip if current file is in ignore_list
|
||||
local ft = api.nvim_buf_get_option(bufnr, "filetype") or ""
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or ""
|
||||
for _, value in pairs(_config.update_focused_file.ignore_list) do
|
||||
if utils.str_find(filepath, value) or utils.str_find(ft, value) then
|
||||
return
|
||||
@ -75,7 +72,7 @@ function M.toggle(find_file, no_focus, cwd, bang)
|
||||
if view.is_visible() then
|
||||
view.close()
|
||||
else
|
||||
local previous_buf = api.nvim_get_current_buf()
|
||||
local previous_buf = vim.api.nvim_get_current_buf()
|
||||
M.open(cwd)
|
||||
if _config.update_focused_file.enable or find_file then
|
||||
M.find_file(false, previous_buf, bang)
|
||||
@ -101,8 +98,8 @@ function M.open_replacing_current_buffer(cwd)
|
||||
return
|
||||
end
|
||||
|
||||
local buf = api.nvim_get_current_buf()
|
||||
local bufname = api.nvim_buf_get_name(buf)
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
if bufname == "" or vim.loop.fs_stat(bufname) == nil then
|
||||
return
|
||||
end
|
||||
@ -121,8 +118,8 @@ end
|
||||
|
||||
function M.tab_change()
|
||||
if view.is_visible { any_tabpage = true } then
|
||||
local bufname = api.nvim_buf_get_name(0)
|
||||
local ft = api.nvim_buf_get_option(0, "ft")
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
local ft = vim.api.nvim_buf_get_option(0, "ft")
|
||||
for _, filter in ipairs(M.config.ignore_buf_on_tab_change) do
|
||||
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
|
||||
return
|
||||
@ -135,14 +132,14 @@ end
|
||||
|
||||
local function find_existing_windows()
|
||||
return vim.tbl_filter(function(win)
|
||||
local buf = api.nvim_win_get_buf(win)
|
||||
return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
|
||||
end, api.nvim_list_wins())
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
return vim.api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
|
||||
end, vim.api.nvim_list_wins())
|
||||
end
|
||||
|
||||
local function is_file_readable(fname)
|
||||
local stat = luv.fs_stat(fname)
|
||||
return stat and stat.type == "file" and luv.fs_access(fname, "R")
|
||||
local stat = vim.loop.fs_stat(fname)
|
||||
return stat and stat.type == "file" and vim.loop.fs_access(fname, "R")
|
||||
end
|
||||
|
||||
function M.find_file(with_open, bufnr, bang)
|
||||
@ -150,11 +147,11 @@ function M.find_file(with_open, bufnr, bang)
|
||||
return
|
||||
end
|
||||
|
||||
bufnr = bufnr or api.nvim_get_current_buf()
|
||||
if not api.nvim_buf_is_valid(bufnr) then
|
||||
bufnr = bufnr or vim.api.nvim_get_current_buf()
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
end
|
||||
local bufname = api.nvim_buf_get_name(bufnr)
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ":p"))
|
||||
if not is_file_readable(filepath) then
|
||||
return
|
||||
@ -181,8 +178,8 @@ function M.open_on_directory()
|
||||
return
|
||||
end
|
||||
|
||||
local buf = api.nvim_get_current_buf()
|
||||
local bufname = api.nvim_buf_get_name(buf)
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
if vim.fn.isdirectory(bufname) ~= 1 then
|
||||
return
|
||||
end
|
||||
@ -198,7 +195,7 @@ end
|
||||
|
||||
local prev_line
|
||||
function M.place_cursor_on_node()
|
||||
local l = api.nvim_win_get_cursor(0)[1]
|
||||
local l = vim.api.nvim_win_get_cursor(0)[1]
|
||||
if l == prev_line then
|
||||
return
|
||||
end
|
||||
@ -209,22 +206,22 @@ function M.place_cursor_on_node()
|
||||
return
|
||||
end
|
||||
|
||||
local line = api.nvim_get_current_line()
|
||||
local cursor = api.nvim_win_get_cursor(0)
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local idx = vim.fn.stridx(line, node.name)
|
||||
|
||||
if idx >= 0 then
|
||||
api.nvim_win_set_cursor(0, { cursor[1], idx })
|
||||
vim.api.nvim_win_set_cursor(0, { cursor[1], idx })
|
||||
end
|
||||
end
|
||||
|
||||
function M.on_enter(netrw_disabled)
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufname = api.nvim_buf_get_name(bufnr)
|
||||
local buftype = api.nvim_buf_get_option(bufnr, "filetype")
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local buftype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
local ft_ignore = _config.ignore_ft_on_setup
|
||||
|
||||
local stats = luv.fs_stat(bufname)
|
||||
local stats = vim.loop.fs_stat(bufname)
|
||||
local is_dir = stats and stats.type == "directory"
|
||||
local is_file = stats and stats.type == "file"
|
||||
local cwd
|
||||
@ -234,7 +231,7 @@ function M.on_enter(netrw_disabled)
|
||||
vim.cmd("noautocmd cd " .. cwd)
|
||||
end
|
||||
|
||||
local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
|
||||
local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
|
||||
local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "")
|
||||
|
||||
local buf_is_dir = is_dir and netrw_disabled
|
||||
@ -265,7 +262,7 @@ function M.on_enter(netrw_disabled)
|
||||
-- Session that left a NvimTree Buffer opened, reopen with it
|
||||
local existing_tree_wins = find_existing_windows()
|
||||
if existing_tree_wins[1] then
|
||||
api.nvim_set_current_win(existing_tree_wins[1])
|
||||
vim.api.nvim_set_current_win(existing_tree_wins[1])
|
||||
end
|
||||
|
||||
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
|
||||
@ -297,27 +294,27 @@ local function manage_netrw(disable_netrw, hijack_netrw)
|
||||
end
|
||||
|
||||
local function setup_vim_commands()
|
||||
api.nvim_create_user_command("NvimTreeOpen", function(res)
|
||||
vim.api.nvim_create_user_command("NvimTreeOpen", function(res)
|
||||
M.open(res.args)
|
||||
end, { nargs = "?", complete = "dir" })
|
||||
api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true })
|
||||
api.nvim_create_user_command("NvimTreeToggle", function(res)
|
||||
vim.api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true })
|
||||
vim.api.nvim_create_user_command("NvimTreeToggle", function(res)
|
||||
M.toggle(false, false, res.args)
|
||||
end, { nargs = "?", complete = "dir" })
|
||||
api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true })
|
||||
api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
|
||||
api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
|
||||
api.nvim_create_user_command("NvimTreeFindFile", function(res)
|
||||
vim.api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true })
|
||||
vim.api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
|
||||
vim.api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
|
||||
vim.api.nvim_create_user_command("NvimTreeFindFile", function(res)
|
||||
M.find_file(true, nil, res.bang)
|
||||
end, { bang = true, bar = true })
|
||||
api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
|
||||
vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
|
||||
M.toggle(true, false, res.args, res.bang)
|
||||
end, { bang = true, nargs = "?", complete = "dir" })
|
||||
api.nvim_create_user_command("NvimTreeResize", function(res)
|
||||
vim.api.nvim_create_user_command("NvimTreeResize", function(res)
|
||||
M.resize(res.args)
|
||||
end, { nargs = 1, bar = true })
|
||||
api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true })
|
||||
api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function()
|
||||
vim.api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true })
|
||||
vim.api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function()
|
||||
collapse_all.fn(true)
|
||||
end, { bar = true })
|
||||
end
|
||||
@ -331,10 +328,10 @@ function M.change_dir(name)
|
||||
end
|
||||
|
||||
local function setup_autocommands(opts)
|
||||
local augroup_id = api.nvim_create_augroup("NvimTree", { clear = true })
|
||||
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
|
||||
local function create_nvim_tree_autocmd(name, custom_opts)
|
||||
local default_opts = { group = augroup_id }
|
||||
api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
|
||||
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
|
||||
end
|
||||
|
||||
-- reset highlights when colorscheme is changed
|
||||
@ -410,9 +407,9 @@ local function setup_autocommands(opts)
|
||||
create_nvim_tree_autocmd("BufEnter", {
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.schedule(function()
|
||||
api.nvim_buf_call(bufnr, function()
|
||||
vim.api.nvim_buf_call(bufnr, function()
|
||||
vim.cmd [[norm! zz]]
|
||||
end)
|
||||
end)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local api = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_color_from_hl(hl_name, fallback)
|
||||
@ -93,12 +91,12 @@ function M.setup()
|
||||
local gui = d.gui and " gui=" .. d.gui or ""
|
||||
local fg = d.fg and " guifg=" .. d.fg or ""
|
||||
local bg = d.bg and " guibg=" .. d.bg or ""
|
||||
api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg)
|
||||
vim.api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg)
|
||||
end
|
||||
|
||||
local links = get_links()
|
||||
for k, d in pairs(links) do
|
||||
api.nvim_command("hi def link NvimTree" .. k .. " " .. d)
|
||||
vim.api.nvim_command("hi def link NvimTree" .. k .. " " .. d)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
local a = vim.api
|
||||
local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
local core = require "nvim-tree.core"
|
||||
@ -18,7 +17,7 @@ local sign_names = {
|
||||
|
||||
local function add_sign(linenr, severity)
|
||||
local buf = view.get_bufnr()
|
||||
if not a.nvim_buf_is_valid(buf) or not a.nvim_buf_is_loaded(buf) then
|
||||
if not vim.api.nvim_buf_is_valid(buf) or not vim.api.nvim_buf_is_loaded(buf) then
|
||||
return
|
||||
end
|
||||
local sign_name = sign_names[severity][1]
|
||||
@ -30,8 +29,8 @@ local function from_nvim_lsp()
|
||||
|
||||
for _, diagnostic in ipairs(vim.diagnostic.get()) do
|
||||
local buf = diagnostic.bufnr
|
||||
if a.nvim_buf_is_valid(buf) then
|
||||
local bufname = a.nvim_buf_get_name(buf)
|
||||
if vim.api.nvim_buf_is_valid(buf) then
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
local lowest_severity = buffer_severity[bufname]
|
||||
if not lowest_severity or diagnostic.severity < lowest_severity then
|
||||
buffer_severity[bufname] = diagnostic.severity
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_dir_git_status(parent_ignored, status, absolute_path)
|
||||
@ -22,7 +20,7 @@ local function get_git_status(parent_ignored, status, absolute_path)
|
||||
end
|
||||
|
||||
function M.has_one_child_folder(node)
|
||||
return #node.nodes == 1 and node.nodes[1].nodes and uv.fs_access(node.nodes[1].absolute_path, "R")
|
||||
return #node.nodes == 1 and node.nodes[1].nodes and vim.loop.fs_access(node.nodes[1].absolute_path, "R")
|
||||
end
|
||||
|
||||
function M.update_git_status(node, parent_ignored, status)
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require "nvim-tree.utils"
|
||||
local builders = require "nvim-tree.explorer.node-builders"
|
||||
local common = require "nvim-tree.explorer.common"
|
||||
@ -11,14 +9,14 @@ local notify = require "nvim-tree.notify"
|
||||
local M = {}
|
||||
|
||||
local function get_type_from(type_, cwd)
|
||||
return type_ or (uv.fs_stat(cwd) or {}).type
|
||||
return type_ or (vim.loop.fs_stat(cwd) or {}).type
|
||||
end
|
||||
|
||||
local function populate_children(handle, cwd, node, status)
|
||||
local node_ignored = node.git_status == "!!"
|
||||
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
|
||||
while true do
|
||||
local name, t = uv.fs_scandir_next(handle)
|
||||
local name, t = vim.loop.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@ -31,7 +29,7 @@ local function populate_children(handle, cwd, node, status)
|
||||
and not nodes_by_path[abs]
|
||||
then
|
||||
local child = nil
|
||||
if t == "directory" and uv.fs_access(abs, "R") then
|
||||
if t == "directory" and vim.loop.fs_access(abs, "R") then
|
||||
child = builders.folder(node, abs, name)
|
||||
elseif t == "file" then
|
||||
child = builders.file(node, abs, name)
|
||||
@ -51,7 +49,7 @@ local function populate_children(handle, cwd, node, status)
|
||||
end
|
||||
|
||||
local function get_dir_handle(cwd)
|
||||
local handle = uv.fs_scandir(cwd)
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
if type(handle) == "string" then
|
||||
notify.error(handle)
|
||||
return
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local git = require "nvim-tree.git"
|
||||
local watch = require "nvim-tree.explorer.watch"
|
||||
local common = require "nvim-tree.explorer.common"
|
||||
@ -13,7 +11,7 @@ local Explorer = {}
|
||||
Explorer.__index = Explorer
|
||||
|
||||
function Explorer.new(cwd)
|
||||
cwd = uv.fs_realpath(cwd or uv.cwd())
|
||||
cwd = vim.loop.fs_realpath(cwd or vim.loop.cwd())
|
||||
local explorer = setmetatable({
|
||||
absolute_path = cwd,
|
||||
nodes = {},
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
local uv = vim.loop
|
||||
local utils = require "nvim-tree.utils"
|
||||
local watch = require "nvim-tree.explorer.watch"
|
||||
|
||||
@ -8,13 +7,13 @@ local M = {
|
||||
}
|
||||
|
||||
function M.folder(parent, absolute_path, name)
|
||||
local handle = uv.fs_scandir(absolute_path)
|
||||
local has_children = handle and uv.fs_scandir_next(handle) ~= nil
|
||||
local handle = vim.loop.fs_scandir(absolute_path)
|
||||
local has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
||||
|
||||
return {
|
||||
type = "directory",
|
||||
absolute_path = absolute_path,
|
||||
fs_stat = uv.fs_stat(absolute_path),
|
||||
fs_stat = vim.loop.fs_stat(absolute_path),
|
||||
group_next = nil, -- If node is grouped, this points to the next child dir/link node
|
||||
has_children = has_children,
|
||||
name = name,
|
||||
@ -39,7 +38,7 @@ function M.is_executable(parent, absolute_path, ext)
|
||||
return utils.is_wsl_windows_fs_exe(ext)
|
||||
end
|
||||
end
|
||||
return uv.fs_access(absolute_path, "X")
|
||||
return vim.loop.fs_access(absolute_path, "X")
|
||||
end
|
||||
|
||||
function M.file(parent, absolute_path, name)
|
||||
@ -50,7 +49,7 @@ function M.file(parent, absolute_path, name)
|
||||
absolute_path = absolute_path,
|
||||
executable = M.is_executable(parent, absolute_path, ext),
|
||||
extension = ext,
|
||||
fs_stat = uv.fs_stat(absolute_path),
|
||||
fs_stat = vim.loop.fs_stat(absolute_path),
|
||||
name = name,
|
||||
parent = parent,
|
||||
}
|
||||
@ -63,11 +62,11 @@ end
|
||||
-- So we need to check for link_to ~= nil when adding new links to the main tree
|
||||
function M.link(parent, absolute_path, name)
|
||||
--- I dont know if this is needed, because in my understanding, there isn't hard links in windows, but just to be sure i changed it.
|
||||
local link_to = uv.fs_realpath(absolute_path)
|
||||
local link_to = vim.loop.fs_realpath(absolute_path)
|
||||
local open, nodes, has_children, watcher
|
||||
if (link_to ~= nil) and uv.fs_stat(link_to).type == "directory" then
|
||||
local handle = uv.fs_scandir(link_to)
|
||||
has_children = handle and uv.fs_scandir_next(handle) ~= nil
|
||||
if (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory" then
|
||||
local handle = vim.loop.fs_scandir(link_to)
|
||||
has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
||||
open = false
|
||||
nodes = {}
|
||||
watcher = watch.create_watcher(link_to)
|
||||
@ -76,7 +75,7 @@ function M.link(parent, absolute_path, name)
|
||||
return {
|
||||
type = "link",
|
||||
absolute_path = absolute_path,
|
||||
fs_stat = uv.fs_stat(absolute_path),
|
||||
fs_stat = vim.loop.fs_stat(absolute_path),
|
||||
group_next = nil, -- If node is grouped, this points to the next child dir/link node
|
||||
has_children = has_children,
|
||||
link_to = link_to,
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require "nvim-tree.utils"
|
||||
local builders = require "nvim-tree.explorer.node-builders"
|
||||
local common = require "nvim-tree.explorer.common"
|
||||
@ -21,7 +19,7 @@ end
|
||||
|
||||
function M.reload(node, status)
|
||||
local cwd = node.link_to or node.absolute_path
|
||||
local handle = uv.fs_scandir(cwd)
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
if type(handle) == "string" then
|
||||
notify.error(handle)
|
||||
return
|
||||
@ -37,7 +35,7 @@ function M.reload(node, status)
|
||||
local node_ignored = node.git_status == "!!"
|
||||
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
|
||||
while true do
|
||||
local ok, name, t = pcall(uv.fs_scandir_next, handle)
|
||||
local ok, name, t = pcall(vim.loop.fs_scandir_next, handle)
|
||||
if not ok or not name then
|
||||
break
|
||||
end
|
||||
@ -48,7 +46,7 @@ function M.reload(node, status)
|
||||
return stat
|
||||
end
|
||||
|
||||
stat = uv.fs_stat(path)
|
||||
stat = vim.loop.fs_stat(path)
|
||||
return stat
|
||||
end
|
||||
|
||||
@ -69,7 +67,7 @@ function M.reload(node, status)
|
||||
end
|
||||
|
||||
if not nodes_by_path[abs] then
|
||||
if t == "directory" and uv.fs_access(abs, "R") then
|
||||
if t == "directory" and vim.loop.fs_access(abs, "R") then
|
||||
local folder = builders.folder(node, abs, name)
|
||||
nodes_by_path[abs] = folder
|
||||
table.insert(node.nodes, folder)
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local git_utils = require "nvim-tree.git.utils"
|
||||
@ -74,7 +72,7 @@ function M.get_project_root(cwd)
|
||||
return nil
|
||||
end
|
||||
|
||||
local stat, _ = uv.fs_stat(cwd)
|
||||
local stat, _ = vim.loop.fs_stat(cwd)
|
||||
if not stat or stat.type ~= "directory" then
|
||||
return nil
|
||||
end
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
local uv = vim.loop
|
||||
local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
@ -60,9 +59,9 @@ end
|
||||
|
||||
function Runner:_run_git_job()
|
||||
local handle, pid
|
||||
local stdout = uv.new_pipe(false)
|
||||
local stderr = uv.new_pipe(false)
|
||||
local timer = uv.new_timer()
|
||||
local stdout = vim.loop.new_pipe(false)
|
||||
local stderr = vim.loop.new_pipe(false)
|
||||
local timer = vim.loop.new_timer()
|
||||
|
||||
local function on_finish(rc)
|
||||
self.rc = rc or 0
|
||||
@ -79,14 +78,14 @@ function Runner:_run_git_job()
|
||||
handle:close()
|
||||
end
|
||||
|
||||
pcall(uv.kill, pid)
|
||||
pcall(vim.loop.kill, pid)
|
||||
end
|
||||
|
||||
local opts = self:_getopts(stdout, stderr)
|
||||
log.line("git", "running job with timeout %dms", self.timeout)
|
||||
log.line("git", "git %s", table.concat(utils.array_remove_nils(opts.args), " "))
|
||||
|
||||
handle, pid = uv.spawn(
|
||||
handle, pid = vim.loop.spawn(
|
||||
"git",
|
||||
opts,
|
||||
vim.schedule_wrap(function(rc)
|
||||
@ -115,8 +114,8 @@ function Runner:_run_git_job()
|
||||
self:_log_raw_output(data)
|
||||
end
|
||||
|
||||
uv.read_start(stdout, vim.schedule_wrap(manage_stdout))
|
||||
uv.read_start(stderr, vim.schedule_wrap(manage_stderr))
|
||||
vim.loop.read_start(stdout, vim.schedule_wrap(manage_stdout))
|
||||
vim.loop.read_start(stderr, vim.schedule_wrap(manage_stderr))
|
||||
end
|
||||
|
||||
function Runner:_wait()
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local api = vim.api
|
||||
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local view = require "nvim-tree.view"
|
||||
local core = require "nvim-tree.core"
|
||||
@ -19,7 +17,7 @@ function M.get_node_at_cursor()
|
||||
return
|
||||
end
|
||||
|
||||
local cursor = api.nvim_win_get_cursor(view.get_winnr())
|
||||
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr())
|
||||
local line = cursor[1]
|
||||
if view.is_help_ui() then
|
||||
local help_lines = require("nvim-tree.renderer.help").compute_lines()
|
||||
@ -57,7 +55,7 @@ function M.expand_or_collapse(node)
|
||||
end
|
||||
|
||||
function M.set_target_win()
|
||||
local id = api.nvim_get_current_win()
|
||||
local id = vim.api.nvim_get_current_win()
|
||||
local tree_id = view.get_winnr()
|
||||
if tree_id and id == tree_id then
|
||||
M.target_winid = 0
|
||||
@ -81,10 +79,10 @@ local function open_view_and_draw()
|
||||
end
|
||||
|
||||
local function should_hijack_current_buf()
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufname = api.nvim_buf_get_name(bufnr)
|
||||
local bufmodified = api.nvim_buf_get_option(bufnr, "modified")
|
||||
local ft = api.nvim_buf_get_option(bufnr, "ft")
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified")
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
|
||||
|
||||
local should_hijack_unnamed = M.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == ""
|
||||
local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and M.hijack_directories.enable
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local a = vim.api
|
||||
|
||||
local view = require "nvim-tree.view"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local Iterator = require "nvim-tree.iterators.node-iterator"
|
||||
@ -28,9 +26,9 @@ local overlay_winnr = nil
|
||||
local function remove_overlay()
|
||||
if view.View.float.enable and view.View.float.quit_on_focus_loss then
|
||||
-- return to normal nvim-tree float behaviour when filter window is closed
|
||||
a.nvim_create_autocmd("WinLeave", {
|
||||
vim.api.nvim_create_autocmd("WinLeave", {
|
||||
pattern = "NvimTree_*",
|
||||
group = a.nvim_create_augroup("NvimTree", { clear = false }),
|
||||
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
view.close()
|
||||
@ -39,7 +37,7 @@ local function remove_overlay()
|
||||
})
|
||||
end
|
||||
|
||||
a.nvim_win_close(overlay_winnr, { force = true })
|
||||
vim.api.nvim_win_close(overlay_winnr, { force = true })
|
||||
overlay_bufnr = nil
|
||||
overlay_winnr = nil
|
||||
|
||||
@ -85,54 +83,54 @@ end
|
||||
|
||||
local function record_char()
|
||||
vim.schedule(function()
|
||||
M.filter = a.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
|
||||
M.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
|
||||
M.apply_filter()
|
||||
redraw()
|
||||
end)
|
||||
end
|
||||
|
||||
local function configure_buffer_overlay()
|
||||
overlay_bufnr = a.nvim_create_buf(false, true)
|
||||
overlay_bufnr = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
a.nvim_buf_attach(overlay_bufnr, true, {
|
||||
vim.api.nvim_buf_attach(overlay_bufnr, true, {
|
||||
on_lines = record_char,
|
||||
})
|
||||
|
||||
a.nvim_create_autocmd("InsertLeave", {
|
||||
vim.api.nvim_create_autocmd("InsertLeave", {
|
||||
callback = remove_overlay,
|
||||
once = true,
|
||||
})
|
||||
|
||||
a.nvim_buf_set_keymap(overlay_bufnr, "i", "<CR>", "<cmd>stopinsert<CR>", {})
|
||||
vim.api.nvim_buf_set_keymap(overlay_bufnr, "i", "<CR>", "<cmd>stopinsert<CR>", {})
|
||||
end
|
||||
|
||||
local function create_overlay()
|
||||
local min_width = 20
|
||||
if view.View.float.enable then
|
||||
-- don't close nvim-tree float when focus is changed to filter window
|
||||
a.nvim_clear_autocmds {
|
||||
vim.api.nvim_clear_autocmds {
|
||||
event = "WinLeave",
|
||||
pattern = "NvimTree_*",
|
||||
group = a.nvim_create_augroup("NvimTree", { clear = false }),
|
||||
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
|
||||
}
|
||||
|
||||
min_width = min_width - 2
|
||||
end
|
||||
|
||||
configure_buffer_overlay()
|
||||
overlay_winnr = a.nvim_open_win(overlay_bufnr, true, {
|
||||
overlay_winnr = vim.api.nvim_open_win(overlay_bufnr, true, {
|
||||
col = 1,
|
||||
row = 0,
|
||||
relative = "cursor",
|
||||
width = math.max(min_width, a.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2),
|
||||
width = math.max(min_width, vim.api.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2),
|
||||
height = 1,
|
||||
border = "none",
|
||||
style = "minimal",
|
||||
})
|
||||
a.nvim_buf_set_option(overlay_bufnr, "modifiable", true)
|
||||
a.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter })
|
||||
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { M.filter })
|
||||
vim.cmd "startinsert"
|
||||
a.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 })
|
||||
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #M.filter + 1 })
|
||||
end
|
||||
|
||||
function M.start_filtering()
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local M = {
|
||||
config = nil,
|
||||
path = nil,
|
||||
@ -29,7 +27,7 @@ function M.profile_start(fmt, ...)
|
||||
return
|
||||
end
|
||||
M.line("profile", "START " .. (fmt or "???"), ...)
|
||||
return uv.hrtime()
|
||||
return vim.loop.hrtime()
|
||||
end
|
||||
|
||||
--- Write to log file via M.line
|
||||
@ -39,7 +37,7 @@ function M.profile_end(start, fmt, ...)
|
||||
if not M.path or not M.config.types.profile and not M.config.types.all then
|
||||
return
|
||||
end
|
||||
local millis = start and math.modf((uv.hrtime() - start) / 1000000) or -1
|
||||
local millis = start and math.modf((vim.loop.hrtime() - start) / 1000000) or -1
|
||||
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
|
||||
end
|
||||
|
||||
|
||||
@ -1,30 +1,28 @@
|
||||
local M = {}
|
||||
|
||||
local api = vim.api
|
||||
local fn = vim.fn
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local function hide(win)
|
||||
if win then
|
||||
if api.nvim_win_is_valid(win) then
|
||||
api.nvim_win_close(win, true)
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- reduce signcolumn/foldcolumn from window width
|
||||
local function effective_win_width()
|
||||
local win_width = fn.winwidth(0)
|
||||
local win_width = vim.fn.winwidth(0)
|
||||
|
||||
-- return zero if the window cannot be found
|
||||
local win_id = fn.win_getid()
|
||||
local win_id = vim.fn.win_getid()
|
||||
|
||||
if win_id == 0 then
|
||||
return win_width
|
||||
end
|
||||
|
||||
-- if the window does not exist the result is an empty list
|
||||
local win_info = fn.getwininfo(win_id)
|
||||
local win_info = vim.fn.getwininfo(win_id)
|
||||
|
||||
-- check if result table is empty
|
||||
if next(win_info) == nil then
|
||||
@ -35,7 +33,7 @@ local function effective_win_width()
|
||||
end
|
||||
|
||||
local function show()
|
||||
local line_nr = api.nvim_win_get_cursor(0)[1]
|
||||
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
||||
if line_nr == 1 and require("nvim-tree.view").is_root_folder_visible() then
|
||||
return
|
||||
end
|
||||
@ -47,36 +45,36 @@ local function show()
|
||||
return
|
||||
end
|
||||
|
||||
local line = fn.getline "."
|
||||
local leftcol = fn.winsaveview().leftcol
|
||||
local line = vim.fn.getline "."
|
||||
local leftcol = vim.fn.winsaveview().leftcol
|
||||
-- hide full name if left column of node in nvim-tree win is not zero
|
||||
if leftcol ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local text_width = fn.strdisplaywidth(fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||
local win_width = effective_win_width()
|
||||
|
||||
if text_width < win_width then
|
||||
return
|
||||
end
|
||||
|
||||
M.popup_win = api.nvim_open_win(api.nvim_create_buf(false, false), false, {
|
||||
M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, {
|
||||
relative = "win",
|
||||
bufpos = { fn.line "." - 2, 0 },
|
||||
bufpos = { vim.fn.line "." - 2, 0 },
|
||||
width = math.min(text_width, vim.o.columns - 2),
|
||||
height = 1,
|
||||
noautocmd = true,
|
||||
style = "minimal",
|
||||
})
|
||||
|
||||
local ns_id = api.nvim_get_namespaces()["NvimTreeHighlights"]
|
||||
local extmarks = api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 })
|
||||
api.nvim_win_call(M.popup_win, function()
|
||||
fn.setbufline("%", 1, line)
|
||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
|
||||
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = 1 })
|
||||
vim.api.nvim_win_call(M.popup_win, function()
|
||||
vim.fn.setbufline("%", 1, line)
|
||||
for _, extmark in ipairs(extmarks) do
|
||||
local hl = extmark[4]
|
||||
api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col)
|
||||
vim.api.nvim_buf_add_highlight(0, ns_id, hl.hl_group, 0, extmark[3], hl.end_col)
|
||||
end
|
||||
vim.cmd [[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]]
|
||||
end)
|
||||
@ -88,8 +86,8 @@ M.setup = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
local group = api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
@ -99,7 +97,7 @@ M.setup = function(opts)
|
||||
end,
|
||||
})
|
||||
|
||||
api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
|
||||
@ -12,19 +12,17 @@ local Builder = require "nvim-tree.renderer.builder"
|
||||
local live_filter = require "nvim-tree.live-filter"
|
||||
local marks = require "nvim-tree.marks"
|
||||
|
||||
local api = vim.api
|
||||
|
||||
local M = {
|
||||
last_highlights = {},
|
||||
}
|
||||
|
||||
local namespace_id = api.nvim_create_namespace "NvimTreeHighlights"
|
||||
local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
|
||||
|
||||
local function _draw(bufnr, lines, hl, signs)
|
||||
api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
M.render_hl(bufnr, hl)
|
||||
api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.fn.sign_unplace(git.SIGN_GROUP)
|
||||
for _, sign in pairs(signs) do
|
||||
vim.fn.sign_place(0, git.SIGN_GROUP, sign.sign, bufnr, { lnum = sign.lnum, priority = 1 })
|
||||
@ -32,12 +30,12 @@ local function _draw(bufnr, lines, hl, signs)
|
||||
end
|
||||
|
||||
function M.render_hl(bufnr, hl)
|
||||
if not bufnr or not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||
for _, data in ipairs(hl or M.last_highlights) do
|
||||
api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_id, data[1], data[2], data[3], data[4])
|
||||
end
|
||||
end
|
||||
|
||||
@ -50,13 +48,13 @@ local picture_map = {
|
||||
|
||||
function M.draw()
|
||||
local bufnr = view.get_bufnr()
|
||||
if not core.get_explorer() or not bufnr or not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not core.get_explorer() or not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
|
||||
local ps = log.profile_start "draw"
|
||||
|
||||
local cursor = api.nvim_win_get_cursor(view.get_winnr())
|
||||
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr())
|
||||
icon_component.reset_config()
|
||||
|
||||
local lines, hl
|
||||
@ -84,7 +82,7 @@ function M.draw()
|
||||
M.last_highlights = hl
|
||||
|
||||
if cursor and #lines >= cursor[1] then
|
||||
api.nvim_win_set_cursor(view.get_winnr(), cursor)
|
||||
vim.api.nvim_win_set_cursor(view.get_winnr(), cursor)
|
||||
end
|
||||
|
||||
if view.is_help_ui() then
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
local a = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local Iterator = require "nvim-tree.iterators.node-iterator"
|
||||
|
||||
local M = {
|
||||
@ -19,16 +16,16 @@ function M.str_find(haystack, needle)
|
||||
end
|
||||
|
||||
function M.read_file(path)
|
||||
local fd = uv.fs_open(path, "r", 438)
|
||||
local fd = vim.loop.fs_open(path, "r", 438)
|
||||
if not fd then
|
||||
return ""
|
||||
end
|
||||
local stat = uv.fs_fstat(fd)
|
||||
local stat = vim.loop.fs_fstat(fd)
|
||||
if not stat then
|
||||
return ""
|
||||
end
|
||||
local data = uv.fs_read(fd, stat.size, 0)
|
||||
uv.fs_close(fd)
|
||||
local data = vim.loop.fs_read(fd, stat.size, 0)
|
||||
vim.loop.fs_close(fd)
|
||||
return data or ""
|
||||
end
|
||||
|
||||
@ -211,19 +208,19 @@ function M.is_wsl_windows_fs_exe(ext)
|
||||
end
|
||||
|
||||
function M.rename_loaded_buffers(old_path, new_path)
|
||||
for _, buf in pairs(a.nvim_list_bufs()) do
|
||||
if a.nvim_buf_is_loaded(buf) then
|
||||
local buf_name = a.nvim_buf_get_name(buf)
|
||||
for _, buf in pairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(buf) then
|
||||
local buf_name = vim.api.nvim_buf_get_name(buf)
|
||||
local exact_match = buf_name == old_path
|
||||
local child_match = (
|
||||
buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator
|
||||
)
|
||||
if exact_match or child_match then
|
||||
a.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1))
|
||||
vim.api.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1))
|
||||
-- to avoid the 'overwrite existing file' error message on write for
|
||||
-- normal files
|
||||
if a.nvim_buf_get_option(buf, "buftype") == "" then
|
||||
a.nvim_buf_call(buf, function()
|
||||
if vim.api.nvim_buf_get_option(buf, "buftype") == "" then
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
vim.cmd "silent! write!"
|
||||
vim.cmd "edit"
|
||||
end)
|
||||
@ -369,7 +366,7 @@ function M.debounce(context, timeout, callback)
|
||||
timer_stop_close(debouncer.timer)
|
||||
end
|
||||
|
||||
local timer = uv.new_timer()
|
||||
local timer = vim.loop.new_timer()
|
||||
debouncer.timer = timer
|
||||
timer:start(timeout, 0, function()
|
||||
timer_stop_close(timer)
|
||||
@ -457,7 +454,7 @@ function M.is_nvim_tree_buf(bufnr)
|
||||
bufnr = 0
|
||||
end
|
||||
if vim.fn.bufexists(bufnr) then
|
||||
local bufname = a.nvim_buf_get_name(bufnr)
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
if vim.fn.fnamemodify(bufname, ":t"):match "^NvimTree_[0-9]+$" then
|
||||
if vim.bo[bufnr].filetype == "NvimTree" then
|
||||
return true
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
local a = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
local events = require "nvim-tree.events"
|
||||
@ -77,9 +75,9 @@ local function matches_bufnr(bufnr)
|
||||
end
|
||||
|
||||
local function wipe_rogue_buffer()
|
||||
for _, bufnr in ipairs(a.nvim_list_bufs()) do
|
||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then
|
||||
pcall(a.nvim_buf_delete, bufnr, { force = true })
|
||||
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -87,9 +85,9 @@ end
|
||||
local function create_buffer(bufnr)
|
||||
wipe_rogue_buffer()
|
||||
|
||||
local tab = a.nvim_get_current_tabpage()
|
||||
BUFNR_PER_TAB[tab] = bufnr or a.nvim_create_buf(false, false)
|
||||
a.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
|
||||
vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)
|
||||
|
||||
for option, value in pairs(BUFFER_OPTIONS) do
|
||||
vim.bo[M.get_bufnr()][option] = value
|
||||
@ -122,7 +120,7 @@ local move_tbl = {
|
||||
|
||||
-- setup_tabpage sets up the initial state of a tab
|
||||
local function setup_tabpage(tabpage)
|
||||
local winnr = a.nvim_get_current_win()
|
||||
local winnr = vim.api.nvim_get_current_win()
|
||||
M.View.tabpages[tabpage] = vim.tbl_extend("force", M.View.tabpages[tabpage] or tabinitial, { winnr = winnr })
|
||||
end
|
||||
|
||||
@ -143,17 +141,17 @@ end
|
||||
|
||||
local function open_window()
|
||||
if M.View.float.enable then
|
||||
a.nvim_open_win(0, true, open_win_config())
|
||||
vim.api.nvim_open_win(0, true, open_win_config())
|
||||
else
|
||||
a.nvim_command "vsp"
|
||||
vim.api.nvim_command "vsp"
|
||||
M.reposition_window()
|
||||
end
|
||||
setup_tabpage(a.nvim_get_current_tabpage())
|
||||
setup_tabpage(vim.api.nvim_get_current_tabpage())
|
||||
set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
local function is_buf_displayed(buf)
|
||||
return a.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1
|
||||
return vim.api.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1
|
||||
end
|
||||
|
||||
local function get_alt_or_next_buf()
|
||||
@ -162,7 +160,7 @@ local function get_alt_or_next_buf()
|
||||
return alt_buf
|
||||
end
|
||||
|
||||
for _, buf in ipairs(a.nvim_list_bufs()) do
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if is_buf_displayed(buf) then
|
||||
return buf
|
||||
end
|
||||
@ -170,7 +168,7 @@ local function get_alt_or_next_buf()
|
||||
end
|
||||
|
||||
local function switch_buf_if_last_buf()
|
||||
if #a.nvim_list_wins() == 1 then
|
||||
if #vim.api.nvim_list_wins() == 1 then
|
||||
local buf = get_alt_or_next_buf()
|
||||
if buf then
|
||||
vim.cmd("sb" .. buf)
|
||||
@ -182,8 +180,8 @@ end
|
||||
|
||||
-- save_tab_state saves any state that should be preserved across redraws.
|
||||
local function save_tab_state()
|
||||
local tabpage = a.nvim_get_current_tabpage()
|
||||
M.View.cursors[tabpage] = a.nvim_win_get_cursor(M.get_winnr())
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr())
|
||||
end
|
||||
|
||||
function M.close()
|
||||
@ -193,15 +191,15 @@ function M.close()
|
||||
save_tab_state()
|
||||
switch_buf_if_last_buf()
|
||||
local tree_win = M.get_winnr()
|
||||
local current_win = a.nvim_get_current_win()
|
||||
for _, win in pairs(a.nvim_list_wins()) do
|
||||
if tree_win ~= win and a.nvim_win_get_config(win).relative == "" then
|
||||
local current_win = vim.api.nvim_get_current_win()
|
||||
for _, win in pairs(vim.api.nvim_list_wins()) do
|
||||
if tree_win ~= win and vim.api.nvim_win_get_config(win).relative == "" then
|
||||
local prev_win = vim.fn.winnr "#" -- this tab only
|
||||
if tree_win == current_win and prev_win > 0 then
|
||||
a.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
||||
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
||||
end
|
||||
if a.nvim_win_is_valid(tree_win) then
|
||||
a.nvim_win_close(tree_win, true)
|
||||
if vim.api.nvim_win_is_valid(tree_win) then
|
||||
vim.api.nvim_win_close(tree_win, true)
|
||||
end
|
||||
events._dispatch_on_tree_close()
|
||||
return
|
||||
@ -275,7 +273,7 @@ function M.resize(size)
|
||||
end
|
||||
|
||||
local new_size = get_size()
|
||||
a.nvim_win_set_width(M.get_winnr(), new_size)
|
||||
vim.api.nvim_win_set_width(M.get_winnr(), new_size)
|
||||
|
||||
events._dispatch_on_tree_resize(new_size)
|
||||
|
||||
@ -286,19 +284,19 @@ end
|
||||
|
||||
function M.reposition_window()
|
||||
local move_to = move_tbl[M.View.side]
|
||||
a.nvim_command("wincmd " .. move_to)
|
||||
vim.api.nvim_command("wincmd " .. move_to)
|
||||
M.resize()
|
||||
end
|
||||
|
||||
local function set_current_win()
|
||||
local current_tab = a.nvim_get_current_tabpage()
|
||||
M.View.tabpages[current_tab].winnr = a.nvim_get_current_win()
|
||||
local current_tab = vim.api.nvim_get_current_tabpage()
|
||||
M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win()
|
||||
end
|
||||
|
||||
function M.open_in_current_win(opts)
|
||||
opts = opts or { hijack_current_buf = true, resize = true }
|
||||
create_buffer(opts.hijack_current_buf and a.nvim_get_current_buf())
|
||||
setup_tabpage(a.nvim_get_current_tabpage())
|
||||
create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
||||
setup_tabpage(vim.api.nvim_get_current_tabpage())
|
||||
set_current_win()
|
||||
set_window_options_and_buffer()
|
||||
if opts.resize then
|
||||
@ -308,7 +306,7 @@ function M.open_in_current_win(opts)
|
||||
end
|
||||
|
||||
function M.abandon_current_window()
|
||||
local tab = a.nvim_get_current_tabpage()
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
BUFNR_PER_TAB[tab] = nil
|
||||
M.View.tabpages[tab].winnr = nil
|
||||
end
|
||||
@ -316,26 +314,26 @@ end
|
||||
function M.is_visible(opts)
|
||||
if opts and opts.any_tabpage then
|
||||
for _, v in pairs(M.View.tabpages) do
|
||||
if v.winnr and a.nvim_win_is_valid(v.winnr) then
|
||||
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
return M.get_winnr() ~= nil and a.nvim_win_is_valid(M.get_winnr())
|
||||
return M.get_winnr() ~= nil and vim.api.nvim_win_is_valid(M.get_winnr())
|
||||
end
|
||||
|
||||
function M.set_cursor(opts)
|
||||
if M.is_visible() then
|
||||
pcall(a.nvim_win_set_cursor, M.get_winnr(), opts)
|
||||
pcall(vim.api.nvim_win_set_cursor, M.get_winnr(), opts)
|
||||
end
|
||||
end
|
||||
|
||||
function M.focus(winnr, open_if_closed)
|
||||
local wnr = winnr or M.get_winnr()
|
||||
|
||||
if a.nvim_win_get_tabpage(wnr or 0) ~= a.nvim_win_get_tabpage(0) then
|
||||
if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then
|
||||
M.close()
|
||||
M.open()
|
||||
wnr = M.get_winnr()
|
||||
@ -343,12 +341,12 @@ function M.focus(winnr, open_if_closed)
|
||||
M.open()
|
||||
end
|
||||
|
||||
a.nvim_set_current_win(wnr)
|
||||
vim.api.nvim_set_current_win(wnr)
|
||||
end
|
||||
|
||||
--- Restores the state of a NvimTree window if it was initialized before.
|
||||
function M.restore_tab_state()
|
||||
local tabpage = a.nvim_get_current_tabpage()
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
M.set_cursor(M.View.cursors[tabpage])
|
||||
end
|
||||
|
||||
@ -356,7 +354,7 @@ end
|
||||
---@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||
---@return number
|
||||
function M.get_winnr(tabpage)
|
||||
tabpage = tabpage or a.nvim_get_current_tabpage()
|
||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
||||
local tabinfo = M.View.tabpages[tabpage]
|
||||
if tabinfo ~= nil then
|
||||
return tabinfo.winnr
|
||||
@ -366,14 +364,14 @@ end
|
||||
--- Returns the current nvim tree bufnr
|
||||
---@return number
|
||||
function M.get_bufnr()
|
||||
return BUFNR_PER_TAB[a.nvim_get_current_tabpage()]
|
||||
return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()]
|
||||
end
|
||||
|
||||
--- Checks if nvim-tree is displaying the help ui within the tabpage specified
|
||||
---@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||
---@return number
|
||||
function M.is_help_ui(tabpage)
|
||||
tabpage = tabpage or a.nvim_get_current_tabpage()
|
||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
||||
local tabinfo = M.View.tabpages[tabpage]
|
||||
if tabinfo ~= nil then
|
||||
return tabinfo.help
|
||||
@ -381,12 +379,12 @@ function M.is_help_ui(tabpage)
|
||||
end
|
||||
|
||||
function M.toggle_help(tabpage)
|
||||
tabpage = tabpage or a.nvim_get_current_tabpage()
|
||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
||||
M.View.tabpages[tabpage].help = not M.View.tabpages[tabpage].help
|
||||
end
|
||||
|
||||
function M.is_buf_valid(bufnr)
|
||||
return bufnr and a.nvim_buf_is_valid(bufnr) and a.nvim_buf_is_loaded(bufnr)
|
||||
return bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)
|
||||
end
|
||||
|
||||
function M._prevent_buffer_override()
|
||||
@ -397,10 +395,10 @@ function M._prevent_buffer_override()
|
||||
-- because this event needs to be run on bufWipeout.
|
||||
-- Otherwise the curwin/curbuf would match the view buffer and the view window.
|
||||
vim.schedule(function()
|
||||
local curwin = a.nvim_get_current_win()
|
||||
local curwinconfig = a.nvim_win_get_config(curwin)
|
||||
local curbuf = a.nvim_win_get_buf(curwin)
|
||||
local bufname = a.nvim_buf_get_name(curbuf)
|
||||
local curwin = vim.api.nvim_get_current_win()
|
||||
local curwinconfig = vim.api.nvim_win_get_config(curwin)
|
||||
local curbuf = vim.api.nvim_win_get_buf(curwin)
|
||||
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
||||
|
||||
if not bufname:match "NvimTree" then
|
||||
for i, tabpage in ipairs(M.View.tabpages) do
|
||||
@ -420,7 +418,7 @@ function M._prevent_buffer_override()
|
||||
vim.cmd "setlocal nowinfixheight"
|
||||
M.open { focus_tree = false }
|
||||
require("nvim-tree.renderer").draw()
|
||||
pcall(a.nvim_win_close, curwin, { force = true })
|
||||
pcall(vim.api.nvim_win_close, curwin, { force = true })
|
||||
|
||||
-- to handle opening a file using :e when nvim-tree is on floating mode
|
||||
-- falling back to the current window instead of creating a new one
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
local uv = vim.loop
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local log = require "nvim-tree.log"
|
||||
@ -45,7 +44,7 @@ function Event:start()
|
||||
|
||||
local rc, _, name
|
||||
|
||||
self._fs_event, _, name = uv.new_fs_event()
|
||||
self._fs_event, _, name = vim.loop.new_fs_event()
|
||||
if not self._fs_event then
|
||||
self._fs_event = nil
|
||||
notify.warn(string.format("Could not initialize an fs_event watcher for path %s : %s", self._path, name))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user