-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
chore: add type annotations and resolve LSP warnings #2555
Changes from 3 commits
fabea33
0b31f06
adeec1a
76c88de
2a6aa31
3b66519
3af30ee
8393f7c
c70229c
b4570bd
15f05f8
6988062
87d2d4f
e201c5b
03ceffc
0fb4f96
ee60886
dcd8cb8
b4ea048
e0cacc9
d16f289
a937cda
ec16b1a
aafccdc
d14eb6f
edc0d63
9ff04a9
7fbc416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,31 @@ local open = require "nvim-tree.actions.tree.open" | |
local events = require "nvim-tree.events" | ||
local notify = require "nvim-tree.notify" | ||
|
||
---@class ParentNode | ||
---@field name string | ||
|
||
---@class BaseNode | ||
---@field absolute_path string | ||
---@field executable boolean | ||
---@field fs_stat uv_fs_t | ||
---@field git_status GitStatus|nil | ||
---@field hidden boolean | ||
---@field name string | ||
---@field parent DirNode | ||
---@field type string | ||
---@field watcher function|nil | ||
|
||
---@class DirNode: BaseNode | ||
---@field has_children boolean | ||
---@field group_next Node|nil | ||
---@field nodes Node[] | ||
---@field open boolean | ||
|
||
---@class FileNode: BaseNode | ||
---@field extension string | ||
|
||
---@alias Node ParentNode|DirNode|FileNode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Where is indeed difficult. We could just create When we eventually get to creating proper node classes they can live in there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's great! It contains all that we know about. LLS can tell us if we're using an unknown field and we can add as we discover them. |
||
|
||
local _config = {} | ||
|
||
local M = { | ||
|
@@ -79,6 +104,7 @@ function M.change_root(path, bufnr) | |
change_dir.fn(vim.fn.fnamemodify(path, ":p:h")) | ||
end | ||
|
||
---@param cwd string|nil | ||
function M.open_replacing_current_buffer(cwd) | ||
if view.is_visible() then | ||
return | ||
|
@@ -159,10 +185,13 @@ function M.place_cursor_on_node() | |
end | ||
end | ||
|
||
---@return table | ||
function M.get_config() | ||
return M.config | ||
end | ||
|
||
---@param disable_netrw boolean | ||
---@param hijack_netrw boolean | ||
local function manage_netrw(disable_netrw, hijack_netrw) | ||
if hijack_netrw then | ||
vim.cmd "silent! autocmd! FileExplorer *" | ||
|
@@ -174,6 +203,7 @@ local function manage_netrw(disable_netrw, hijack_netrw) | |
end | ||
end | ||
|
||
---@param name string|nil | ||
function M.change_dir(name) | ||
change_dir.fn(name) | ||
|
||
|
@@ -182,6 +212,7 @@ function M.change_dir(name) | |
end | ||
end | ||
|
||
---@param opts table | ||
local function setup_autocommands(opts) | ||
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true }) | ||
local function create_nvim_tree_autocmd(name, custom_opts) | ||
|
@@ -677,9 +708,15 @@ local ACCEPTED_STRINGS = { | |
}, | ||
} | ||
|
||
---@param conf table | ||
local function validate_options(conf) | ||
local msg | ||
|
||
---@param user any | ||
---@param def any | ||
---@param strs table | ||
---@param types table | ||
---@param prefix string | ||
local function validate(user, def, strs, types, prefix) | ||
-- if user's option is not a table there is nothing to do | ||
if type(user) ~= "table" then | ||
|
@@ -762,6 +799,7 @@ function M.purge_all_state() | |
end | ||
end | ||
|
||
---@param conf table|nil | ||
function M.setup(conf) | ||
if vim.fn.has "nvim-0.8" == 0 then | ||
notify.warn "nvim-tree.lua requires Neovim 0.8 or higher" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ local M = { | |
config = {}, | ||
} | ||
|
||
---@param windows table | ||
local function close_windows(windows) | ||
-- Prevent from closing when the win count equals 1 or 2, | ||
-- where the win to remove could be the last opened. | ||
|
@@ -23,6 +24,7 @@ local function close_windows(windows) | |
end | ||
end | ||
|
||
---@param absolute_path string | ||
local function clear_buffer(absolute_path) | ||
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 } | ||
for _, buf in pairs(bufs) do | ||
|
@@ -44,10 +46,13 @@ local function clear_buffer(absolute_path) | |
end | ||
end | ||
|
||
---@param cwd string | ||
---@return boolean|nil | ||
local function remove_dir(cwd) | ||
local handle = vim.loop.fs_scandir(cwd) | ||
if type(handle) == "string" then | ||
return notify.error(handle) | ||
notify.error(handle) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some cases I added an explicit nil return instead of returning the call of a function that returns nil. |
||
end | ||
|
||
while true do | ||
|
@@ -75,27 +80,30 @@ local function remove_dir(cwd) | |
end | ||
|
||
--- Remove a node, notify errors, dispatch events | ||
--- @param node table | ||
---@param node Node | ||
function M.remove(node) | ||
local notify_node = notify.render_path(node.absolute_path) | ||
if node.nodes ~= nil and not node.link_to then | ||
local success = remove_dir(node.absolute_path) | ||
if not success then | ||
return notify.error("Could not remove " .. notify_node) | ||
notify.error("Could not remove " .. notify_node) | ||
return | ||
end | ||
events._dispatch_folder_removed(node.absolute_path) | ||
else | ||
events._dispatch_will_remove_file(node.absolute_path) | ||
local success = vim.loop.fs_unlink(node.absolute_path) | ||
if not success then | ||
return notify.error("Could not remove " .. notify_node) | ||
notify.error("Could not remove " .. notify_node) | ||
return | ||
end | ||
events._dispatch_file_removed(node.absolute_path) | ||
clear_buffer(node.absolute_path) | ||
end | ||
notify.info(notify_node .. " was properly removed.") | ||
end | ||
|
||
---@param node Node | ||
function M.fn(node) | ||
if node.name == ".." then | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic... finding all these bits every time always slows me down.