Skip to content

Commit 1ff045c

Browse files
committed
refactor(nvim): add luadoc annotations to nvim files
1 parent 74ca67a commit 1ff045c

9 files changed

Lines changed: 38 additions & 5 deletions

File tree

home/dot_config/exact_nvim/exact_ftplugin/qf.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local g = vim.g
44
-- Disable built-in statusline.
55
g.qf_disable_statusline = true
66

7+
---@type string[]
78
local qf_statusline = {
89
'%{repeat(nr2char(32),4)}', -- Generate space characters given number of times.
910
'', -- Show a custom list icon.

home/dot_config/exact_nvim/exact_lsp/lua_ls.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ local LspConfig = {
55
},
66
on_init = function(client)
77
if client.workspace_folders then
8+
---@type string
89
local path = client.workspace_folders[1].name
10+
911
if
1012
path ~= vim.fn.stdpath('config')
1113
and (

home/dot_config/exact_nvim/exact_lua/exact_user/buffer.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ local api = vim.api
22
local fn = vim.fn
33
local cmd = vim.cmd
44

5+
---@param opts { force: boolean? }
6+
---@return false?
57
local function remove(opts)
8+
---@type integer
69
local target_buf_id = api.nvim_get_current_buf()
710

811
-- Do nothing if buffer is in modified state.
@@ -11,13 +14,16 @@ local function remove(opts)
1114
end
1215

1316
-- Hide target buffer from all windows.
14-
vim.tbl_map(function(win_id)
15-
win_id = win_id or 0
17+
---@type integer[]
18+
local win_ids = fn.win_findbuf(target_buf_id)
1619

20+
for _, win_id in ipairs(win_ids) do
21+
---@type integer
1722
local current_buf_id = api.nvim_win_get_buf(win_id)
1823

1924
api.nvim_win_call(win_id, function()
2025
-- Try using alternate buffer
26+
---@type integer
2127
local alt_buf_id = fn.bufnr('#')
2228
if alt_buf_id ~= current_buf_id and fn.buflisted(alt_buf_id) == 1 then
2329
api.nvim_win_set_buf(win_id, alt_buf_id)
@@ -31,12 +37,11 @@ local function remove(opts)
3137
end
3238

3339
-- Create new listed scratch buffer
40+
---@type integer
3441
local new_buf = api.nvim_create_buf(true, true)
3542
api.nvim_win_set_buf(win_id, new_buf)
3643
end)
37-
38-
return true
39-
end, fn.win_findbuf(target_buf_id))
44+
end
4045

4146
cmd.bdelete({ target_buf_id, bang = opts.force })
4247
end

home/dot_config/exact_nvim/exact_lua/exact_user/foldtext.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@return string
12
local function foldtext()
23
local start_line = vim.fn.getline(vim.v.foldstart)
34
local end_line = vim.fn.getline(vim.v.foldend)

home/dot_config/exact_nvim/exact_lua/exact_user/shada.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
local function set_shada_file()
2+
---@type string?
23
local git_root = require('snacks').git.get_root()
4+
5+
---@type string
36
local dir = git_root ~= nil and git_root or vim.fn.getcwd()
47

8+
---@type string
59
local shada_file = vim.fs.joinpath(
610
vim.fn.stdpath('state'),
711
'shada',

home/dot_config/exact_nvim/exact_lua/exact_user/utils.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local b = vim.b
22

3+
---@param cmd string
34
local function set_undo_ftplugin(cmd)
45
local undo_cmd = cmd
56

home/dot_config/exact_nvim/exact_plugin/exact_autocmds/buffers.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ vim.api.nvim_create_autocmd('BufReadPost', {
2828
desc = 'Restore cursor to file position in previous editing session.',
2929
pattern = '?*',
3030
group = vim.api.nvim_create_augroup('JumpLastPosition', { clear = true }),
31+
---@param args { buf: integer }
3132
callback = function(args)
3233
-- Skip if the buffer is not a normal file or a git commit.
3334
if
@@ -37,7 +38,9 @@ vim.api.nvim_create_autocmd('BufReadPost', {
3738
return
3839
end
3940

41+
---@type integer[]
4042
local mark = vim.api.nvim_buf_get_mark(args.buf, '"')
43+
---@type integer
4144
local line_count = vim.api.nvim_buf_line_count(args.buf)
4245

4346
if mark[1] > 0 and mark[1] <= line_count then
@@ -57,6 +60,7 @@ vim.api.nvim_create_autocmd('BufEnter', {
5760
})
5861

5962
-- Disable persistent undo for sensitive files
63+
---@type string[]
6064
local sensitive_patterns = {
6165
-- Temp directories
6266
'/tmp/*',

home/dot_config/exact_nvim/exact_plugin/exact_autocmds/macro.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
local api = vim.api
2+
3+
---@type integer?
24
local win_id = nil
5+
6+
---@type integer?
37
local buf_id = nil
48

9+
---@type { row: integer, col_offset: integer }
510
local config = {
611
row = 2,
712
col_offset = 4,
813
}
914

15+
---@return nil
1016
local function close_banner()
1117
if win_id and api.nvim_win_is_valid(win_id) then
1218
api.nvim_win_close(win_id, true)
@@ -20,6 +26,7 @@ local function close_banner()
2026
buf_id = nil
2127
end
2228

29+
---@return nil
2330
local function open_banner()
2431
local reg = vim.fn.reg_recording()
2532

home/dot_config/exact_nvim/exact_plugin/lsp.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
---@type integer
12
local lsp_group = vim.api.nvim_create_augroup('UserLspConfig', { clear = true })
23

34
-- Highlight references to the symbol under the cursor.
45
vim.api.nvim_create_autocmd('LspAttach', {
56
group = lsp_group,
7+
---@param args { buf: integer, data: { client_id: integer } }
68
callback = function(args)
79
local client = vim.lsp.get_client_by_id(args.data.client_id)
810
if not client then
@@ -15,6 +17,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
1517
args.buf
1618
)
1719
then
20+
---@type integer
1821
local highlight_group =
1922
vim.api.nvim_create_augroup('LspDocumentHighlight', { clear = false })
2023

@@ -39,14 +42,18 @@ vim.api.nvim_create_autocmd('LspAttach', {
3942
-- General keymaps for LSP functions.
4043
vim.api.nvim_create_autocmd('LspAttach', {
4144
group = lsp_group,
45+
---@param args { buf: integer }
4246
callback = function(args)
47+
---@type { buffer: integer, silent: boolean }
4348
local map_opts = { buffer = args.buf, silent = true }
4449

4550
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, map_opts)
4651
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, map_opts)
4752
vim.keymap.set('n', 'J', vim.diagnostic.open_float, map_opts)
4853
vim.keymap.set('n', 'K', function()
54+
---@type integer
4955
local width = math.floor(vim.o.columns * 0.8)
56+
---@type integer
5057
local height = math.floor(vim.o.lines * 0.3)
5158
vim.lsp.buf.hover({ max_height = height, max_width = width })
5259
end, map_opts)
@@ -56,6 +63,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
5663
-- Keymaps for inlay hints.
5764
vim.api.nvim_create_autocmd('LspAttach', {
5865
group = lsp_group,
66+
---@param args { buf: integer, data: { client_id: integer } }
5967
callback = function(args)
6068
local client = vim.lsp.get_client_by_id(args.data.client_id)
6169
if not client then

0 commit comments

Comments
 (0)