From 0a409f31515336383b7e98c3ee956f7bcdc29345 Mon Sep 17 00:00:00 2001 From: nbr Date: Sun, 1 Oct 2023 10:31:22 +0200 Subject: [PATCH] DEV-102 feat: improve type handling --- .gitignore | 3 +- .luarc.json | 2 +- README.md | 2 +- lua/terra-core/actions/config.lua | 5 +- lua/terra-core/actions/files.lua | 2 +- lua/terra-core/config.lua | 2 + lua/terra-core/themes/control/day.lua | 1 + lua/terra-core/themes/fall/day.lua | 1 + lua/terra-core/themes/kurzgesagt/day.lua | 1 + lua/terra-core/themes/spring/day.lua | 1 + lua/terra-core/themes/summer/day.lua | 1 + lua/terra-core/themes/winter/day.lua | 1 + lua/terra-core/types.lua | 76 ++++++++++++------------ 13 files changed, 55 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index f974b20d..9d18d8e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ debug -service.log check.json -file_Users_nikolausbrunner_Documents_dev_repos_terra-theme_core.nvim_._lua.log +*.log diff --git a/.luarc.json b/.luarc.json index cf739dad..eab04aca 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,5 +1,5 @@ { "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", - "Lua.diagnostics.disable": [], + "Lua.diagnostics.disable": ["undefined-global"], "Lua.diagnostics.globals": ["vim"] } diff --git a/README.md b/README.md index a14e868f..65ee5b65 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This is all a work in progress. Lint whole project with `lua-language-server` while respecting the `.luarc.json`. ```bash -lua-language-server --check ./lua --checklevel=Warning --logpath . --configpath /Users/nikolausbrunner/Documents/dev/repos/terra-theme/core.nvim/.luarc.json +lua-language-server --check ./lua --checklevel=Warning --logpath . --configpath /Users/nikolausbrunner/Documents/dev/repos/terra-theme/terra-core.nvim/.luarc.json ``` > Note: This currently works only with absolute paths. This seems to be a bug in `lua-language-server`, and I commented on a similar issue [here](https://github.com/LuaLS/lua-language-server/issues/2038#issuecomment-1500215468). diff --git a/lua/terra-core/actions/config.lua b/lua/terra-core/actions/config.lua index ff55c85a..c8024a7b 100644 --- a/lua/terra-core/actions/config.lua +++ b/lua/terra-core/actions/config.lua @@ -114,13 +114,16 @@ function M.select_variant() icon = vim.g.terra_config.icons[selected_variant], }) + -- construct colorscheme name + local colorscheme_name = "terra_" .. vim.g.terra_config.theme .. "_" .. selected_variant + M.set_options({ variant = selected_variant, }) M.sync_vim_opt_background_with_terra_variant(vim.g.terra_config.variant) - reload_colorscheme() + reload_colorscheme(colorscheme_name) end ---@param item unknown diff --git a/lua/terra-core/actions/files.lua b/lua/terra-core/actions/files.lua index a3ec55fb..0964ecb7 100644 --- a/lua/terra-core/actions/files.lua +++ b/lua/terra-core/actions/files.lua @@ -4,7 +4,7 @@ local M = {} ---@return string function M.get_plugin_path() local runtimepaths = vim.api.nvim_get_option("runtimepath") - local plugin_path = nil + local plugin_path = "" for _, path in ipairs(vim.split(runtimepaths, ",")) do if path:find("terra%-core") then diff --git a/lua/terra-core/config.lua b/lua/terra-core/config.lua index 613f5b92..b6b2cf17 100644 --- a/lua/terra-core/config.lua +++ b/lua/terra-core/config.lua @@ -19,6 +19,7 @@ M.themes = { ---@type TerraConfig M.default_config = { + loaded = false, debug = false, theme = M.themes[1], @@ -44,6 +45,7 @@ M.default_config = { }, keywords = { bold = true, + italic = true, }, functions = { bold = true, diff --git a/lua/terra-core/themes/control/day.lua b/lua/terra-core/themes/control/day.lua index 50306549..cb6134a3 100644 --- a/lua/terra-core/themes/control/day.lua +++ b/lua/terra-core/themes/control/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/themes/fall/day.lua b/lua/terra-core/themes/fall/day.lua index 7db83b06..5136ba8c 100644 --- a/lua/terra-core/themes/fall/day.lua +++ b/lua/terra-core/themes/fall/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/themes/kurzgesagt/day.lua b/lua/terra-core/themes/kurzgesagt/day.lua index 94586a54..14f7fafb 100644 --- a/lua/terra-core/themes/kurzgesagt/day.lua +++ b/lua/terra-core/themes/kurzgesagt/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/themes/spring/day.lua b/lua/terra-core/themes/spring/day.lua index 8f67bc3a..eb22f6a4 100644 --- a/lua/terra-core/themes/spring/day.lua +++ b/lua/terra-core/themes/spring/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/themes/summer/day.lua b/lua/terra-core/themes/summer/day.lua index b76ae4ee..80d726b4 100644 --- a/lua/terra-core/themes/summer/day.lua +++ b/lua/terra-core/themes/summer/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/themes/winter/day.lua b/lua/terra-core/themes/winter/day.lua index 1a15a2c3..61164576 100644 --- a/lua/terra-core/themes/winter/day.lua +++ b/lua/terra-core/themes/winter/day.lua @@ -94,6 +94,7 @@ M.semantics = { light = M.primaries[6], }, active = M.palette.yellow, + invert = M.primaries[11], neutral = M.primaries[5], diff = { add = M.palette.green, diff --git a/lua/terra-core/types.lua b/lua/terra-core/types.lua index b31edc6b..1c5a02c4 100644 --- a/lua/terra-core/types.lua +++ b/lua/terra-core/types.lua @@ -1,21 +1,21 @@ ----------------------------------------Highlight ---@class TerraHighlightDefinition ----@field fg string ----@field bg string ----@field sp string ----@field bold boolean ----@field italic boolean ----@field blend integer ----@field standout boolean ----@field underline boolean ----@field undercurl boolean ----@field underdouble boolean ----@field underdotted boolean ----@field underdashed boolean ----@field strikethrough boolean ----@field reverse boolean ----@field link string +---@field fg? string +---@field bg? string +---@field sp? string +---@field bold? boolean +---@field italic? boolean +---@field blend? integer +---@field standout? boolean +---@field underline? boolean +---@field undercurl? boolean +---@field underdouble? boolean +---@field underdotted? boolean +---@field underdashed? boolean +---@field strikethrough? boolean +---@field reverse? boolean +---@field link? string ---@alias TerraHighlights table> @@ -25,10 +25,11 @@ ---@alias TerraHighlightMapExtension.map fun(colors: TerraColors, config: TerraConfig): TerraHighlights ---@class TerraHighlightsSpec ----@field enabled boolean Whether or not the highlight map should be enabled +---@field enabled? boolean Default: true ---@field map TerraHighlightMapExtension.map -------------------------------------------Colors + ---@class TerraColors.Debug ---@field neon_pink string ---@field electric_lime string @@ -96,32 +97,33 @@ ---@field semantics TerraColors.Semantics -------------------------------------------Config + ---@alias TerraConfig.Variant "day" | "night" ---@alias TerraConfig.Theme "spring" | "summer" | "fall" | "winter" | "control" | "kurzgesagt" ---@class TerraConfig.CodeStyle ----@field comments TerraHighlightDefinition ----@field keywords TerraHighlightDefinition ----@field functions TerraHighlightDefinition ----@field strings TerraHighlightDefinition ----@field variables TerraHighlightDefinition ----@field messages TerraHighlightDefinition Affects: `WarningMsg`, `ErrorMsg`, `MoreMsg`, `ModeMsg` +---@field comments? TerraHighlightDefinition +---@field keywords? TerraHighlightDefinition +---@field functions? TerraHighlightDefinition +---@field strings? TerraHighlightDefinition +---@field variables? TerraHighlightDefinition +---@field messages? TerraHighlightDefinition Affects: `WarningMsg`, `ErrorMsg`, `MoreMsg`, `ModeMsg` ---@class TerraConfig.Diagnostics ----@field darker boolean Wether to use darker colors for diagnostics ----@field undercurl boolean Wether to use undercurls for diagnostics ----@field background boolean Wether to use background color for virtual text +---@field darker boolean Wether to use darker colors for diagnostics (Default: false) +---@field undercurl boolean Wether to use undercurls for diagnostics (Default: false) +---@field background boolean Wether to use background color for virtual text (Default: false) ---@class TerraConfig ----@field loaded boolean Wether the config has been loaded ----@field debug boolean Enables the Debug Mode (Enables various debug messages) ----@field theme TerraConfig.Theme Currently set theme ----@field variant TerraConfig.Variant Currently set variant ----@field icons table Icons associated with each theme ----@field transparent boolean Wether to render the background color ----@field dim_inactive_panes boolean Wether to dim inactive panes ----@field term_colors boolean Wether to enable terminal colors ----@field ending_tildes boolean Wether to show the end-of-buffer tildes ----@field code_style TerraConfig.CodeStyle Code styling options ----@field colors table Override default colors ----@field diagnostics TerraConfig.Diagnostics Diagnostics related settings +---@field loaded? boolean Wether the config has been loaded. (Default: false) +---@field debug? boolean Enables the Debug Mode (Enables various debug messages) (Default: false) +---@field theme? TerraConfig.Theme Currently set theme (Default: "spring") +---@field variant? TerraConfig.Variant Currently set variant (Default: "night") +---@field icons? table Icons associated with each theme +---@field transparent? boolean Wether to render the background color (Default: false) +---@field dim_inactive_panes? boolean Wether to dim inactive panes (Default: false) +---@field term_colors? boolean Wether to enable terminal colors (Default: true) +---@field ending_tildes? boolean Wether to show the end-of-buffer tildes (Default: false) +---@field code_style? TerraConfig.CodeStyle Code styling options (Default: See Documentation) +---@field colors? table Override default colors (Default: {}) +---@field diagnostics? TerraConfig.Diagnostics Diagnostics related settings (Default: See Documentation)