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

View File

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

View File

@@ -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 = {},

View File

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

View File

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