Skip to content

Commit afd6775

Browse files
committed
doc: improve lua language server typing annotations
1 parent 8f5f57f commit afd6775

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lua/astrocore/config.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
-- copyright 2023
88
-- GNU General Public License v3.0
99

10+
---@class AstroCoreMapping: vim.api.keyset.keymap
11+
---@field [1] string|function rhs of keymap
12+
---@field name string? optional which-key mapping name
13+
14+
---@alias AstroCoreMappings table<string,table<string,(AstroCoreMapping|string|false)?>?>
15+
16+
---@class AstroCoreCommand: vim.api.keyset.user_command
17+
---@field [1] string|function the command to execute
18+
19+
---@class AstroCoreAutocmd: vim.api.keyset.create_autocmd
20+
---@field event string|string[] Event(s) that will trigger the handler
21+
1022
---@class AstroCoreGitWorktree
1123
---@field toplevel string the top level directory
1224
---@field gitdir string the location of the git directory
@@ -85,7 +97,7 @@
8597
--- }
8698
---}
8799
---```
88-
---@field autocmds table<string,table[]|false>?
100+
---@field autocmds table<string,AstroCoreAutocmd[]|false>?
89101
---Configuration of user commands
90102
---The key into the table is the name of the user command and the value is a table of command options
91103
---Example:
@@ -101,7 +113,7 @@
101113
--- }
102114
---}
103115
---```
104-
---@field commands table<string,table|false>?
116+
---@field commands table<string,AstroCoreCommand|false>?
105117
---Configuration of vim mappings to create.
106118
---The first key into the table is the vim map mode (`:h map-modes`), and the value is a table of entries to be passed to `vim.keymap.set` (`:h vim.keymap.set`):
107119
--- - The key is the first parameter or the vim mode (only a single mode supported) and the value is a table of keymaps within that mode:
@@ -133,7 +145,7 @@
133145
--- }
134146
---}
135147
---```
136-
---@field mappings table<string,table<string,(table|string|false)?>?>?
148+
---@field mappings AstroCoreMappings?
137149
---@field _map_sections table<string,{ desc: string?, name: string? }>?
138150
---Configuration of vim `on_key` functions.
139151
---The key into the table is the namespace of the function and the value is a list like table of `on_key` functions

lua/astrocore/init.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ function M.empty_map_table()
239239
end
240240

241241
--- Table based API for setting keybindings
242-
---@param map_table table A nested table where the first key is the vim mode, the second key is the key to map, and the value is the function to set the mapping to
243-
---@param base? table A base set of options to set on every keybinding
242+
---@param map_table AstroCoreMappings A nested table where the first key is the vim mode, the second key is the key to map, and the value is the function to set the mapping to
243+
---@param base? vim.api.keyset.keymap A base set of options to set on every keybinding
244244
function M.set_mappings(map_table, base)
245245
local was_no_which_key_queue = not M.which_key_queue
246246
-- iterate over the first keys for each mode
@@ -250,9 +250,11 @@ function M.set_mappings(map_table, base)
250250
for keymap, options in pairs(maps) do
251251
-- build the options for the command accordingly
252252
if options then
253-
local cmd = options
253+
local cmd
254254
local keymap_opts = base
255-
if type(options) == "table" then
255+
if type(options) == "string" then
256+
cmd = options
257+
else
256258
cmd = options[1]
257259
keymap_opts = vim.tbl_deep_extend("force", keymap_opts, options)
258260
keymap_opts[1] = nil

0 commit comments

Comments
 (0)