Skip to content

Commit

Permalink
doc: improve lua language server typing annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Jan 22, 2024
1 parent 8f5f57f commit afd6775
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 15 additions & 3 deletions lua/astrocore/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
-- copyright 2023
-- GNU General Public License v3.0

---@class AstroCoreMapping: vim.api.keyset.keymap
---@field [1] string|function rhs of keymap
---@field name string? optional which-key mapping name

---@alias AstroCoreMappings table<string,table<string,(AstroCoreMapping|string|false)?>?>

---@class AstroCoreCommand: vim.api.keyset.user_command
---@field [1] string|function the command to execute

---@class AstroCoreAutocmd: vim.api.keyset.create_autocmd
---@field event string|string[] Event(s) that will trigger the handler

---@class AstroCoreGitWorktree
---@field toplevel string the top level directory
---@field gitdir string the location of the git directory
Expand Down Expand Up @@ -85,7 +97,7 @@
--- }
---}
---```
---@field autocmds table<string,table[]|false>?
---@field autocmds table<string,AstroCoreAutocmd[]|false>?
---Configuration of user commands
---The key into the table is the name of the user command and the value is a table of command options
---Example:
Expand All @@ -101,7 +113,7 @@
--- }
---}
---```
---@field commands table<string,table|false>?
---@field commands table<string,AstroCoreCommand|false>?
---Configuration of vim mappings to create.
---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`):
--- - 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:
Expand Down Expand Up @@ -133,7 +145,7 @@
--- }
---}
---```
---@field mappings table<string,table<string,(table|string|false)?>?>?
---@field mappings AstroCoreMappings?
---@field _map_sections table<string,{ desc: string?, name: string? }>?
---Configuration of vim `on_key` functions.
---The key into the table is the namespace of the function and the value is a list like table of `on_key` functions
Expand Down
10 changes: 6 additions & 4 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ function M.empty_map_table()
end

--- Table based API for setting keybindings
---@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
---@param base? table A base set of options to set on every keybinding
---@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
---@param base? vim.api.keyset.keymap A base set of options to set on every keybinding
function M.set_mappings(map_table, base)
local was_no_which_key_queue = not M.which_key_queue
-- iterate over the first keys for each mode
Expand All @@ -250,9 +250,11 @@ function M.set_mappings(map_table, base)
for keymap, options in pairs(maps) do
-- build the options for the command accordingly
if options then
local cmd = options
local cmd
local keymap_opts = base
if type(options) == "table" then
if type(options) == "string" then
cmd = options
else
cmd = options[1]
keymap_opts = vim.tbl_deep_extend("force", keymap_opts, options)
keymap_opts[1] = nil
Expand Down

0 comments on commit afd6775

Please sign in to comment.