Skip to content

Commit aa7048d

Browse files
committed
docs(status): add strong typing to the status component functions and configuration
1 parent d6c3bf7 commit aa7048d

File tree

3 files changed

+134
-21
lines changed

3 files changed

+134
-21
lines changed

lua/astroui/status/component.lua

+17-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function M.fill(opts)
2727
end
2828

2929
--- A function to build a set of children components for an entire file information section
30-
---@param opts? table options for configuring file_icon, filename, filetype, file_modified, file_read_only, and the overall padding
30+
---@param opts? AstroUIComponentFileInfoOpts provider options
3131
---@return table # The Heirline component table
3232
-- @usage local heirline_component = require("astroui.status").component.file_info()
3333
function M.file_info(opts)
@@ -44,15 +44,15 @@ function M.file_info(opts)
4444
end
4545

4646
--- A function with different file_info defaults specifically for use in the tabline
47-
---@param opts? table options for configuring file_icon, filename, filetype, file_modified, file_read_only, and the overall padding
47+
---@param opts? AstroUIComponentTablineFileInfoOpts provider options
4848
---@return table # The Heirline component table
4949
-- @usage local heirline_component = require("astroui.status").component.tabline_file_info()
5050
function M.tabline_file_info(opts)
5151
return M.file_info(extend_tbl(vim.tbl_get(config, "components", "tabline_file_info"), opts))
5252
end
5353

5454
--- A function to build a set of children components for an entire navigation section
55-
---@param opts? table options for configuring ruler, percentage, scrollbar, and the overall padding
55+
---@param opts? AstroUIComponentNavOpts provider options
5656
---@return table # The Heirline component table
5757
-- @usage local heirline_component = require("astroui.status").component.nav()
5858
function M.nav(opts)
@@ -61,7 +61,7 @@ function M.nav(opts)
6161
end
6262

6363
--- A function to build a set of children components for information shown in the cmdline
64-
---@param opts? table options for configuring macro recording, search count, and the overall padding
64+
---@param opts? AstroUIComponentCmdInfoOpts provider options
6565
---@return table # The Heirline component table
6666
-- @usage local heirline_component = require("astroui.status").component.cmd_info()
6767
function M.cmd_info(opts)
@@ -70,7 +70,7 @@ function M.cmd_info(opts)
7070
end
7171

7272
--- A function to build a set of children components for a mode section
73-
---@param opts? table options for configuring mode_text, paste, spell, and the overall padding
73+
---@param opts? AstroUIComponentModeOpts provider options
7474
---@return table # The Heirline component table
7575
-- @usage local heirline_component = require("astroui.status").component.mode { mode_text = true }
7676
function M.mode(opts)
@@ -80,7 +80,7 @@ function M.mode(opts)
8080
end
8181

8282
--- A function to build a set of children components for an LSP breadcrumbs section
83-
---@param opts? table options for configuring breadcrumbs and the overall padding
83+
---@param opts? AstroUIComponentBreadcrumbsOpts provider options
8484
---@return table # The Heirline component table
8585
-- @usage local heirline_component = require("astroui.status").component.breadcrumbs()
8686
function M.breadcrumbs(opts)
@@ -90,7 +90,7 @@ function M.breadcrumbs(opts)
9090
end
9191

9292
--- A function to build a set of children components for the current file path
93-
---@param opts? table options for configuring path and the overall padding
93+
---@param opts? AstroUIComponentSeparatedPathOpts provider options
9494
---@return table # The Heirline component table
9595
-- @usage local heirline_component = require("astroui.status").component.separated_path()
9696
function M.separated_path(opts)
@@ -100,7 +100,7 @@ function M.separated_path(opts)
100100
end
101101

102102
--- A function to build a set of children components for a git branch section
103-
---@param opts? table options for configuring git branch and the overall padding
103+
---@param opts? AstroUIComponentGitBranchOpts provider options
104104
---@return table # The Heirline component table
105105
-- @usage local heirline_component = require("astroui.status").component.git_branch()
106106
function M.git_branch(opts)
@@ -109,7 +109,7 @@ function M.git_branch(opts)
109109
end
110110

111111
--- A function to build a set of children components for a git difference section
112-
---@param opts? table options for configuring git changes and the overall padding
112+
---@param opts? AstroUIComponentGitDiffOpts provider options
113113
---@return table # The Heirline component table
114114
-- @usage local heirline_component = require("astroui.status").component.git_diff()
115115
function M.git_diff(opts)
@@ -126,7 +126,7 @@ function M.git_diff(opts)
126126
end
127127

128128
--- A function to build a set of children components for a diagnostics section
129-
---@param opts? table options for configuring diagnostic providers and the overall padding
129+
---@param opts? AstroUIComponentDiagnosticsOpts provider options
130130
---@return table # The Heirline component table
131131
-- @usage local heirline_component = require("astroui.status").component.diagnostics()
132132
function M.diagnostics(opts)
@@ -143,7 +143,7 @@ function M.diagnostics(opts)
143143
end
144144

145145
--- A function to build a set of children components for a Treesitter section
146-
---@param opts? table options for configuring diagnostic providers and the overall padding
146+
---@param opts? AstroUIComponentTreesitterOpts provider options
147147
---@return table # The Heirline component table
148148
-- @usage local heirline_component = require("astroui.status").component.treesitter()
149149
function M.treesitter(opts)
@@ -152,7 +152,7 @@ function M.treesitter(opts)
152152
end
153153

154154
--- A function to build a set of children components for an LSP section
155-
---@param opts? table options for configuring lsp progress and client_name providers and the overall padding
155+
---@param opts? AstroUIComponentLspOpts provider options
156156
---@return table # The Heirline component table
157157
-- @usage local heirline_component = require("astroui.status").component.lsp()
158158
function M.lsp(opts)
@@ -173,7 +173,7 @@ function M.lsp(opts)
173173
end
174174

175175
--- A function to build a set of children components for a git branch section
176-
---@param opts? table options for configuring git branch and the overall padding
176+
---@param opts? AstroUIComponentVirtualEnvOpts provider options
177177
---@return table # The Heirline component table
178178
-- @usage local heirline_component = require("astroui.status").component.git_branch()
179179
function M.virtual_env(opts)
@@ -182,7 +182,7 @@ function M.virtual_env(opts)
182182
end
183183

184184
--- A function to build a set of components for a foldcolumn section in a statuscolumn
185-
---@param opts? table options for configuring foldcolumn and the overall padding
185+
---@param opts? AstroUIComponentFoldcolumnOpts provider options
186186
---@return table # The Heirline component table
187187
-- @usage local heirline_component = require("astroui.status").component.foldcolumn()
188188
function M.foldcolumn(opts)
@@ -191,7 +191,7 @@ function M.foldcolumn(opts)
191191
end
192192

193193
--- A function to build a set of components for a numbercolumn section in statuscolumn
194-
---@param opts? table options for configuring numbercolumn and the overall padding
194+
---@param opts? AstroUIComponentNumbercolumnOpts provider options
195195
---@return table # The Heirline component table
196196
-- @usage local heirline_component = require("astroui.status").component.numbercolumn()
197197
function M.numbercolumn(opts)
@@ -200,7 +200,7 @@ function M.numbercolumn(opts)
200200
end
201201

202202
--- A function to build a set of components for a signcolumn section in statuscolumn
203-
---@param opts? table options for configuring signcolumn and the overall padding
203+
---@param opts? AstroUIComponentSigncolumnOpts provider options
204204
---@return table # The Heirline component table
205205
-- @usage local heirline_component = require("astroui.status").component.signcolumn()
206206
function M.signcolumn(opts)
@@ -209,7 +209,7 @@ function M.signcolumn(opts)
209209
end
210210

211211
--- A general function to build a section of astronvim status providers with highlights, conditions, and section surrounding
212-
---@param opts? table a list of components to build into a section
212+
---@param opts? AstroUIComponentBuilderOpts component builder options
213213
---@return table # The Heirline component table
214214
-- @usage local heirline_component = require("astroui.status").components.builder({ { provider = "file_icon", opts = { padding = { right = 1 } } }, { provider = "filename" } })
215215
function M.builder(opts)

lua/astroui/status/config.lua

+115-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
---@field left integer? number of spaces to pad to the left
1212
---@field right integer? number of spaces to pad to the right
1313

14+
---@class AstroUIStatusSurround
15+
---@field separator string|string[]? the separator index to use in the `separators` table
16+
---@field color (fun(self: table): string|table)|string|table? the color to use as the separator foreground/component background
17+
---@field condition (boolean|fun(self: table): boolean?)? the condition for displaying the surrounded component
18+
---@field update AstroUIUpdateEvents? control updating of separators, either a list of events or true to update freely
19+
1420
---@class AstroUIStatusIcon
1521
---@field kind string? the icon name as set in the AstroUI icons
1622
---@field padding AstroUIStatusPadding? padding settings to apply to the icon
@@ -98,7 +104,7 @@
98104
---@class AstroUIProviderLspProgressOpts: AstroUIStatusStylizeOpts
99105

100106
---@class AstroUIProviderLspClientNamesOpts: AstroUIStatusStylizeOpts
101-
---@field integrations { null_ls: boolean?, conform: boolean?, nvim-lint: boolean? } enable or disable client name integrations
107+
---@field integrations { null_ls: boolean?, conform: boolean?, nvim-lint: boolean? }? enable or disable client name integrations
102108
---@field mappings { [string]: (string|fun(client: string): string)? }? add custom client name mappings ("*" will apply to all as a fallback)
103109
---@field truncate number? percentage of statusline of the maximum width before truncation with ellipsis
104110

@@ -143,6 +149,113 @@
143149
---@field treesitter_status AstroUIProviderTreesitterStatusOpts? default options for the `treesitter_status` provider
144150
---@field str AstroUIProviderStrOpts? default options for the `str` provider
145151

152+
---@class AstroUIInitBreadcrumbsOpts
153+
---@field max_depth integer? the maximum depth of breadcrumbs to show moving upwards
154+
---@field separator string? the string to use when separating breadcrumbs
155+
---@field icon { enabled: boolean?, hl: boolean? }? enable/disable icon and it's semantic highlighting
156+
---@field padding AstroUIStatusPadding? padding options for the component
157+
158+
---@class AstroUIInitSeparatedPathOpts
159+
---@field max_depth integer? the maximum depth of breadcrumbs to show moving upwards
160+
---@field path_func (fun(self: table): string)? the function for calculating the path to separate
161+
---@field delimiter string? the string used when splitting the path into pieces
162+
---@field separator string? the string to use for the path separator
163+
---@field prefix boolean? whether or not to apply a prefix of the separator at the start of the path
164+
---@field suffix boolean? whether or not to apply a suffix of the separator at the end of the path
165+
---@field padding AstroUIStatusPadding? padding options for the component
166+
167+
---@class AstroUIComponentBuilderProviderOpts
168+
---@field provider (fun(self: table): string?)|string a statusline provider function or the name of an AstroUI status provider
169+
---@field opts table? a table of options to provide to the provider if the provider is an AstroUI status provider
170+
171+
---Configuration of the component building. Other keys are supported which are all keys which are allowed inside of a Heirline statusline component. See the `heirline` documentation for more details
172+
---@class AstroUIComponentBuilderOpts
173+
---@field padding AstroUIStatusPadding|false? padding options for final component
174+
---@field surround AstroUIStatusSurround|false? surround options for final component
175+
---@field [integer] AstroUIComponentBuilderProviderOpts? table of providers to include in the final component in an ordered list. Must provide a `provider` key
176+
177+
---@class AstroUIComponentFileInfoOpts: AstroUIComponentBuilderOpts
178+
---@field file_icon AstroUIProviderFileIconOpts|false? `file_icon` provider options
179+
---@field unique_path AstroUIProviderUniquePathOpts|false? `unique_path` provider options
180+
---@field filename AstroUIProviderFilenameOpts|false? `filename` provider options
181+
---@field filetype AstroUIProviderFiletypeOpts|false? `filetype` provider options
182+
---@field file_modified AstroUIProviderFileModifiedOpts|false? `file_modified` provider options
183+
---@field file_read_only AstroUIProviderFileReadOnlyOpts|false? `file_read_only` provider options
184+
---@field close_button AstroUIProviderCloseButtonOpts|false? `close_button` provider options
185+
186+
---@class AstroUIComponentTablineFileInfoOpts: AstroUIComponentFileInfoOpts
187+
188+
---@class AstroUIComponentNavOpts: AstroUIComponentBuilderOpts
189+
---@field ruler AstroUIProviderRulerOpts|false? `ruler` provider options
190+
---@field percentage AstroUIProviderPercentageOpts|false? `percentage` provider options
191+
---@field scrollbar AstroUIProviderScrollbarOpts|false? `scrollbar` provider options
192+
193+
---@class AstroUIComponentCmdInfoOpts: AstroUIComponentBuilderOpts
194+
---@field macro_recording AstroUIProviderMacroRecordingOpts|false? `macro_recording` provider options
195+
---@field search_count AstroUIProviderSearchCountOpts|false? `search_count` provider options
196+
---@field showcmd AstroUIProviderShowcmdOpts|false? `showcmd` provider options
197+
198+
---@class AstroUIComponentModeOpts: AstroUIComponentBuilderOpts
199+
---@field mode_text AstroUIProviderModeTextOpts|false? `mode_text` provider options
200+
---@field str AstroUIProviderStrOpts|false? `str` provider options
201+
---@field paste AstroUIProviderPasteOpts|false? `paste` provider options
202+
---@field spell AstroUIProviderSpellOpts|false? `spell` provider options
203+
204+
---@class AstroUIComponentBreadcrumbsOpts: AstroUIInitBreadcrumbsOpts
205+
206+
---@class AstroUIComponentSeparatedPathOpts: AstroUIInitSeparatedPathOpts
207+
208+
---@class AstroUIComponentGitBranchOpts: AstroUIComponentBuilderOpts
209+
---@field git_branch AstroUIProviderGitBranchOpts|false? `git_branch` provider options
210+
211+
---@class AstroUIComponentGitDiffOpts: AstroUIComponentBuilderOpts
212+
---@field added AstroUIProviderGitDiffOpts|false? `git_diff` provider options for added git differences
213+
---@field changed AstroUIProviderGitDiffOpts|false? `git_diff` provider options for changed git differences
214+
---@field removed AstroUIProviderGitDiffOpts|false? `git_diff` provider options for removed git differences
215+
216+
---@class AstroUIComponentDiagnosticsOpts: AstroUIComponentBuilderOpts
217+
---@field ERROR AstroUIProviderDiagnosticsOpts|false? `diagnostics` provider options for errors
218+
---@field WARN AstroUIProviderDiagnosticsOpts|false? `diagnostics` provider options for warnings
219+
---@field INFO AstroUIProviderDiagnosticsOpts|false? `diagnostics` provider options for information
220+
---@field HINT AstroUIProviderDiagnosticsOpts|false? `diagnostics` provider options for hints
221+
222+
---@class AstroUIComponentTreesitterOpts: AstroUIComponentBuilderOpts
223+
---@field str AstroUIProviderStrOpts|false? `str` provider options for when treesitter is available
224+
225+
---@class AstroUIComponentLspOpts: AstroUIComponentBuilderOpts
226+
---@field lsp_progress AstroUIProviderLspProgressOpts|false? `lsp_progress` provider options
227+
---@field lsp_client_names AstroUIProviderLspClientNamesOpts|false? `lsp_client_names` provider options
228+
229+
---@class AstroUIComponentVirtualEnvOpts: AstroUIComponentBuilderOpts
230+
---@field virtual_env AstroUIProviderVirtualEnvOpts|false? `virtual_env` provider options
231+
232+
---@class AstroUIComponentFoldcolumnOpts: AstroUIComponentBuilderOpts
233+
---@field foldcolumn AstroUIProviderFoldcolumnOpts|false? `foldcolumn` provider options
234+
235+
---@class AstroUIComponentNumbercolumnOpts: AstroUIComponentBuilderOpts
236+
---@field numbercolumn AstroUIProviderNumbercolumnOpts|false? `numbercolumn` provider options
237+
238+
---@class AstroUIComponentSigncolumnOpts: AstroUIComponentBuilderOpts
239+
---@field signcolumn AstroUIProviderSigncolumnOpts|false? `signcolumn` provider options
240+
241+
---@class AstroUIComponents
242+
---@field file_info AstroUIComponentFileInfoOpts? default options for the `file_info` component
243+
---@field tabline_file_info AstroUIComponentTablineFileInfoOpts? default options for the `tabline_file_info` component
244+
---@field nav AstroUIComponentNavOpts? default options for the `nav` component
245+
---@field cmd_info AstroUIComponentCmdInfoOpts? default options for the `cmd_info` component
246+
---@field mode AstroUIComponentModeOpts? default options for the `mode` component
247+
---@field breadcrumbs AstroUIComponentBreadcrumbsOpts? default options for the `breadcrumbs` component
248+
---@field separated_path AstroUIComponentSeparatedPathOpts? default options for the `separated_path` component
249+
---@field git_branch AstroUIComponentGitBranchOpts? default options for the `git_branch` component
250+
---@field git_diff AstroUIComponentGitDiffOpts? default options for the `git_diff` component
251+
---@field diagnostics AstroUIComponentDiagnosticsOpts? default options for the `diagnostics` component
252+
---@field treesitter AstroUIComponentTreesitterOpts? default options for the `treesitter` component
253+
---@field lsp AstroUIComponentLspOpts? default options for the `lsp` component
254+
---@field virtual_env AstroUIComponentVirtualEnvOpts? default options for the `virtual_env` component
255+
---@field foldcolumn AstroUIComponentFoldcolumnOpts? default options for the `foldcolumn` component
256+
---@field numbercolumn AstroUIComponentNumbercolumnOpts? default options for the `numbercolumn` component
257+
---@field signcolumn AstroUIComponentSigncolumnOpts? default options for the `signcolumn` component
258+
146259
---@class AstroUISeparators
147260
---@field none string[]? placeholder separator for elements with "no" separator, typically two empty strings
148261
---@field left string[]? Separators used for elements designated as being on the left of the statusline
@@ -185,7 +298,7 @@
185298
--- }
186299
---}
187300
---```
188-
---@field components table?
301+
---@field components AstroUIComponents?
189302
---**MEANT FOR INTERNAL USE ONLY**
190303
---A table of fallback colors if a colorscheme used by the user does not have a highlight group, the entry point to this are typically through the `status.colors` option.
191304
---@field fallback_colors StringMap?

lua/astroui/status/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local provider = require "astroui.status.provider"
1919
local status_utils = require "astroui.status.utils"
2020

2121
--- An `init` function to build a set of children components for LSP breadcrumbs
22-
---@param opts? table # options for configuring the breadcrumbs (default: `{ max_depth = 5, separator = "  ", icon = { enabled = true, hl = false }, padding = { left = 0, right = 0 } }`)
22+
---@param opts? AstroUIInitBreadcrumbsOpts component init options
2323
---@return function # The Heirline init function
2424
-- @usage local heirline_component = { init = require("astroui.status").init.breadcrumbs { padding = { left = 1 } } }
2525
function M.breadcrumbs(opts)
@@ -80,7 +80,7 @@ function M.breadcrumbs(opts)
8080
end
8181

8282
--- An `init` function to build a set of children components for a separated path to file
83-
---@param opts? table options for configuring the breadcrumbs (default: `{ max_depth = 3, path_func = provider.unique_path(), delimiter = "/", separator = "", suffix = true, padding = { left = 0, right = 0 } }`)
83+
---@param opts? AstroUIInitSeparatedPathOpts component init options
8484
---@return function # The Heirline init function
8585
-- @usage local heirline_component = { init = require("astroui.status").init.separated_path { padding = { left = 1 } } }
8686
function M.separated_path(opts)

0 commit comments

Comments
 (0)