Skip to content

chore: resolve undefined-field warnings, fix link git statuses, rewrite devicons #2968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 100 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
8859bbb
add todo
alex-courtis Oct 11, 2024
98ca98c
refactor(#2886): multi instance: node class refactoring: extract link…
alex-courtis Oct 11, 2024
893957a
safer git_status_dir
alex-courtis Oct 11, 2024
03f9dd2
refactor(#2886): multi instance: node class refactoring: DirectoryNod…
alex-courtis Oct 13, 2024
fb2070d
Merge branch 'master' into node-classes-feature-branch-2
alex-courtis Oct 19, 2024
8331a24
refactor(#2886): multi instance: node group functions refactoring (#2…
alex-courtis Oct 20, 2024
0992969
move lib.get_cursor_position to Explorer
alex-courtis Oct 20, 2024
7324fb1
move lib.get_node_at_cursor to Explorer
alex-courtis Oct 21, 2024
8994c1e
move lib.get_nodes to Explorer
alex-courtis Oct 21, 2024
5830585
move place_cursor_on_node to Explorer
alex-courtis Oct 21, 2024
e2e6b2b
resolve resource leak in purge_all_state
alex-courtis Oct 21, 2024
ff85d80
move many autocommands into Explorer
alex-courtis Oct 21, 2024
a44544a
Merge branch 'master' into 2941-move-lib-to-explorer
alex-courtis Oct 25, 2024
4c9c885
post merge tidy
alex-courtis Oct 25, 2024
7fd4cc8
Merge remote-tracking branch 'origin/master' into 2941-move-lib-to-ex…
alex-courtis Oct 25, 2024
e115199
chore: resolve undefined-field
alex-courtis Oct 25, 2024
dd937d0
chore: resolve undefined-field
alex-courtis Oct 25, 2024
64e0c90
chore: resolve undefined-field
alex-courtis Oct 25, 2024
6aba4a8
chore: resolve undefined-field
alex-courtis Oct 25, 2024
7548dfd
chore: resolve undefined-field
alex-courtis Oct 25, 2024
e7b9c71
chore: resolve undefined-field
alex-courtis Oct 25, 2024
e9e4bcd
chore: resolve undefined-field
alex-courtis Oct 25, 2024
4ba0db7
Revert "chore: resolve undefined-field"
alex-courtis Oct 25, 2024
1e18892
chore: resolve undefined-field
alex-courtis Oct 25, 2024
2a98d56
chore: resolve undefined-field
alex-courtis Oct 25, 2024
ab4f769
chore: resolve undefined-field
alex-courtis Oct 25, 2024
1c812ae
chore: resolve undefined-field
alex-courtis Oct 25, 2024
179c2e2
chore: resolve undefined-field
alex-courtis Oct 25, 2024
8128fed
chore: resolve undefined-field
alex-courtis Oct 26, 2024
7fdca30
chore: resolve undefined-field
alex-courtis Oct 26, 2024
e61b16d
chore: resolve undefined-field
alex-courtis Oct 26, 2024
3d00128
chore: resolve undefined-field
alex-courtis Oct 26, 2024
568d0f1
chore: resolve undefined-field
alex-courtis Oct 26, 2024
3218d96
chore: resolve undefined-field
alex-courtis Oct 26, 2024
868a5ef
chore: resolve undefined-field
alex-courtis Oct 26, 2024
d631ee1
chore: resolve undefined-field
alex-courtis Oct 26, 2024
bb23127
chore: resolve undefined-field
alex-courtis Oct 26, 2024
d19f68b
chore: resolve undefined-field
alex-courtis Oct 26, 2024
9311cfb
chore: resolve undefined-field
alex-courtis Oct 26, 2024
e0d737d
chore: resolve undefined-field
alex-courtis Oct 26, 2024
52ff301
chore: resolve undefined-field
alex-courtis Oct 26, 2024
d663059
chore: resolve undefined-field
alex-courtis Oct 26, 2024
3595418
chore: resolve undefined-field
alex-courtis Oct 26, 2024
558d90d
chore: resolve undefined-field
alex-courtis Oct 26, 2024
eacb610
chore: resolve undefined-field
alex-courtis Oct 26, 2024
5290897
chore: resolve undefined-field
alex-courtis Oct 26, 2024
c883df9
chore: resolve undefined-field
alex-courtis Oct 26, 2024
aa161a0
chore: resolve undefined-field
alex-courtis Oct 26, 2024
44281f7
chore: resolve undefined-field
alex-courtis Oct 26, 2024
009b2c9
chore: resolve undefined-field
alex-courtis Oct 26, 2024
622a8d1
chore: resolve undefined-field
alex-courtis Oct 26, 2024
1f041c3
Merge branch 'master' into chore-undefined-field
alex-courtis Oct 26, 2024
bed7a07
chore: resolve undefined-field
alex-courtis Oct 26, 2024
c684104
Merge remote-tracking branch 'origin/master' into chore-undefined-field
alex-courtis Oct 26, 2024
5c46c9c
chore: resolve undefined-field
alex-courtis Oct 27, 2024
e82db1c
chore: resolve undefined-field
alex-courtis Oct 27, 2024
a16e67f
Revert "chore: resolve undefined-field"
alex-courtis Oct 27, 2024
2fba44f
chore: resolve undefined-field
alex-courtis Oct 27, 2024
5647bc3
Merge branch 'master' into chore-undefined-field
alex-courtis Oct 27, 2024
9b36527
chore: class new is now generic
alex-courtis Oct 28, 2024
46725da
Merge remote-tracking branch 'origin/master' into chore-undefined-field
alex-courtis Oct 28, 2024
4372e6a
chore: resolve undefined-field
alex-courtis Oct 28, 2024
a4a6e6c
chore: resolve undefined-field
alex-courtis Oct 28, 2024
142cb30
chore: resolve undefined-field
alex-courtis Oct 28, 2024
4aba93b
chore: resolve undefined-field
alex-courtis Oct 28, 2024
1c8b343
chore: resolve undefined-field
alex-courtis Oct 28, 2024
c8b6848
chore: resolve undefined-field
alex-courtis Oct 28, 2024
caed010
chore: resolve undefined-field
alex-courtis Oct 28, 2024
a789224
chore: resolve undefined-field
alex-courtis Oct 28, 2024
e5ac77b
chore: resolve undefined-field
alex-courtis Oct 28, 2024
f6e238b
chore: resolve undefined-field
alex-courtis Oct 28, 2024
3ec180e
chore: resolve undefined-field
alex-courtis Oct 28, 2024
4303f25
Merge remote-tracking branch 'origin/master' into chore-undefined-field
alex-courtis Oct 28, 2024
217370b
chore: resolve undefined-field
alex-courtis Oct 28, 2024
dd42701
Merge remote-tracking branch 'origin/master' into chore-undefined-field
alex-courtis Oct 29, 2024
e38c387
chore: resolve undefined-field
alex-courtis Oct 29, 2024
0e9b844
chore: resolve undefined-field
alex-courtis Oct 29, 2024
05f4376
Revert "chore: resolve undefined-field"
alex-courtis Oct 29, 2024
31545f2
move icon builders into node classes
alex-courtis Oct 29, 2024
a035ba5
move icon builders into node classes
alex-courtis Oct 29, 2024
8609037
chore: resolve undefined-field
alex-courtis Oct 29, 2024
afc01dd
chore: resolve undefined-field
alex-courtis Oct 29, 2024
3ec276c
chore: resolve undefined-field
alex-courtis Oct 29, 2024
87932dc
chore: resolve undefined-field
alex-courtis Oct 29, 2024
33333a0
chore: resolve undefined-field
alex-courtis Oct 29, 2024
7988cb9
chore: resolve undefined-field
alex-courtis Oct 29, 2024
962f1ef
move folder specifics from icons to Directory
alex-courtis Oct 29, 2024
0eb05a2
move folder specifics from icons to Directory
alex-courtis Nov 2, 2024
8053244
move folder specifics from icons to Directory
alex-courtis Nov 2, 2024
612f787
move folder specifics from icons to Directory
alex-courtis Nov 2, 2024
b5f2b3a
move file specifics from icons to File
alex-courtis Nov 2, 2024
82c868f
clean up sorters
alex-courtis Nov 2, 2024
1e1a273
chore: resolve undefined-field
alex-courtis Nov 2, 2024
3b68b94
Merge branch 'master' into chore-undefined-field
alex-courtis Nov 2, 2024
0acbc79
tidy hl icon name
alex-courtis Nov 2, 2024
6818306
file devicon uses library to fall back
alex-courtis Nov 3, 2024
ea69ab3
file devicon uses library to fall back
alex-courtis Nov 3, 2024
e8fc9ec
Merge remote-tracking branch 'origin/master' into chore-undefined-field
alex-courtis Nov 3, 2024
112b1b6
file devicon uses library to fall back
alex-courtis Nov 3, 2024
571c5e7
Merge branch 'master' into chore-undefined-field
alex-courtis Nov 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,6 @@ function M.setup(conf)
require("nvim-tree.buffers").setup(opts)
require("nvim-tree.help").setup(opts)
require("nvim-tree.watcher").setup(opts)
if M.config.renderer.icons.show.file and pcall(require, "nvim-web-devicons") then
require("nvim-web-devicons").setup()
end

setup_autocommands(opts)

Expand Down
175 changes: 81 additions & 94 deletions lua/nvim-tree/actions/fs/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,34 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn

local DirectoryNode = require("nvim-tree.node.directory")

---@enum ACTION
local ACTION = {
copy = "copy",
cut = "cut",
}
---@alias ClipboardAction "copy" | "cut"
---@alias ClipboardData table<ClipboardAction, Node[]>

---@alias ClipboardActionFn fun(source: string, dest: string): boolean, string?

---@class Clipboard to handle all actions.fs clipboard API
---@field config table hydrated user opts.filters
---@field private explorer Explorer
---@field private data table<ACTION, Node[]>
---@field private data ClipboardData
---@field private clipboard_name string
---@field private reg string
local Clipboard = {}

---@param opts table user options
---@param explorer Explorer
---@return Clipboard
function Clipboard:new(opts, explorer)
---@type Clipboard
local o = {
explorer = explorer,
data = {
[ACTION.copy] = {},
[ACTION.cut] = {},
copy = {},
cut = {},
},
clipboard_name = opts.actions.use_system_clipboard and "system" or "neovim",
reg = opts.actions.use_system_clipboard and "+" or "1",
config = {
filesystem_watchers = opts.filesystem_watchers,
actions = opts.actions,
},
}

Expand All @@ -47,13 +50,11 @@ end
---@return boolean
---@return string|nil
local function do_copy(source, destination)
local source_stats, handle
local success, errmsg
local source_stats, err = vim.loop.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
log.line("copy_paste", "do_copy fs_stat '%s' failed '%s'", source, err)
return false, err
end

log.line("copy_paste", "do_copy %s '%s' -> '%s'", source_stats.type, source, destination)
Expand All @@ -64,25 +65,28 @@ local function do_copy(source, destination)
end

if source_stats.type == "file" then
success, errmsg = vim.loop.fs_copyfile(source, destination)
local success
success, err = vim.loop.fs_copyfile(source, destination)
if not success then
log.line("copy_paste", "do_copy fs_copyfile failed '%s'", errmsg)
return false, errmsg
log.line("copy_paste", "do_copy fs_copyfile failed '%s'", err)
return false, err
end
return true
elseif source_stats.type == "directory" then
handle, errmsg = vim.loop.fs_scandir(source)
local handle
handle, err = vim.loop.fs_scandir(source)
if type(handle) == "string" then
return false, handle
elseif not handle then
log.line("copy_paste", "do_copy fs_scandir '%s' failed '%s'", source, errmsg)
return false, errmsg
log.line("copy_paste", "do_copy fs_scandir '%s' failed '%s'", source, err)
return false, err
end

success, errmsg = vim.loop.fs_mkdir(destination, source_stats.mode)
local success
success, err = 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
log.line("copy_paste", "do_copy fs_mkdir '%s' failed '%s'", destination, err)
return false, err
end

while true do
Expand All @@ -93,44 +97,42 @@ local function do_copy(source, destination)

local new_name = utils.path_join({ source, name })
local new_destination = utils.path_join({ destination, name })
success, errmsg = do_copy(new_name, new_destination)
success, err = do_copy(new_name, new_destination)
if not success then
return false, errmsg
return false, err
end
end
else
errmsg = string.format("'%s' illegal file type '%s'", source, source_stats.type)
log.line("copy_paste", "do_copy %s", errmsg)
return false, errmsg
err = string.format("'%s' illegal file type '%s'", source, source_stats.type)
log.line("copy_paste", "do_copy %s", err)
return false, err
end

return true
end

---@param source string
---@param dest string
---@param action ACTION
---@param action_fn fun(source: string, dest: string)
---@param action ClipboardAction
---@param action_fn ClipboardActionFn
---@return boolean|nil -- success
---@return string|nil -- error message
local function do_single_paste(source, dest, action, action_fn)
local dest_stats
local success, errmsg, errcode
local notify_source = notify.render_path(source)

log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest)

dest_stats, errmsg, errcode = vim.loop.fs_stat(dest)
if not dest_stats and errcode ~= "ENOENT" then
notify.error("Could not " .. action .. " " .. notify_source .. " - " .. (errmsg or "???"))
return false, errmsg
local dest_stats, err, err_name = vim.loop.fs_stat(dest)
if not dest_stats and err_name ~= "ENOENT" then
notify.error("Could not " .. action .. " " .. notify_source .. " - " .. (err or "???"))
return false, err
end

local function on_process()
success, errmsg = action_fn(source, dest)
local success, error = action_fn(source, dest)
if not success then
notify.error("Could not " .. action .. " " .. notify_source .. " - " .. (errmsg or "???"))
return false, errmsg
notify.error("Could not " .. action .. " " .. notify_source .. " - " .. (error or "???"))
return false, error
end

find_file(utils.path_remove_trailing(dest))
Expand Down Expand Up @@ -173,7 +175,7 @@ local function do_single_paste(source, dest, action, action_fn)
end

---@param node Node
---@param clip table
---@param clip ClipboardData
local function toggle(node, clip)
if node.name == ".." then
return
Expand All @@ -191,49 +193,52 @@ end

---Clear copied and cut
function Clipboard:clear_clipboard()
self.data[ACTION.copy] = {}
self.data[ACTION.cut] = {}
self.data.copy = {}
self.data.cut = {}
notify.info("Clipboard has been emptied.")
self.explorer.renderer:draw()
end

---Copy one node
---@param node Node
function Clipboard:copy(node)
utils.array_remove(self.data[ACTION.cut], node)
toggle(node, self.data[ACTION.copy])
utils.array_remove(self.data.cut, node)
toggle(node, self.data.copy)
self.explorer.renderer:draw()
end

---Cut one node
---@param node Node
function Clipboard:cut(node)
utils.array_remove(self.data[ACTION.copy], node)
toggle(node, self.data[ACTION.cut])
utils.array_remove(self.data.copy, node)
toggle(node, self.data.cut)
self.explorer.renderer:draw()
end

---Paste cut or cop
---@private
---@param node Node
---@param action ACTION
---@param action_fn fun(source: string, dest: string)
---@param action ClipboardAction
---@param action_fn ClipboardActionFn
function Clipboard:do_paste(node, action, action_fn)
if node.name == ".." then
node = self.explorer
elseif node:is(DirectoryNode) then
node = node:last_group_node()
else
local dir = node:as(DirectoryNode)
if dir then
node = dir:last_group_node()
end
end
local clip = self.data[action]
if #clip == 0 then
return
end

local destination = node.absolute_path
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 .. " " .. notify.render_path(destination) .. " - " .. (errmsg or "???"))
local stats, err, err_name = vim.loop.fs_stat(destination)
if not stats and err_name ~= "ENOENT" then
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, err)
notify.error("Could not " .. action .. " " .. notify.render_path(destination) .. " - " .. (err or "???"))
return
end
local is_dir = stats and stats.type == "directory"
Expand Down Expand Up @@ -278,24 +283,24 @@ end
---Paste cut (if present) or copy (if present)
---@param node Node
function Clipboard:paste(node)
if self.data[ACTION.cut][1] ~= nil then
self:do_paste(node, ACTION.cut, do_cut)
elseif self.data[ACTION.copy][1] ~= nil then
self:do_paste(node, ACTION.copy, do_copy)
if self.data.cut[1] ~= nil then
self:do_paste(node, "cut", do_cut)
elseif self.data.copy[1] ~= nil then
self:do_paste(node, "copy", do_copy)
end
end

function Clipboard:print_clipboard()
local content = {}
if #self.data[ACTION.cut] > 0 then
if #self.data.cut > 0 then
table.insert(content, "Cut")
for _, node in pairs(self.data[ACTION.cut]) do
for _, node in pairs(self.data.cut) do
table.insert(content, " * " .. (notify.render_path(node.absolute_path)))
end
end
if #self.data[ACTION.copy] > 0 then
if #self.data.copy > 0 then
table.insert(content, "Copy")
for _, node in pairs(self.data[ACTION.copy]) do
for _, node in pairs(self.data.copy) do
table.insert(content, " * " .. (notify.render_path(node.absolute_path)))
end
end
Expand All @@ -305,65 +310,45 @@ end

---@param content string
function Clipboard:copy_to_reg(content)
local clipboard_name
local reg
if self.config.actions.use_system_clipboard == true then
clipboard_name = "system"
reg = "+"
else
clipboard_name = "neovim"
reg = "1"
end

-- manually firing TextYankPost does not set vim.v.event
-- workaround: create a scratch buffer with the clipboard contents and send a yank command
local temp_buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_text(temp_buf, 0, 0, 0, 0, { content })
vim.api.nvim_buf_call(temp_buf, function()
vim.cmd(string.format('normal! "%sy$', reg))
vim.cmd(string.format('normal! "%sy$', self.reg))
end)
vim.api.nvim_buf_delete(temp_buf, {})

notify.info(string.format("Copied %s to %s clipboard!", content, clipboard_name))
notify.info(string.format("Copied %s to %s clipboard!", content, self.clipboard_name))
end

---@param node Node
function Clipboard:copy_filename(node)
local content

if node.name == ".." then
-- root
content = vim.fn.fnamemodify(self.explorer.absolute_path, ":t")
self:copy_to_reg(vim.fn.fnamemodify(self.explorer.absolute_path, ":t"))
else
-- node
content = node.name
self:copy_to_reg(node.name)
end

self:copy_to_reg(content)
end

---@param node Node
function Clipboard:copy_basename(node)
local content

if node.name == ".." then
-- root
content = vim.fn.fnamemodify(self.explorer.absolute_path, ":t:r")
self:copy_to_reg(vim.fn.fnamemodify(self.explorer.absolute_path, ":t:r"))
else
-- node
content = vim.fn.fnamemodify(node.name, ":r")
self:copy_to_reg(vim.fn.fnamemodify(node.name, ":r"))
end

self:copy_to_reg(content)
end

---@param node Node
function Clipboard:copy_path(node)
local content

if node.name == ".." then
-- root
content = utils.path_add_trailing("")
self:copy_to_reg(utils.path_add_trailing(""))
else
-- node
local absolute_path = node.absolute_path
Expand All @@ -373,10 +358,12 @@ function Clipboard:copy_path(node)
end

local relative_path = utils.path_relative(absolute_path, cwd)
content = node.nodes ~= nil and utils.path_add_trailing(relative_path) or relative_path
if node:is(DirectoryNode) then
self:copy_to_reg(utils.path_add_trailing(relative_path))
else
self:copy_to_reg(relative_path)
end
end

self:copy_to_reg(content)
end

---@param node Node
Expand All @@ -394,14 +381,14 @@ end
---@param node Node
---@return boolean
function Clipboard:is_cut(node)
return vim.tbl_contains(self.data[ACTION.cut], node)
return vim.tbl_contains(self.data.cut, node)
end

---Node is copied. Will not be cut.
---@param node Node
---@return boolean
function Clipboard:is_copied(node)
return vim.tbl_contains(self.data[ACTION.copy], node)
return vim.tbl_contains(self.data.copy, node)
end

return Clipboard
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

---@param node Node?
function M.fn(node)
node = node or core.get_explorer() --[[@as Node]]
node = node or core.get_explorer()
if not node then
return
end
Expand Down
Loading
Loading