refacto: ubiquitous language renaming

BREAKING
- rename all 'entry' to 'node' or '_node' if shadowing
- rename all 'entries' to 'nodes'
This commit is contained in:
kiyan
2022-02-05 18:10:09 +01:00
parent 10b4a97f7f
commit 4a9e53143b
13 changed files with 113 additions and 113 deletions

View File

@@ -6,13 +6,13 @@ function M.fn()
if node.open then
node.open = false
end
if node.entries then
iter(node.entries)
if node.nodes then
iter(node.nodes)
end
end
end
iter(require'nvim-tree.lib'.Tree.entries)
iter(require'nvim-tree.lib'.Tree.nodes)
require'nvim-tree.lib'.redraw()
end

View File

@@ -68,8 +68,8 @@ end
local function add_to_clipboard(node, clip)
if node.name == '..' then return end
for idx, entry in ipairs(clip) do
if entry.absolute_path == node.absolute_path then
for idx, _node in ipairs(clip) do
if _node.absolute_path == node.absolute_path then
table.remove(clip, idx)
return a.nvim_out_write(node.absolute_path..' removed to clipboard.\n')
end
@@ -102,9 +102,9 @@ local function do_paste(node, action_type, action_fn)
destination = vim.fn.fnamemodify(destination, ':p:h:h')
end
for _, entry in ipairs(clip) do
local dest = utils.path_join({destination, entry.name })
do_single_paste(entry.absolute_path, dest, action_type, action_fn)
for _, _node in ipairs(clip) do
local dest = utils.path_join({destination, _node.name })
do_single_paste(_node.absolute_path, dest, action_type, action_fn)
end
clipboard[action_type] = {}
@@ -159,13 +159,13 @@ end
function M.copy_path(node)
local absolute_path = node.absolute_path
local relative_path = utils.path_relative(absolute_path, lib.Tree.cwd)
local content = node.entries ~= nil and utils.path_add_trailing(relative_path) or relative_path
local content = node.nodes ~= nil and utils.path_add_trailing(relative_path) or relative_path
return copy_to_clipboard(content)
end
function M.copy_absolute_path(node)
local absolute_path = node.absolute_path
local content = node.entries ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
local content = node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
return copy_to_clipboard(content)
end

View File

@@ -9,7 +9,7 @@ local M = {}
local function focus_file(file)
local _, i = utils.find_node(
lib.Tree.entries,
lib.Tree.nodes,
function(node) return node.absolute_path == file end
)
require'nvim-tree.view'.set_cursor({i+1, 1})
@@ -33,7 +33,7 @@ local function create_file(file)
events._dispatch_file_created(file)
end
local function get_num_entries(iter)
local function get_num_nodes(iter)
local i = 0
for _ in iter do
i = i + 1
@@ -43,7 +43,7 @@ end
local function get_containing_folder(node)
local is_open = vim.g.nvim_tree_create_in_closed_folder == 1 or node.open
if node.entries ~= nil and is_open then
if node.nodes ~= nil and is_open then
return utils.path_add_trailing(node.absolute_path)
end
local node_name_size = #(node.name or '')
@@ -62,7 +62,7 @@ function M.fn(node)
if node.name == '..' then
node = {
absolute_path = lib.Tree.cwd,
entries = lib.Tree.entries,
nodes = lib.Tree.nodes,
open = true,
}
end
@@ -72,12 +72,12 @@ function M.fn(node)
if not file then return end
-- create a folder for each path element if the folder does not exist
-- if the answer ends with a /, create a file for the last entry
-- if the answer ends with a /, create a file for the last path element
local is_last_path_file = not file:match(utils.path_separator..'$')
local path_to_create = ''
local idx = 0
local num_entries = get_num_entries(utils.path_split(utils.path_remove_trailing(file)))
local num_nodes = get_num_nodes(utils.path_split(utils.path_remove_trailing(file)))
local is_error = false
for path in utils.path_split(file) do
idx = idx + 1
@@ -87,7 +87,7 @@ function M.fn(node)
else
path_to_create = utils.path_join({path_to_create, p})
end
if is_last_path_file and idx == num_entries then
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)

View File

@@ -82,7 +82,7 @@ local keypress_funcs = {
if node.name == '..' then
return
end
if node.entries ~= nil then
if node.nodes ~= nil then
return lib.expand_or_collapse(node)
end
return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path)
@@ -107,15 +107,15 @@ function M.on_keypress(action)
if node.name == ".." then
return require'nvim-tree.actions.change-dir'.fn("..")
elseif action == "cd" and node.entries ~= nil then
elseif action == "cd" and node.nodes ~= nil then
return require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
elseif action == "cd" then
return
end
if node.link_to and not node.entries then
if node.link_to and not node.nodes then
require'nvim-tree.actions.open-file'.fn(action, node.link_to)
elseif node.entries ~= nil then
elseif node.nodes ~= nil then
lib.expand_or_collapse(node)
else
require'nvim-tree.actions.open-file'.fn(action, node.absolute_path)

View File

@@ -13,16 +13,16 @@ local function get_line_from_node(node, find_parent)
end
local line = 2
local function iter(entries, recursive)
for _, entry in ipairs(entries) do
local n = lib().get_last_group_node(entry)
local function iter(nodes, recursive)
for _, _node in ipairs(nodes) do
local n = lib().get_last_group_node(_node)
if node_path == n.absolute_path then
return line, entry
return line, _node
end
line = line + 1
if entry.open == true and recursive then
local _, child = iter(entry.entries, recursive)
if _node.open == true and recursive then
local _, child = iter(_node.nodes, recursive)
if child ~= nil then return line, child end
end
end
@@ -42,7 +42,7 @@ function M.parent_node(node, should_close)
node.open = false
altered_tree = true
else
local line, parent = iter(lib().Tree.entries, true)
local line, parent = iter(lib().Tree.nodes, true)
if parent == nil then
line = 1
elseif should_close then
@@ -69,9 +69,9 @@ function M.sibling(direction)
local line = 0
local parent, _
-- Check if current node is already at root entries
for index, entry in ipairs(lib().Tree.entries) do
if node_path == entry.absolute_path then
-- Check if current node is already at root nodes
for index, _node in ipairs(lib().Tree.nodes) do
if node_path == _node.absolute_path then
line = index
end
end
@@ -79,9 +79,9 @@ function M.sibling(direction)
if line > 0 then
parent = lib().Tree
else
_, parent = iter(lib().Tree.entries, true)
if parent ~= nil and #parent.entries > 1 then
line, _ = get_line_from_node(node)(parent.entries)
_, parent = iter(lib().Tree.nodes, true)
if parent ~= nil and #parent.nodes > 1 then
line, _ = get_line_from_node(node)(parent.nodes)
end
-- Ignore parent line count
@@ -91,12 +91,12 @@ function M.sibling(direction)
local index = line + direction
if index < 1 then
index = 1
elseif index > #parent.entries then
index = #parent.entries
elseif index > #parent.nodes then
index = #parent.nodes
end
local target_node = parent.entries[index]
local target_node = parent.nodes[index]
line, _ = get_line_from_node(target_node)(lib().Tree.entries, true)
line, _ = get_line_from_node(target_node)(lib().Tree.nodes, true)
view.set_cursor({line, 0})
end
end

View File

@@ -58,7 +58,7 @@ function M.fn(node)
local ans = utils.get_user_input_char()
utils.clear_prompt()
if ans:match('^y') then
if node.entries ~= nil and not node.link_to then
if node.nodes ~= nil and not node.link_to then
local success = remove_dir(node.absolute_path)
if not success then
return a.nvim_err_writeln('Could not remove '..node.name)

View File

@@ -61,7 +61,7 @@ function M.fn(node)
-- trashing
if is_confirmed then
if node.entries ~= nil and not node.link_to then
if node.nodes ~= nil and not node.link_to then
trash_path(function()
events._dispatch_folder_removed(node.absolute_path)
lib.refresh_tree()