Skip to content

Commit d8d6c48

Browse files
authored
refactor: annotate deprecated functions, fix lua-ls warnings (#1723)
1 parent b545111 commit d8d6c48

36 files changed

+226
-119
lines changed

.github/workflows/luals-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
mise_toml: |
2828
[tools]
2929
neovim = "${{ matrix.neovim }}"
30-
lua-language-server = "latest"
30+
lua-language-server = "3.13.6"
3131
3232
- name: Run lua-language-server check
3333
continue-on-error: true

.luarc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3-
"diagnostics.libraryFiles": "Disable",
3+
"diagnostics": {
4+
"libraryFiles": "Disable"
5+
},
46
"runtime": {
57
"version": "LuaJIT",
68
"path": [

lua/neo-tree.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
local vim = vim
22
local M = {}
33

4-
-- DEPRECATED: to be removed in a future release, use this instead:
5-
-- ```
6-
-- require("neo-tree.command").execute({ action = "close" })
7-
-- ```
4+
--- To be removed in a future release, use this instead:
5+
--- ```lua
6+
--- require("neo-tree.command").execute({ action = "close" })
7+
--- ```
8+
---@deprecated
89
M.close_all = function()
910
require("neo-tree.command").execute({ action = "close" })
1011
end

lua/neo-tree/command/parser.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local utils = require("neo-tree.utils")
2+
local _compat = require("neo-tree.utils._compat")
23

34
local M = {
45
FLAG = "<FLAG>",
@@ -8,7 +9,7 @@ local M = {
89
}
910

1011
M.setup = function(all_source_names)
11-
local source_names = utils.table_copy(all_source_names)
12+
local source_names = vim.deepcopy(all_source_names, _compat.noref())
1213
table.insert(source_names, "migrations")
1314

1415
-- A special source referring to the last used source.
@@ -88,7 +89,7 @@ M.resolve_path = function(path, validate_type)
8889
local abs_path = vim.fn.fnamemodify(expanded, ":p")
8990
if validate_type then
9091
local stat = vim.loop.fs_stat(abs_path)
91-
if stat.type ~= validate_type then
92+
if stat and stat.type ~= validate_type then
9293
error("Invalid path: " .. path .. " is not a " .. validate_type)
9394
end
9495
end

lua/neo-tree/events/queue.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ local event_queues = {}
66
local event_definitions = {}
77
local M = {}
88

9+
---@class neotree.Event.Handler.Result
10+
---@field handled boolean?
11+
912
---@class neotree.Event.Handler
1013
---@field event neotree.Event|string
11-
---@field handler fun(...)
14+
---@field handler fun(table?):(neotree.Event.Handler.Result?)
1215
---@field id string?
1316

1417
local validate_event_handler = function(event_handler)

lua/neo-tree/git/ignored.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ M.mark_ignored = function(state, items, callback)
129129

130130
for folder, folder_items in pairs(folders) do
131131
local args = { "-C", folder, "check-ignore", "--stdin" }
132+
---@diagnostic disable-next-line: missing-fields
132133
local job = Job:new({
133134
command = "git",
134135
args = args,

lua/neo-tree/git/status.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ local function get_priority_git_status_code(status, other_status)
4949
end
5050
end
5151

52+
---@class neotree.Git.Context
53+
---@field status neotree.Git.Status
54+
55+
---@class neotree.Git.Status
56+
---@field [string] string
57+
5258
local parse_git_status_line = function(context, line)
5359
context.lines_parsed = context.lines_parsed + 1
5460
if type(line) ~= "string" then
@@ -114,13 +120,11 @@ local parse_git_status_line = function(context, line)
114120
end)
115121
end
116122
end
117-
118123
---Parse "git status" output for the current working directory.
119124
---@base git ref base
120125
---@exclude_directories boolean Whether to skip bubling up status to directories
121126
---@path string Path to run the git status command in, defaults to cwd.
122-
---@return table table Table with the path as key and the status as value.
123-
---@return table, string|nil The git root for the specified path.
127+
---@return neotree.Git.Status, string? git_status the neotree.Git.Status of the given root
124128
M.status = function(base, exclude_directories, path)
125129
local git_root = git_utils.get_repository_root(path)
126130
if not utils.truthy(git_root) then
@@ -250,6 +254,7 @@ M.status_async = function(path, base, opts)
250254
end)
251255

252256
utils.debounce(event_id, function()
257+
---@diagnostic disable-next-line: missing-fields
253258
local staged_job = Job:new({
254259
command = "git",
255260
args = { "-C", git_root, "diff", "--staged", "--name-status", base, "--" },
@@ -267,6 +272,7 @@ M.status_async = function(path, base, opts)
267272
end,
268273
})
269274

275+
---@diagnostic disable-next-line: missing-fields
270276
local unstaged_job = Job:new({
271277
command = "git",
272278
args = { "-C", git_root, "diff", "--name-status" },
@@ -287,6 +293,7 @@ M.status_async = function(path, base, opts)
287293
end,
288294
})
289295

296+
---@diagnostic disable-next-line: missing-fields
290297
local untracked_job = Job:new({
291298
command = "git",
292299
args = { "-C", git_root, "ls-files", "--exclude-standard", "--others" },
@@ -307,6 +314,7 @@ M.status_async = function(path, base, opts)
307314
end,
308315
})
309316

317+
---@diagnostic disable-next-line: missing-fields
310318
Job:new({
311319
command = "git",
312320
args = {

lua/neo-tree/git/utils.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ M.get_repository_root = function(path, callback)
1111
args = { "-C", path, "rev-parse", "--show-toplevel" }
1212
end
1313
if type(callback) == "function" then
14+
---@diagnostic disable-next-line: missing-fields
1415
Job:new({
1516
command = "git",
1617
args = args,
@@ -32,12 +33,12 @@ M.get_repository_root = function(path, callback)
3233
end,
3334
}):start()
3435
else
35-
local ok, git_root = utils.execute_command({ "git", unpack(args) })
36+
local ok, git_output = utils.execute_command({ "git", unpack(args) })
3637
if not ok then
37-
log.trace("GIT ROOT ERROR ", git_root)
38+
log.trace("GIT ROOT ERROR ", git_output)
3839
return nil
3940
end
40-
git_root = git_root[1]
41+
local git_root = git_output[1]
4142

4243
if utils.is_windows then
4344
git_root = utils.windowize_path(git_root)

lua/neo-tree/setup/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ M.buffer_enter_event = function()
248248
vim.schedule(function()
249249
-- try to delete the buffer, only because if it was new it would take
250250
-- on options from the neo-tree window that are undesirable.
251+
---@diagnostic disable-next-line: param-type-mismatch
251252
pcall(vim.cmd, "bdelete " .. bufname)
252253
local fake_state = {
253254
window = {

lua/neo-tree/sources/buffers/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ M.buffers_changed = function()
8181
end
8282

8383
---Navigate to the given path.
84-
---@param path string Path to navigate to. If empty, will navigate to the cwd.
84+
---@param path string? Path to navigate to. If empty, will navigate to the cwd.
8585
M.navigate = function(state, path, path_to_reveal, callback, async)
8686
state.dirty = false
8787
local path_changed = false

0 commit comments

Comments
 (0)