fix: replace vim.* "requires" with explicit calls to vim functions (#1701)

This commit is contained in:
Alexander Courtis
2022-11-06 10:37:33 +11:00
committed by GitHub
parent 6d6a44626d
commit 8cc369695b
30 changed files with 263 additions and 321 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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