chore: add type annotations and resolve LSP warnings (#2555)

* chore: add type annotations to (almost) all functions

* stylua

* Add classes for symlink nodes

* Replace deprecated `@vararg`

* Move node classes to `node` module

* Fix `Symlink*` classes

* add vim and libuv runtime for luals, qualify libuv types

* add scripts/luals-check, not quite ready for CI

* additional nil checks for git/init.lua and git/runner.lua

* additional nil checks for nvim-tree.lua

* wrap vim.cmd-as-a-function calls inside functions

* vim.tbl_filter predicate returns booleans

* Revert "add scripts/luals-check, not quite ready for CI"

This reverts commit c70229cad9.

* Add `MinimalNode` class in `marks` module

* Fix various LSP warnings

* stylua

* Fix `Explorer` class, update related annotations and add necessary checks

* Add missing annotations to `live-filter`

* Add temporary aliases for `uv.*` types

* Resolve remaining LSP warnings

* Revert changes not related to internal types

* Minor adjustments

* Update doc comments style

* Minor adjustments (pt. 2)

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Azad
2023-12-09 01:34:35 +01:00
committed by GitHub
parent 7d1760f892
commit 13f967f8e7
51 changed files with 622 additions and 161 deletions

View File

@@ -6,9 +6,15 @@ local M = {
current_tab = vim.api.nvim_get_current_tabpage(),
}
---@param name string
---@return string|nil
local function clean_input_cwd(name)
name = vim.fn.fnameescape(name)
local root_parent_cwd = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
local cwd = core.get_cwd()
if cwd == nil then
return
end
local root_parent_cwd = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h")
if name == ".." and root_parent_cwd then
return vim.fn.expand(root_parent_cwd)
else
@@ -16,17 +22,23 @@ local function clean_input_cwd(name)
end
end
---@param new_tabpage integer
---@return boolean
local function is_window_event(new_tabpage)
local is_event_scope_window = vim.v.event.scope == "window" or vim.v.event.changed_window
return is_event_scope_window and new_tabpage == M.current_tab
end
---@param foldername string
---@return boolean
local function prevent_cwd_change(foldername)
local is_same_cwd = foldername == core.get_cwd()
local is_restricted_above = M.options.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
return is_same_cwd or is_restricted_above
end
---@param input_cwd string
---@param with_open boolean|nil
function M.fn(input_cwd, with_open)
if not core.get_explorer() then
return
@@ -38,7 +50,7 @@ function M.fn(input_cwd, with_open)
end
local foldername = clean_input_cwd(input_cwd)
if prevent_cwd_change(foldername) then
if foldername == nil or prevent_cwd_change(foldername) then
return
end
@@ -46,14 +58,19 @@ function M.fn(input_cwd, with_open)
M.force_dirchange(foldername, with_open)
end
---@param global boolean
---@param path string
local function cd(global, path)
vim.cmd((global and "cd " or "lcd ") .. vim.fn.fnameescape(path))
end
---@return boolean
local function should_change_dir()
return M.options.enable and vim.tbl_isempty(vim.v.event)
end
---@param f function
---@return fun(foldername: string, should_open_view: boolean|nil)
local function add_profiling_to(f)
return function(foldername, should_open_view)
local profile = log.profile_start("change dir %s", foldername)