Skip to content

Commit 0eb4214

Browse files
authored
chore: improve types (#118)
1 parent 4651da4 commit 0eb4214

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

lua/one_monokai/colors.lua

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
---@class one_monokai.colors
2+
---@field [string] string|number
13
local colors = {}
24

3-
---@class colors
5+
---@type one_monokai.colors
46
local defaults = {
57
fg = "#abb2bf",
68
bg = "#282c34",
@@ -27,12 +29,11 @@ local defaults = {
2729
none = "NONE",
2830
}
2931

30-
---@type colors
3132
colors = vim.deepcopy(defaults)
3233

33-
---Converts a hex color to an RGB table
34-
---@param color string #Hex color
35-
---@return integer[] #RGB table {r, g, b}
34+
---Converts a hex color to an RGB table.
35+
---@param color string #Hex color.
36+
---@return integer[] #RGB table {r, g, b}.
3637
local function hex2rgb(color)
3738
color = color:lower()
3839

@@ -45,11 +46,11 @@ end
4546

4647
---Blends two hex colors together based on the alpha value.
4748
---
48-
---[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua)
49-
---@param fg string #Foreground hex color
50-
---@param bg string #Background hex color
51-
---@param alpha number #Blend factor between 0 (only bg) and 1 (only fg)
52-
---@return string #Hex color of the resulting blended color
49+
---[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua).
50+
---@param fg string #Foreground hex color.
51+
---@param bg string #Background hex color.
52+
---@param alpha number #Blend factor between 0 (only bg) and 1 (only fg).
53+
---@return string #Hex color of the resulting blended color.
5354
local function blend(fg, bg, alpha)
5455
local bg_rgb = hex2rgb(bg)
5556
local fg_rgb = hex2rgb(fg)
@@ -61,25 +62,25 @@ local function blend(fg, bg, alpha)
6162
return ("#%02x%02x%02x"):format(r, g, b)
6263
end
6364

64-
---Darkens the current hex color
65+
---Darkens the current hex color.
6566
---@param s string
66-
---@param alpha number #Value between 0 and 1
67+
---@param alpha number #Value between 0 and 1.
6768
function string.darken(s, alpha)
6869
return blend(s, "#000000", alpha)
6970
end
7071

71-
---Lightens the current hex color
72+
---Lightens the current hex color.
7273
---@param s string
73-
---@param alpha number #Value between 0 and 1
74+
---@param alpha number #Value between 0 and 1.
7475
function string.lighten(s, alpha)
7576
return blend(s, "#ffffff", alpha)
7677
end
7778

78-
---Resolve and retrieve the value of a color
79-
---@param name string #Name of the color
80-
---@param value string|number #Value of the color
81-
---@return string|number? #Hex color or 24-bit RGB value, or default if invalid
82-
local function resolve_color(name, value)
79+
---Resolve and retrieve the value of a color.
80+
---@param name string #Name of the color.
81+
---@param value string|number #Value of the color.
82+
---@return string|number? #Hex color or 24-bit RGB value, or default if invalid.
83+
local function resolve(name, value)
8384
local color_type = type(value)
8485

8586
-- Resolve string first to optimize the common case
@@ -115,7 +116,7 @@ end
115116
local config = require "one_monokai.config"
116117

117118
for name, value in pairs(config.colors or {}) do
118-
colors[name] = resolve_color(name, value)
119+
colors[name] = resolve(name, value)
119120
end
120121

121122
return colors

lua/one_monokai/config.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
---@class one_monokai.config
2+
---@field transparent boolean #Whether to enable transparent background.
3+
---@field colors? one_monokai.colors #Custom colors.
4+
---@field highlights? fun(colors:one_monokai.colors):one_monokai.highlights.groups #Custom highlight groups.
5+
---@field italics boolean #Whether to apply italics to certain highlight groups.
16
local config = {}
27

3-
---@class options
4-
---@field transparent boolean #Whether to enable transparent background
5-
---@field colors? colors #Custom colors
6-
---@field highlights? fun(colors:colors):groups #Custom highlight groups
7-
---@field italics boolean #Whether to apply italics to certain highlight groups
8+
---@type one_monokai.config
89
local defaults = {
910
transparent = false,
1011
colors = nil,
@@ -14,11 +15,10 @@ local defaults = {
1415
italics = true,
1516
}
1617

17-
---@type options
1818
local options = vim.deepcopy(defaults)
1919

20-
---Extend default with user's config
21-
---@param opts options
20+
---Extend default with user's config.
21+
---@param opts one_monokai.config
2222
function config.extend(opts)
2323
if not opts or vim.tbl_isempty(opts) then
2424
return

lua/one_monokai/highlights/groups.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
---@class one_monokai.highlights.groups
2+
---@field [string] vim.api.keyset.highlight
13
local groups = {}
24

35
local colors = require "one_monokai.colors"
46
local config = require "one_monokai.config"
57

6-
---@class groups
8+
---@type one_monokai.highlights.groups
79
local defaults = {
810
Boolean = { fg = colors.cyan },
911
Character = { fg = colors.yellow },
@@ -764,15 +766,13 @@ local defaults = {
764766
SnacksPickerMatch = { fg = colors.green },
765767
}
766768

767-
-- hide all semantic highlights by default,
768-
-- only enable those from the default table
769+
-- Hide all semantic highlights by default, only enable those from the default table.
769770
for _, semantic_group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
770771
if not defaults[semantic_group] then
771772
defaults[semantic_group] = {}
772773
end
773774
end
774775

775-
---@type groups
776776
groups = vim.deepcopy(defaults)
777777

778778
return groups

lua/one_monokai/highlights/init.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
---@class one_monokai.highlights
12
local highlights = {}
23

3-
---Set highlight groups
4-
---@param groups groups #Highlight groups
4+
---Set highlight groups.
5+
---@param groups one_monokai.highlights.groups #Highlight groups.
56
local function set_highlight(groups)
67
local logs = require "one_monokai.logs"
78
local set_hl = vim.api.nvim_set_hl
@@ -15,7 +16,7 @@ local function set_highlight(groups)
1516
end
1617
end
1718

18-
---Load all highlight groups
19+
---Load all highlight groups.
1920
function highlights.load()
2021
local config = require "one_monokai.config"
2122
local default = require "one_monokai.highlights.groups"

lua/one_monokai/logs.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
---@class logs
1+
---@class one_monokai.logs
22
local logs = {}
33

4-
---Display a notification to the user
4+
---Display a notification to the user.
55
---@param level vim.log.levels
66
---@param s string|number
77
---@param ... any
@@ -13,14 +13,14 @@ local function notify(level, s, ...)
1313
})
1414
end
1515

16-
---Display an error message to the user
16+
---Display an error message to the user.
1717
---@param s string|number
1818
---@param ... any
1919
logs.error = function(s, ...)
2020
notify(vim.log.levels.ERROR, s, ...)
2121
end
2222

23-
---Display a warning message to the user
23+
---Display a warning message to the user.
2424
---@param s string|number
2525
---@param ... any
2626
logs.warning = function(s, ...)

0 commit comments

Comments
 (0)