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 1 commit
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
Prev Previous commit
Next Next commit
chore: resolve undefined-field
  • Loading branch information
alex-courtis committed Oct 26, 2024
commit d663059c3e419e6597fc0aa4430f725a278ee1ee
7 changes: 4 additions & 3 deletions lua/nvim-tree/explorer/watch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ function M.create_watcher(node)
return nil
end

---@param watcher Watcher
local function callback(watcher)
log.line("watcher", "node event scheduled refresh %s", watcher.context)
utils.debounce(watcher.context, M.config.filesystem_watchers.debounce_delay, function()
log.line("watcher", "node event scheduled refresh %s", watcher.data.context)
utils.debounce(watcher.data.context, M.config.filesystem_watchers.debounce_delay, function()
if watcher.destroyed then
return
end
Expand All @@ -82,7 +83,7 @@ function M.create_watcher(node)
end

M.uid = M.uid + 1
return Watcher:new(path, nil, callback, {
return Watcher:create(path, nil, callback, {
context = "explorer:watch:" .. path .. ":" .. M.uid,
})
end
Expand Down
9 changes: 5 additions & 4 deletions lua/nvim-tree/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,19 @@ function M.load_project_status(path)
if M.config.filesystem_watchers.enable then
log.line("watcher", "git start")

---@param w Watcher
local callback = function(w)
log.line("watcher", "git event scheduled '%s'", w.toplevel)
utils.debounce("git:watcher:" .. w.toplevel, M.config.filesystem_watchers.debounce_delay, function()
log.line("watcher", "git event scheduled '%s'", w.data.toplevel)
utils.debounce("git:watcher:" .. w.data.toplevel, M.config.filesystem_watchers.debounce_delay, function()
if w.destroyed then
return
end
reload_tree_at(w.toplevel)
reload_tree_at(w.data.toplevel)
end)
end

local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" })
watcher = Watcher:new(git_dir, WATCHED_FILES, callback, {
watcher = Watcher:create(git_dir, WATCHED_FILES, callback, {
toplevel = toplevel,
})
end
Expand Down
173 changes: 100 additions & 73 deletions lua/nvim-tree/watcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ local notify = require("nvim-tree.notify")
local log = require("nvim-tree.log")
local utils = require("nvim-tree.utils")

local M = {
config = {},
}

---@class Event
local Event = {
_events = {},
}
Event.__index = Event

---@class Watcher
local Watcher = {
_watchers = {},
}
Watcher.__index = Watcher
local Class = require("nvim-tree.class")

local FS_EVENT_FLAGS = {
-- inotify or equivalent will be used; fallback to stat has not yet been implemented
Expand All @@ -25,42 +11,62 @@ local FS_EVENT_FLAGS = {
recursive = false,
}

local M = {
config = {},
}

---@class (exact) Event: Class
---@field destroyed boolean
---@field private path string
---@field private fs_event uv.uv_fs_event_t?
---@field private listeners function[]
local Event = Class:new()

---Registry of all events
---@type Event[]
local events = {}

---Static factory method
---Creates and starts an Event
---@param path string
---@return Event|nil
function Event:new(path)
log.line("watcher", "Event:new '%s'", path)

local e = setmetatable({
_path = path,
_fs_event = nil,
_listeners = {},
}, Event)

if e:start() then
Event._events[path] = e
return e
function Event:create(path)
log.line("watcher", "Event:create '%s'", path)

---@type Event
local o = {
destroyed = false,
path = path,
fs_event = nil,
listeners = {},
}
o = self:new(o) --[[@as Event]]

if o:start() then
events[path] = o
return o
else
return nil
end
end

---@return boolean
function Event:start()
log.line("watcher", "Event:start '%s'", self._path)
log.line("watcher", "Event:start '%s'", self.path)

local rc, _, name

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))
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))
return false
end

local event_cb = vim.schedule_wrap(function(err, filename)
if err then
log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self._path, filename, err)
local message = string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self._path)
log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self.path, filename, err)
local message = string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self.path)
if err == "EPERM" and (utils.is_windows or utils.is_wsl) then
-- on directory removal windows will cascade the filesystem events out of order
log.line("watcher", message)
Expand All @@ -69,19 +75,19 @@ function Event:start()
self:destroy(message)
end
else
log.line("watcher", "event_cb '%s' '%s'", self._path, filename)
for _, listener in ipairs(self._listeners) do
log.line("watcher", "event_cb '%s' '%s'", self.path, filename)
for _, listener in ipairs(self.listeners) do
listener(filename)
end
end
end)

rc, _, name = self._fs_event:start(self._path, FS_EVENT_FLAGS, event_cb)
rc, _, name = self.fs_event:start(self.path, FS_EVENT_FLAGS, event_cb)
if rc ~= 0 then
if name == "EMFILE" then
M.disable_watchers("fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting")
else
notify.warn(string.format("Could not start the fs_event watcher for path %s : %s", self._path, name))
notify.warn(string.format("Could not start the fs_event watcher for path %s : %s", self.path, name))
end
return false
end
Expand All @@ -91,81 +97,102 @@ end

---@param listener function
function Event:add(listener)
table.insert(self._listeners, listener)
table.insert(self.listeners, listener)
end

---@param listener function
function Event:remove(listener)
utils.array_remove(self._listeners, listener)
if #self._listeners == 0 then
utils.array_remove(self.listeners, listener)
if #self.listeners == 0 then
self:destroy()
end
end

---@param message string|nil
function Event:destroy(message)
log.line("watcher", "Event:destroy '%s'", self._path)
log.line("watcher", "Event:destroy '%s'", self.path)

if self._fs_event then
if self.fs_event then
if message then
notify.warn(message)
end

local rc, _, name = self._fs_event:stop()
local rc, _, name = self.fs_event:stop()
if rc ~= 0 then
notify.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self._path, name))
notify.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self.path, name))
end
self._fs_event = nil
self.fs_event = nil
end

Event._events[self._path] = nil

self.destroyed = true
events[self.path] = nil
end

---Static factory method
---Creates and starts a Watcher
---@class (exact) Watcher: Class
---@field data table user data
---@field destroyed boolean
---@field private path string
---@field private callback fun(watcher: Watcher)
---@field private files string[]?
---@field private listener fun(filename: string)?
---@field private event Event
local Watcher = Class:new()

---Registry of all watchers
---@type Watcher[]
local watchers = {}

---Static factory method
---@param path string
---@param files string[]|nil
---@param callback function
---@param data table
---@param callback fun(watcher: Watcher)
---@param data table user data
---@return Watcher|nil
function Watcher:new(path, files, callback, data)
log.line("watcher", "Watcher:new '%s' %s", path, vim.inspect(files))

local w = setmetatable(data, Watcher)
function Watcher:create(path, files, callback, data)
log.line("watcher", "Watcher:create '%s' %s", path, vim.inspect(files))

w._event = Event._events[path] or Event:new(path)
w._listener = nil
w._path = path
w._files = files
w._callback = callback

if not w._event then
local event = events[path] or Event:create(path)
if not event then
return nil
end

w:start()
---@type Watcher
local o = {
data = data,
destroyed = false,
path = path,
callback = callback,
files = files,
listener = nil,
event = event,
}
o = self:new(o) --[[@as Watcher]]

o:start()

table.insert(Watcher._watchers, w)
table.insert(watchers, o)

return w
return o
end

function Watcher:start()
self._listener = function(filename)
if not self._files or vim.tbl_contains(self._files, filename) then
self._callback(self)
self.listener = function(filename)
if not self.files or vim.tbl_contains(self.files, filename) then
self.callback(self)
end
end

self._event:add(self._listener)
self.event:add(self.listener)
end

function Watcher:destroy()
log.line("watcher", "Watcher:destroy '%s'", self._path)
log.line("watcher", "Watcher:destroy '%s'", self.path)

self._event:remove(self._listener)
self.event:remove(self.listener)

utils.array_remove(Watcher._watchers, self)
utils.array_remove(watchers, self)

self.destroyed = true
end
Expand All @@ -183,11 +210,11 @@ end
function M.purge_watchers()
log.line("watcher", "purge_watchers")

for _, w in ipairs(utils.array_shallow_clone(Watcher._watchers)) do
for _, w in ipairs(utils.array_shallow_clone(watchers)) do
w:destroy()
end

for _, e in pairs(Event._events) do
for _, e in pairs(events) do
e:destroy()
end
end
Expand Down
Loading