diff --git a/lua/one_monokai/colors.lua b/lua/one_monokai/colors.lua index aef792e..151d0cf 100644 --- a/lua/one_monokai/colors.lua +++ b/lua/one_monokai/colors.lua @@ -1,6 +1,8 @@ +---@class one_monokai.colors +---@field [string] string|number local colors = {} ----@class colors +---@type one_monokai.colors local defaults = { fg = "#abb2bf", bg = "#282c34", @@ -27,12 +29,11 @@ local defaults = { none = "NONE", } ----@type colors colors = vim.deepcopy(defaults) ----Converts a hex color to an RGB table ----@param color string #Hex color ----@return integer[] #RGB table {r, g, b} +---Converts a hex color to an RGB table. +---@param color string #Hex color. +---@return integer[] #RGB table {r, g, b}. local function hex2rgb(color) color = color:lower() @@ -45,11 +46,11 @@ end ---Blends two hex colors together based on the alpha value. --- ----[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua) ----@param fg string #Foreground hex color ----@param bg string #Background hex color ----@param alpha number #Blend factor between 0 (only bg) and 1 (only fg) ----@return string #Hex color of the resulting blended color +---[View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua). +---@param fg string #Foreground hex color. +---@param bg string #Background hex color. +---@param alpha number #Blend factor between 0 (only bg) and 1 (only fg). +---@return string #Hex color of the resulting blended color. local function blend(fg, bg, alpha) local bg_rgb = hex2rgb(bg) local fg_rgb = hex2rgb(fg) @@ -61,25 +62,25 @@ local function blend(fg, bg, alpha) return ("#%02x%02x%02x"):format(r, g, b) end ----Darkens the current hex color +---Darkens the current hex color. ---@param s string ----@param alpha number #Value between 0 and 1 +---@param alpha number #Value between 0 and 1. function string.darken(s, alpha) return blend(s, "#000000", alpha) end ----Lightens the current hex color +---Lightens the current hex color. ---@param s string ----@param alpha number #Value between 0 and 1 +---@param alpha number #Value between 0 and 1. function string.lighten(s, alpha) return blend(s, "#ffffff", alpha) end ----Resolve and retrieve the value of a color ----@param name string #Name of the color ----@param value string|number #Value of the color ----@return string|number? #Hex color or 24-bit RGB value, or default if invalid -local function resolve_color(name, value) +---Resolve and retrieve the value of a color. +---@param name string #Name of the color. +---@param value string|number #Value of the color. +---@return string|number? #Hex color or 24-bit RGB value, or default if invalid. +local function resolve(name, value) local color_type = type(value) -- Resolve string first to optimize the common case @@ -115,7 +116,7 @@ end local config = require "one_monokai.config" for name, value in pairs(config.colors or {}) do - colors[name] = resolve_color(name, value) + colors[name] = resolve(name, value) end return colors diff --git a/lua/one_monokai/config.lua b/lua/one_monokai/config.lua index f2bbc99..ddd19ac 100644 --- a/lua/one_monokai/config.lua +++ b/lua/one_monokai/config.lua @@ -1,10 +1,11 @@ +---@class one_monokai.config +---@field transparent boolean #Whether to enable transparent background. +---@field colors? one_monokai.colors #Custom colors. +---@field highlights? fun(colors:one_monokai.colors):one_monokai.highlights.groups #Custom highlight groups. +---@field italics boolean #Whether to apply italics to certain highlight groups. local config = {} ----@class options ----@field transparent boolean #Whether to enable transparent background ----@field colors? colors #Custom colors ----@field highlights? fun(colors:colors):groups #Custom highlight groups ----@field italics boolean #Whether to apply italics to certain highlight groups +---@type one_monokai.config local defaults = { transparent = false, colors = nil, @@ -14,11 +15,10 @@ local defaults = { italics = true, } ----@type options local options = vim.deepcopy(defaults) ----Extend default with user's config ----@param opts options +---Extend default with user's config. +---@param opts one_monokai.config function config.extend(opts) if not opts or vim.tbl_isempty(opts) then return diff --git a/lua/one_monokai/highlights/groups.lua b/lua/one_monokai/highlights/groups.lua index b975dbc..2e0350b 100644 --- a/lua/one_monokai/highlights/groups.lua +++ b/lua/one_monokai/highlights/groups.lua @@ -1,9 +1,11 @@ +---@class one_monokai.highlights.groups +---@field [string] vim.api.keyset.highlight local groups = {} local colors = require "one_monokai.colors" local config = require "one_monokai.config" ----@class groups +---@type one_monokai.highlights.groups local defaults = { Boolean = { fg = colors.cyan }, Character = { fg = colors.yellow }, @@ -764,15 +766,13 @@ local defaults = { SnacksPickerMatch = { fg = colors.green }, } --- hide all semantic highlights by default, --- only enable those from the default table +-- Hide all semantic highlights by default, only enable those from the default table. for _, semantic_group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do if not defaults[semantic_group] then defaults[semantic_group] = {} end end ----@type groups groups = vim.deepcopy(defaults) return groups diff --git a/lua/one_monokai/highlights/init.lua b/lua/one_monokai/highlights/init.lua index 0ed3894..60e2d80 100644 --- a/lua/one_monokai/highlights/init.lua +++ b/lua/one_monokai/highlights/init.lua @@ -1,7 +1,8 @@ +---@class one_monokai.highlights local highlights = {} ----Set highlight groups ----@param groups groups #Highlight groups +---Set highlight groups. +---@param groups one_monokai.highlights.groups #Highlight groups. local function set_highlight(groups) local logs = require "one_monokai.logs" local set_hl = vim.api.nvim_set_hl @@ -15,7 +16,7 @@ local function set_highlight(groups) end end ----Load all highlight groups +---Load all highlight groups. function highlights.load() local config = require "one_monokai.config" local default = require "one_monokai.highlights.groups" diff --git a/lua/one_monokai/logs.lua b/lua/one_monokai/logs.lua index fb2e82d..9bd5d8f 100644 --- a/lua/one_monokai/logs.lua +++ b/lua/one_monokai/logs.lua @@ -1,7 +1,7 @@ ----@class logs +---@class one_monokai.logs local logs = {} ----Display a notification to the user +---Display a notification to the user. ---@param level vim.log.levels ---@param s string|number ---@param ... any @@ -13,14 +13,14 @@ local function notify(level, s, ...) }) end ----Display an error message to the user +---Display an error message to the user. ---@param s string|number ---@param ... any logs.error = function(s, ...) notify(vim.log.levels.ERROR, s, ...) end ----Display a warning message to the user +---Display a warning message to the user. ---@param s string|number ---@param ... any logs.warning = function(s, ...)