Skip to content

Commit 98db85c

Browse files
authored
refactor(config, modules): add types (#354)
Add and improve types (LSP) for groups, config, and modules.
1 parent 9f9bc89 commit 98db85c

29 files changed

+266
-79
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Assigning `false` to groups/specs/palettes clears previous settings from the config store
2020
- Loading/sourcing colorscheme now causes recompilation if config or overrides changed, even if `setup()` was called before
2121
- Refactored and improved `Color` lib (LSP types and descriptions, code-dedupe, stricter ctor, etc.) (#352)
22+
- Added and improved types (LSP) for groups, config, and modules (#354)
2223

2324
### Changes
2425

lua/github-theme/config.lua

+78-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
11
local collect = require('github-theme.lib.collect')
22
local util = require('github-theme.util')
3-
43
local M = { theme = 'github_dark', has_options = false }
54

5+
-- TODO: improve type of `specs` and `palettes`
6+
---@class (exact) GhTheme.Config
7+
---@field options? GhTheme.Config.Options
8+
---@field palettes? table
9+
---@field specs? table
10+
---@field groups? table<GhTheme.Theme|"all", table<string, GhTheme.HighlightGroup>>
11+
12+
---@class (exact) GhTheme.Config.Module
13+
---@field enable? boolean whether to set plugin-specific highlights for this module/plugin
14+
15+
---@class (exact) GhTheme.Config.Module.Coc: GhTheme.Config.Module
16+
---@field background? boolean whether to set background color of virtual text
17+
18+
---@class (exact) GhTheme.Config.Module.Diagnostic: GhTheme.Config.Module
19+
---@field background? boolean whether to set background color of virtual text
20+
21+
---@class (exact) GhTheme.Config.Module.NativeLSP: GhTheme.Config.Module
22+
---@field background? boolean whether to set background color of virtual text
23+
24+
---Config for external modules/plugins.
25+
---@class (exact) GhTheme.Config.Options.Modules
26+
---@field cmp? boolean|GhTheme.Config.Module
27+
---@field coc? boolean|GhTheme.Config.Module.Coc
28+
---@field coc_explorer? boolean|GhTheme.Config.Module
29+
---@field dapui? boolean|GhTheme.Config.Module
30+
---@field diffchar? boolean|GhTheme.Config.Module
31+
---@field dashboard? boolean|GhTheme.Config.Module
32+
---@field diagnostic? boolean|GhTheme.Config.Module.Diagnostic
33+
---@field fidget? boolean|GhTheme.Config.Module
34+
---@field fzf? boolean|GhTheme.Config.Module
35+
---@field gitgutter? boolean|GhTheme.Config.Module
36+
---@field gitsigns? boolean|GhTheme.Config.Module
37+
---@field indent_blankline? boolean|GhTheme.Config.Module
38+
---@field lsp_semantic_tokens? boolean|GhTheme.Config.Module
39+
---@field lsp_trouble? boolean|GhTheme.Config.Module
40+
---@field mini? boolean|GhTheme.Config.Module
41+
---@field native_lsp? boolean|GhTheme.Config.Module.NativeLSP
42+
---@field neogit? boolean|GhTheme.Config.Module
43+
---@field neotree? boolean|GhTheme.Config.Module
44+
---@field notify? boolean|GhTheme.Config.Module
45+
---@field nvimtree? boolean|GhTheme.Config.Module
46+
---@field telescope? boolean|GhTheme.Config.Module
47+
---@field treesitter? boolean|GhTheme.Config.Module
48+
---@field treesitter_context? boolean|GhTheme.Config.Module
49+
---@field whichkey? boolean|GhTheme.Config.Module
50+
51+
---@class GhTheme.Config.Options
652
local defaults = {
753
compile_file_suffix = '_compiled',
854
compile_path = util.join_paths(util.cache_home, 'github-theme'),
@@ -13,15 +59,34 @@ local defaults = {
1359
dim_inactive = false,
1460
module_default = true,
1561
styles = {
62+
---@type GhTheme.HighlightGroup.Style
1663
comments = 'NONE',
64+
65+
---@type GhTheme.HighlightGroup.Style
1766
functions = 'NONE',
67+
68+
---@type GhTheme.HighlightGroup.Style
1869
keywords = 'NONE',
70+
71+
---@type GhTheme.HighlightGroup.Style
1972
variables = 'NONE',
73+
74+
---@type GhTheme.HighlightGroup.Style
2075
conditionals = 'NONE',
76+
77+
---@type GhTheme.HighlightGroup.Style
2178
constants = 'NONE',
79+
80+
---@type GhTheme.HighlightGroup.Style
2281
numbers = 'NONE',
82+
83+
---@type GhTheme.HighlightGroup.Style
2384
operators = 'NONE',
85+
86+
---@type GhTheme.HighlightGroup.Style
2487
strings = 'NONE',
88+
89+
---@type GhTheme.HighlightGroup.Style
2590
types = 'NONE',
2691
},
2792
inverse = {
@@ -33,9 +98,12 @@ local defaults = {
3398
floats = true,
3499
sidebars = {
35100
enable = true,
101+
---List of (filetype or `'terminal'`) whose bg will be darkened.
36102
list = {},
37103
},
38104
},
105+
106+
---@type GhTheme.Config.Options.Modules
39107
modules = {
40108
coc = {
41109
background = true,
@@ -55,6 +123,12 @@ local defaults = {
55123
},
56124
}
57125

126+
-- The following is done to disallow the addition of any more fields.
127+
128+
---@type GhTheme.Config.Options
129+
---@diagnostic disable-next-line: redefined-local
130+
local defaults = defaults
131+
58132
M.options = collect.deep_copy(defaults)
59133

60134
M.module_names = {
@@ -84,10 +158,12 @@ M.module_names = {
84158
'whichkey',
85159
}
86160

161+
---@param name GhTheme.Theme
87162
function M.set_theme(name)
88163
M.theme = name
89164
end
90165

166+
---@param opts GhTheme.Config.Options
91167
function M.set_options(opts)
92168
opts = opts or {}
93169
M.options = collect.deep_extend(M.options, opts)
@@ -107,7 +183,7 @@ end
107183

108184
function M.hash()
109185
local hash = require('github-theme.lib.hash')(M.options)
110-
return hash and hash or 0
186+
return hash or 0
111187
end
112188

113189
return M

lua/github-theme/group.lua

+40-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@ local template = require('github-theme.util.template')
33
local override = require('github-theme.override')
44
local M = {}
55

6+
---A string whose contents is a comma-separated list of styles.
7+
---
8+
---## Examples
9+
---```lua
10+
---group.style = "bold,italic,underline"
11+
---group.style = "NONE"
12+
---```
13+
---@alias GhTheme.HighlightGroup.Style
14+
---| "NONE"
15+
---| "bold"
16+
---| "standout"
17+
---| "underline"
18+
---| "undercurl"
19+
---| "underdouble"
20+
---| "underdotted"
21+
---| "underdashed"
22+
---| "strikethrough"
23+
---| "italic"
24+
---| "reverse"
25+
---| "nocombine"
26+
---| string
27+
28+
---A Neovim highlight-group definition.
29+
---@class (exact) GhTheme.HighlightGroup
30+
---@field fg? GhTheme.Color.CSSHexString
31+
---@field bg? GhTheme.Color.CSSHexString
32+
---@field sp? GhTheme.Color.CSSHexString
33+
---@field style? GhTheme.HighlightGroup.Style
34+
---@field blend? integer
35+
---@field nocombine? boolean
36+
---@field link? string
37+
---@field force? boolean
38+
39+
---@param spec GhTheme.Spec
40+
---@return table<string, GhTheme.HighlightGroup>
641
function M.from(spec)
742
local config = require('github-theme.config').options
843

@@ -44,9 +79,11 @@ function M.from(spec)
4479
return res
4580
end
4681

47-
function M.load(name)
48-
name = name or require('github-theme.config').theme
49-
return M.from(require('github-theme.spec').load(name))
82+
---@param theme? GhTheme.Theme
83+
---@return table<string, GhTheme.HighlightGroup>
84+
function M.load(theme)
85+
theme = theme or require('github-theme.config').theme
86+
return M.from(require('github-theme.spec').load(theme))
5087
end
5188

5289
return M

lua/github-theme/group/modules/cmp.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
6-
local has_ts = config.modules.treesitter
5+
---@param spec GhTheme.Spec
6+
---@param config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, config, _opts)
9+
local has_ts = config.modules.treesitter == true
10+
or type(config.modules.treesitter) == 'table' and config.modules.treesitter.enable
711
local syn = spec.syntax
812

913
-- stylua: ignore
14+
---@type table<string, GhTheme.HighlightGroup>
1015
return {
1116
CmpDocumentation = { fg = spec.fg1, bg = spec.bg0 },
1217
CmpDocumentationBorder = { fg = spec.sel0, bg = spec.bg0 },

lua/github-theme/group/modules/coc.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param opts GhTheme.Config.Module.Coc
8+
function M.get(spec, _config, opts)
69
local syn = spec.syntax
710

11+
---@type table<string, GhTheme.HighlightGroup>
812
return {
913
CocInlayHint = { fg = syn.comment, bg = opts.background and spec.bg2 or 'NONE' },
1014
}

lua/github-theme/group/modules/coc_explorer.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
9+
---@type table<string, GhTheme.HighlightGroup>
610
return {
711
CocExplorerNormalFloat = { link = 'NormalSB' },
812

lua/github-theme/group/modules/dapui.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
69
local c = spec.palette
710

811
-- stylua: ignore
12+
---@type table<string, GhTheme.HighlightGroup>
913
return {
1014
DapUIScope = { fg = c.cyan.base },
1115
DapUIType = { fg = c.magenta.base },

lua/github-theme/group/modules/dashboard.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
69
-- stylua: ignore
10+
---@type table<string, GhTheme.HighlightGroup>
711
return {
812
DashboardShortCut = { link = 'Identifier' },
913
DashboardHeader = { link = 'Title' },

lua/github-theme/group/modules/diagnostic.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
local M = {}
22

3-
function M.get(spec, config, opts)
3+
---@param spec GhTheme.Spec
4+
---@param _config GhTheme.Config.Options
5+
---@param opts GhTheme.Config.Module.Diagnostic
6+
function M.get(spec, _config, opts)
47
local d = spec.diag
58
local dbg = spec.diag_bg
69

710
-- stylua: ignore
11+
---@type table<string, GhTheme.HighlightGroup>
812
return {
913
DiagnosticError = { fg = d.error },
1014
DiagnosticWarn = { fg = d.warn },
@@ -17,9 +21,9 @@ function M.get(spec, config, opts)
1721
DiagnosticSignHint = { link = 'DiagnosticHint' },
1822

1923
DiagnosticVirtualTextError = { fg = d.error, bg = opts.background and dbg.error or 'NONE' },
20-
DiagnosticVirtualTextWarn = { fg = d.warn, bg = opts.background and dbg.warn or 'NONE' },
21-
DiagnosticVirtualTextInfo = { fg = d.info, bg = opts.background and dbg.info or 'NONE' },
22-
DiagnosticVirtualTextHint = { fg = d.hint, bg = opts.background and dbg.hint or 'NONE' },
24+
DiagnosticVirtualTextWarn = { fg = d.warn, bg = opts.background and dbg.warn or 'NONE' },
25+
DiagnosticVirtualTextInfo = { fg = d.info, bg = opts.background and dbg.info or 'NONE' },
26+
DiagnosticVirtualTextHint = { fg = d.hint, bg = opts.background and dbg.hint or 'NONE' },
2327

2428
DiagnosticUnderlineError = { style = 'undercurl', sp = d.error },
2529
DiagnosticUnderlineWarn = { style = 'undercurl', sp = d.warn },

lua/github-theme/group/modules/diffchar.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
9+
---@type table<string, GhTheme.HighlightGroup>
610
return {
711
DiffAdd = { link = 'diffAdded' },
812
DiffChange = { link = 'diffChanged' },

lua/github-theme/group/modules/fidget.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param _spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(_spec, _config, _opts)
69
-- stylua: ignore
10+
---@type table<string, GhTheme.HighlightGroup>
711
return {
812
FidgetTitle = { link = 'Title' },
9-
FidgetTask = { link = 'LineNr' },
13+
FidgetTask = { link = 'LineNr' },
1014
}
1115
end
1216

lua/github-theme/group/modules/fzf.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param _spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(_spec, _config, _opts)
69
-- stylua: ignore
10+
---@type table<string, GhTheme.HighlightGroup>
711
return {
812
FzfLuaNormal = { link = 'Normal' },
913
FzfLuaBorder = { link = 'Normal' },

lua/github-theme/group/modules/gitgutter.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
69
local git = spec.git
710

811
-- stylua: ignore
12+
---@type table<string, GhTheme.HighlightGroup>
913
return {
1014
GitGutterAdd = { fg = git.add }, -- diff mode: Added line |diff.txt|
1115
GitGutterChange = { fg = git.changed }, -- diff mode: Changed line |diff.txt|

lua/github-theme/group/modules/gitsigns.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
local M = {}
44

5-
function M.get(spec, config, opts)
5+
---@param spec GhTheme.Spec
6+
---@param _config GhTheme.Config.Options
7+
---@param _opts GhTheme.Config.Module
8+
function M.get(spec, _config, _opts)
69
local git = spec.git
710

811
-- stylua: ignore
12+
---@type table<string, GhTheme.HighlightGroup>
913
return {
1014
GitSignsAdd = { fg = git.add }, -- diff mode: Added line |diff.txt|
1115
GitSignsChange = { fg = git.changed }, -- diff mode: Changed line |diff.txt|

0 commit comments

Comments
 (0)