Skip to content

Commit 588db8e

Browse files
committed
refactor(config, modules): add types
1 parent 9f9bc89 commit 588db8e

28 files changed

+254
-74
lines changed

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

+34-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ 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+
---@alias GhTheme.HighlightGroup.Style
8+
---| "NONE"
9+
---| "bold"
10+
---| "standout"
11+
---| "underline"
12+
---| "undercurl"
13+
---| "underdouble"
14+
---| "underdotted"
15+
---| "underdashed"
16+
---| "strikethrough"
17+
---| "italic"
18+
---| "reverse"
19+
---| "nocombine"
20+
---| string
21+
22+
---A Neovim highlight-group definition.
23+
---@class (exact) GhTheme.HighlightGroup
24+
---@field fg? GhTheme.Color.CSSHexString
25+
---@field bg? GhTheme.Color.CSSHexString
26+
---@field sp? GhTheme.Color.CSSHexString
27+
---@field style? GhTheme.HighlightGroup.Style
28+
---@field blend? integer
29+
---@field nocombine? boolean
30+
---@field link? string
31+
---@field force? boolean
32+
33+
---@param spec GhTheme.Spec
34+
---@return table<string, GhTheme.HighlightGroup>
635
function M.from(spec)
736
local config = require('github-theme.config').options
837

@@ -44,9 +73,11 @@ function M.from(spec)
4473
return res
4574
end
4675

47-
function M.load(name)
48-
name = name or require('github-theme.config').theme
49-
return M.from(require('github-theme.spec').load(name))
76+
---@param theme? GhTheme.Theme
77+
---@return table<string, GhTheme.HighlightGroup>
78+
function M.load(theme)
79+
theme = theme or require('github-theme.config').theme
80+
return M.from(require('github-theme.spec').load(theme))
5081
end
5182

5283
return M

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

+5-1
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 table
8+
function M.get(spec, config, _opts)
69
local has_ts = config.modules.treesitter
710
local syn = spec.syntax
811

912
-- stylua: ignore
13+
---@type table<string, GhTheme.HighlightGroup>
1014
return {
1115
CmpDocumentation = { fg = spec.fg1, bg = spec.bg0 },
1216
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 table
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 table
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 table
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 table
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 table
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 table
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 table
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 table
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 table
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 table
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|

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ local C = require('github-theme.lib.color')
44

55
local M = {}
66

7-
function M.get(spec, config, opts)
7+
---@param spec GhTheme.Spec
8+
---@param _config GhTheme.Config.Options
9+
---@param _opts table
10+
function M.get(spec, _config, _opts)
811
local p = spec.palette
912

1013
local fg = C(spec.bg1):blend(C(spec.fg1), 0.1):to_css()
1114
local cyan_fg = C(spec.bg1):blend(C(p.cyan.bright), 0.35):to_css()
1215

1316
-- stylua: ignore
17+
---@type table<string, GhTheme.HighlightGroup>
1418
return {
1519
IndentBlanklineChar = { fg = fg },
1620
IndentBlanklineContextChar = { fg = cyan_fg },

0 commit comments

Comments
 (0)