Skip to content

Commit e01ca7d

Browse files
authored
refactor(types): type annotate nearly everything (#1799)
1 parent b287285 commit e01ca7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+977
-543
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ format:
1313

1414
# Dependencies:
1515

16-
DEPS := ./.dependencies/site/pack/vendor/start
16+
DEPS := ${CURDIR}/.dependencies/site/pack/vendor/start
1717

1818
$(DEPS):
1919
mkdir -p "$(DEPS)"
@@ -34,9 +34,9 @@ setup: $(DEPS)/nui.nvim $(DEPS)/nvim-web-devicons $(DEPS)/plenary.nvim
3434
clean:
3535
rm -rf "$(DEPS)"
3636

37-
CONFIGURATION = .luarc.json
37+
CONFIGURATION = ${CURDIR}/.luarc.json
3838
luals-check: setup
3939
VIMRUNTIME="`nvim --clean --headless --cmd 'lua io.write(vim.env.VIMRUNTIME)' --cmd 'quit'`" lua-language-server --configpath=$(CONFIGURATION) --check=.
4040

4141
emmylua-check: setup
42-
VIMRUNTIME="`nvim --clean --headless --cmd 'lua io.write(vim.env.VIMRUNTIME)' --cmd 'quit'`" emmylua_check -c $(CONFIGURATION) .
42+
VIMRUNTIME="`nvim --clean --headless --cmd 'lua io.write(vim.env.VIMRUNTIME)' --cmd 'quit'`" emmylua_check -c $(CONFIGURATION) -i ".dependencies/**" -- .

lua/neo-tree.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ M.ensure_config = function()
2222
return M.config
2323
end
2424

25+
---@param ignore_filetypes string[]?
26+
---@param ignore_winfixbuf boolean?
2527
M.get_prior_window = function(ignore_filetypes, ignore_winfixbuf)
2628
local utils = require("neo-tree.utils")
2729
ignore_filetypes = ignore_filetypes or {}
@@ -54,14 +56,18 @@ end
5456

5557
M.paste_default_config = function()
5658
local utils = require("neo-tree.utils")
57-
local base_path = debug.getinfo(utils.truthy).source:match("@(.*)/utils/init.lua$")
59+
---@type string
60+
local base_path = assert(debug.getinfo(utils.truthy).source:match("@(.*)/utils/init.lua$"))
61+
---@type string
5862
local config_path = base_path .. utils.path_separator .. "defaults.lua"
63+
---@type string[]?
5964
local lines = vim.fn.readfile(config_path)
6065
if lines == nil then
6166
error("Could not read neo-tree.defaults")
6267
end
6368

6469
-- read up to the end of the config, jut to omit the final return
70+
---@type string[]
6571
local config = {}
6672
for _, line in ipairs(lines) do
6773
table.insert(config, line)

lua/neo-tree/collections.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
local log = require("neo-tree.log")
22

3+
---@class neotree.collections.ListNode
4+
---@field prev neotree.collections.ListNode?
5+
---@field next neotree.collections.ListNode?
6+
---@field value any
7+
38
local Node = {}
49
function Node:new(value)
510
local props = { prev = nil, next = nil, value = value }
@@ -8,14 +13,21 @@ function Node:new(value)
813
return props
914
end
1015

16+
---@class neotree.collections.LinkedList
17+
---@field head neotree.collections.ListNode?
18+
---@field tail neotree.collections.ListNode?
19+
---@field size integer
1120
local LinkedList = {}
21+
22+
---@return neotree.collections.LinkedList
1223
function LinkedList:new()
1324
local props = { head = nil, tail = nil, size = 0 }
1425
setmetatable(props, self)
1526
self.__index = self
1627
return props
1728
end
1829

30+
---@param node neotree.collections.ListNode
1931
function LinkedList:add_node(node)
2032
if self.head == nil then
2133
self.head = node
@@ -29,6 +41,7 @@ function LinkedList:add_node(node)
2941
return node
3042
end
3143

44+
---@param node neotree.collections.ListNode
3245
function LinkedList:remove_node(node)
3346
if node.prev ~= nil then
3447
node.prev.next = node.next
@@ -49,7 +62,11 @@ function LinkedList:remove_node(node)
4962
end
5063

5164
-- First in Last Out
65+
---@class neotree.collections.Queue
66+
---@field _list neotree.collections.LinkedList
5267
local Queue = {}
68+
69+
---@return neotree.collections.Queue
5370
function Queue:new()
5471
local props = { _list = LinkedList:new() }
5572
setmetatable(props, self)
@@ -66,6 +83,7 @@ end
6683
---Iterates over the entire list, running func(value) on each element.
6784
---If func returns true, the element is removed from the list.
6885
---@param func function The function to run on each element.
86+
---@return table? result
6987
function Queue:for_each(func)
7088
local node = self._list.head
7189
while node ~= nil do
@@ -91,6 +109,7 @@ function Queue:for_each(func)
91109
end
92110
end
93111
if not node_is_next then
112+
---@diagnostic disable-next-line: need-check-nil
94113
node = node.next
95114
end
96115
end

lua/neo-tree/command/completion.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ local M = {
55
show_key_value_completions = true,
66
}
77

8+
---@param key_prefix string?
9+
---@param base_path string
10+
---@return string paths_string
811
local get_path_completions = function(key_prefix, base_path)
912
key_prefix = key_prefix or ""
1013
local completions = {}
@@ -29,6 +32,8 @@ local get_path_completions = function(key_prefix, base_path)
2932
return table.concat(completions, "\n")
3033
end
3134

35+
---@param key_prefix string?
36+
---@return string references_string
3237
local get_ref_completions = function(key_prefix)
3338
key_prefix = key_prefix or ""
3439
local completions = { key_prefix .. "HEAD" }
@@ -46,6 +51,9 @@ local get_ref_completions = function(key_prefix)
4651
return table.concat(completions, "\n")
4752
end
4853

54+
---@param argLead string
55+
---@param cmdLine string
56+
---@return string candidates_string
4957
M.complete_args = function(argLead, cmdLine)
5058
local candidates = {}
5159
local existing = utils.split(cmdLine, " ")
@@ -80,12 +88,12 @@ M.complete_args = function(argLead, cmdLine)
8088
-- continuation of a key=value pair
8189
local key = string.sub(argLead, 1, eq - 1)
8290
local value = string.sub(argLead, eq + 1)
83-
local arg_type = parser.arg_type_lookup[key]
84-
if arg_type == parser.PATH then
91+
local arg_type = parser.argtype_lookup[key]
92+
if arg_type == parser.argtypes.PATH then
8593
return get_path_completions(key .. "=", value)
86-
elseif arg_type == parser.REF then
94+
elseif arg_type == parser.argtypes.REF then
8795
return get_ref_completions(key .. "=")
88-
elseif arg_type == parser.LIST then
96+
elseif arg_type == parser.argtypes.LIST then
8997
local valid_values = parser.arguments[key].values
9098
if valid_values and not (parsed[key] and #parsed[key] > 0) then
9199
for _, vv in ipairs(valid_values) do
@@ -101,7 +109,7 @@ M.complete_args = function(argLead, cmdLine)
101109
for value, key in pairs(parser.reverse_lookup) do
102110
value = tostring(value)
103111
local key_already_used = false
104-
if parser.arg_type_lookup[key] == parser.LIST then
112+
if parser.argtype_lookup[key] == parser.argtypes.LIST then
105113
key_already_used = type(parsed[key]) ~= "nil"
106114
else
107115
key_already_used = type(parsed[value]) ~= "nil"

lua/neo-tree/command/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ M.execute = function(args)
9494
end
9595

9696
-- Now get the correct state
97+
---@type neotree.State
9798
local state
9899
local requested_position = args.position or nt.config[args.source].window.position
99100
if requested_position == "current" then

0 commit comments

Comments
 (0)