Skip to content

Commit

Permalink
refactor: move to only lua_ls annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Aug 4, 2023
1 parent 63ed189 commit 743973c
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 173 deletions.
5 changes: 4 additions & 1 deletion .neoconf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"neodev": {
"library": {
"enabled": true,
"plugins": true
"plugins": [
"lazy.nvim",
"astroui"
]
}
},
"neoconf": {
Expand Down
11 changes: 0 additions & 11 deletions config.ld

This file was deleted.

21 changes: 10 additions & 11 deletions lua/astrocore/buffer.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
--- ### AstroNvim Buffer Utilities
--
-- Buffer management related utility functions
--
-- This module can be loaded with `local buffer_utils = require "astrocore.buffer"`
--
-- @module astrocore.buffer
-- @copyright 2023
-- @license GNU General Public License v3.0

---AstroNvim Buffer Utilities
---
---Buffer management related utility functions
---
---This module can be loaded with `local buffer_utils = require "astrocore.buffer"`
---
---copyright 2023
---license GNU General Public License v3.0
---@class astrocore.buffer
local M = {}

local astro = require "astrocore"
Expand Down Expand Up @@ -89,7 +88,7 @@ function M.move(n)
end

--- Navigate left and right by n places in the bufferline
-- @param n number The number of tabs to navigate to (positive = right, negative = left)
---@param n number The number of tabs to navigate to (positive = right, negative = left)
function M.nav(n)
local current = vim.api.nvim_get_current_buf()
for i, v in ipairs(vim.t.bufs) do
Expand Down
224 changes: 146 additions & 78 deletions lua/astrocore/config.lua
Original file line number Diff line number Diff line change
@@ -1,98 +1,166 @@
--- ### AstroNvim Core Configuration
-- AstroNvim Core Configuration
--
-- This module simply defines the configuration table structure for `opts` used in:
--
-- require("astrocore").setup(opts)
--
-- @module astrocore.config
-- @copyright 2023
-- @license GNU General Public License v3.0
-- copyright 2023
-- GNU General Public License v3.0

---@type AstroCoreConfig
return {
---@class AstroCoreGitWorktree
---@field toplevel string the top level directory
---@field gitdir string the location of the git directory

---@class AstroCoreMaxFile
---@field size integer? the number of bytes in a file
---@field lines integer? the number of lines in a file

---@class AstroCoreSessionAutosave
---@field last boolean? whether or not to save the last session
---@field cwd boolean? whether or not to save a session for the current working directory

---@class AstroCoreSessionIgnore
---@field dirs string[]? directories to ignore
---@field filetypes string[]? filetypes to ignore
---@field buftypes string[]? buffer types to ignore

---@class AstroCoreSessionOpts
---Session autosaving options
---Example:
---
---```lua
---autosave = {
--- last = true,
--- cwd = true,
---}
---```
---@field autosave AstroCoreSessionAutosave?
---Patterns to ignore when saving sessions
---Example:
---
---```lua
---autosave = {
--- dirs = { "/path/to/ignore/sessions/dir" },
--- filetypes = { "gitcommit", "gitrebase" },
--- buftypes = { "nofile" }
---}
---```
---@field ignore AstroCoreSessionIgnore?

---@class AstroCoreFeatureOpts
---@field autopairs boolean? enable or disable autopairs on start (boolean; default = true)
---@field cmp boolean? enable or disable cmp on start (boolean; default = true)
---@field highlighturl boolean? enable or disable highlighting of urls on start (boolean; default = true)
---table for defining the size of the max file for all features, above these limits we disable features like treesitter.
---Example:
---
---```lua
---max_file = {
--- size = 1024 * 100,
--- lines = 10000
---},
---```
---@field max_file AstroCoreMaxFile?
---@field notifications boolean? enable or disable notifications on start (boolean; default = true)

---@class AstroCoreOpts
---@field autocmds table<string,table[]>?
---@field commands table<string,table>?
---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:
--- - The first element with no key in the table is the action (the 2nd parameter) and the rest of the keys/value pairs are options for the third parameter.
---Example:
--
---```lua
---mappings = {
--- -- map mode (:h map-modes)
--- n = {
--- -- use vimscript strings for mappings
--- ["<C-s>"] = { ":w!<cr>", desc = "Save File" },
--- -- navigate buffer tabs with `H` and `L`
--- L = {
--- function()
--- require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1)
--- end,
--- desc = "Next buffer",
--- },
--- H = {
--- function()
--- require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1))
--- end,
--- desc = "Previous buffer",
--- },
--- -- tables with just a `desc` key will be registered with which-key if it's installed
--- -- this is useful for naming menus
--- ["<leader>b"] = { desc = "Buffers" },
--- }
---}
---```
---@field mappings table<string,table<string,(table|boolean|string)?>?>?
---@field on_keys table<string,fun(key:string)[]>?
---Configuration table of features provided by AstroCore
---Example:
--
---```lua
---features = {
--- autopairs = true,
--- cmp = true,
--- highlighturl = true,
--- notiifcations = true,
--- max_file = { size = 1024 * 100, lines = 10000 },
---}
---```
---@field features AstroCoreFeatureOpts?
---Enable git integration for detached worktrees
---Example:
--
---```lua
---git_worktrees = {
--- { toplevel = vim.env.HOME, gitdir=vim.env.HOME .. "/.dotfiles" }
---}
---```
---@field git_worktrees AstroCoreGitWorktree[]?
---Configuration table of session options for AstroNvim's session management powered by Resession
---Example:
--
---```lua
---sessions = {
--- autosave = {
--- last = true, -- auto save last session
--- cwd = true, -- auto save session for each working directory
--- },
--- ignore = {
--- dirs = {}, -- working directories to ignore sessions in
--- filetypes = { "gitcommit", "gitrebase" }, -- filetypes to ignore sessions
--- buftypes = {}, -- buffer types to ignore sessions
--- },
---}
---```
---@field sessions AstroCoreSessionOpts?

---@type AstroCoreOpts
local M = {
autocmds = {},
commands = {},
--- Configuration of vim mappings to create
--
-- @field mode The key, `mode` 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:
--
-- The first element with no key in the table is the action (the 2nd parameter) and the rest of the keys/value pairs are options for the third parameter.
-- @usage mappings = {
-- -- map mode (:h map-modes)
-- n = {
-- -- use vimscript strings for mappings
-- ["<C-s>"] = { ":w!<cr>", desc = "Save File" },
-- -- navigate buffer tabs with `H` and `L`
-- L = {
-- function()
-- require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1)
-- end,
-- desc = "Next buffer",
-- },
-- H = {
-- function()
-- require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1))
-- end,
-- desc = "Previous buffer",
-- },
-- -- tables with just a `desc` key will be registered with which-key if it's installed
-- -- this is useful for naming menus
-- ["<leader>b"] = { desc = "Buffers" },
-- }
-- }
mappings = {},
on_keys = {},
--- Configuration table of features provided by AstroCore
-- @field autopairs enable or disable autopairs on start (boolean; default = true)
-- @field cmp enable or disable cmp on start (boolean; default = true)
-- @field highlighturl enable or disable highlighting of urls on start (boolean; default = true)
-- @field max_file table for defining the size of the max file for all features, above these limites we disable features like treesitter. This table has the fields: `size` (the number of bytes of a file) and `lines` (the number of lines of a file)
-- @field notifications enable or disable notifications on start (boolean; default = true)
-- @usage features = {
-- autopairs = true,
-- cmp = true,
-- highlighturl = true,
-- notiifcations = true,
-- max_file = { size = 1024 * 100, lines = 10000 },
-- }
features = {
autopairs = true,
cmp = true, -- enable completion at start
highlighturl = true, -- highlight URLs by default
cmp = true,
highlighturl = true,
max_file = { size = 1024 * 100, lines = 10000 },
notifications = true, -- disable notifications
notifications = true,
},
--- Enable git integration for detached worktrees (specify a list-like table where each entry is of the form `{ toplevel = vim.env.HOME, gitdir=vim.env.HOME .. "/.dotfiles" }`)
-- @table git_worktrees
-- @usage git_worktrees = {
-- { toplevel = vim.env.HOME, gitdir=vim.env.HOME .. "/.dotfiles" }
-- }
git_worktrees = nil,
--- Configuration table of session options for AstroNvim's session management powered by Resession
-- @field autosave a table with fields `last` and `cwd` to control if they should autosave sessions
-- @field ignore a table of lists for `dirs`, `filetypes`, and `buftypes` which should be ignored when autosaving sessions
-- @usage sessions = {
-- autosave = {
-- last = true, -- auto save last session
-- cwd = true, -- auto save session for each working directory
-- },
-- ignore = {
-- dirs = {}, -- working directories to ignore sessions in
-- filetypes = { "gitcommit", "gitrebase" }, -- filetypes to ignore sessions
-- buftypes = {}, -- buffer types to ignore sessions
-- },
-- }
sessions = {
autosave = {
last = true, -- auto save last session
cwd = true, -- auto save session for each working directory
},
autosave = { last = true, cwd = true },
ignore = {
dirs = {}, -- working directories to ignore sessions in
filetypes = { "gitcommit", "gitrebase" }, -- filetypes to ignore sessions
buftypes = {}, -- buffer types to ignore sessions
dirs = {},
filetypes = { "gitcommit", "gitrebase" },
buftypes = {},
},
},
}

return M
7 changes: 7 additions & 0 deletions lua/astrocore/health.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-- ### AstroNvim Health Checks
--
-- use with `:checkhealth astrocore`
--
-- copyright 2023
-- license GNU General Public License v3.0

local M = {}

-- TODO: remove deprecated method check after dropping support for neovim v0.9
Expand Down
29 changes: 17 additions & 12 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
--- ### AstroNvim Core Utilities
--
-- Various utility functions to use within AstroNvim and user configurations.
--
-- This module can be loaded with `local astro = require "astrocore"`
--
-- @module astrocore
-- @copyright 2023
-- @license GNU General Public License v3.0

---AstroNvim Core Utilities
---
---Various utility functions to use within AstroNvim and user configurations.
---
---This module can be loaded with `local astro = require "astrocore"`
---
---copyright 2023
---license GNU General Public License v3.0
---@class astrocore
local M = {}

--- The configuration as set by the user through the `setup()` function
M.config = require "astrocore.config"

--- A table to manage ToggleTerm terminals created by the user, indexed by the command run and then the instance number
---@type table<string,table<integer,table>>
M.user_terminals = {}

--- Merge extended options with a default table of options
Expand Down Expand Up @@ -203,6 +204,10 @@ function M.load_plugin_with_func(plugin, module, func_names)
end
end

--- A placeholder variable used to queue section names to be registered by which-key
---@type table?
M.which_key_queue = nil

--- Register queued which-key mappings
function M.which_key_register()
if M.which_key_queue then
Expand Down Expand Up @@ -322,7 +327,7 @@ function M.file_worktree(file, worktrees)
end

--- Setup and configure AstroCore
---@param opts AstroCoreConfig
---@param opts AstroCoreOpts
---@see astrocore.config
function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts)
Expand Down
20 changes: 9 additions & 11 deletions lua/astrocore/mason.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
--- ### Mason Utils
--
-- Mason related utility functions to use within AstroNvim and user configurations.
--
-- This module can be loaded with `local mason_utils = require("astrocore.mason")`
--
-- @module astrocore.mason
-- @see astrocore
-- @copyright 2023
-- @license GNU General Public License v3.0

---Mason Utilities
---
---Mason related utility functions to use within AstroNvim and user configurations.
---
---This module can be loaded with `local mason_utils = require("astrocore.mason")`
---
---copyright 2023
---license GNU General Public License v3.0
---@class astrocore.mason
local M = {}

local astro = require "astrocore"
Expand Down
Loading

0 comments on commit 743973c

Please sign in to comment.