feat: error_lens config

This commit is contained in:
Max Miliano 2024-09-02 10:45:36 -03:00
parent 151aabdeb7
commit 7cd978401e
5 changed files with 263 additions and 93 deletions

View file

@ -1,8 +1,12 @@
{
"workspace.library": [
"/home/milianor/neovim/share/nvim/runtime",
"${3rd}/luv/library",
"${3rd}/busted/library",
"${3rd}/luassert/library"
]
}
"workspace.library": [
"/usr/share/nvim/runtime",
"${3rd}/luv/library",
"${3rd}/busted/library",
"~/.local/share/nvim/lazy/solarized.nvim",
"${3rd}/luassert/library"
],
"diagnostics.disable": [
"duplicate-doc-field"
]
}

View file

@ -25,20 +25,19 @@ designed for use with terminal and gui applications.
- [Docs](#docs)
- [Commands](#commands)
- [Default Config](#default-config)
- [Config Variant](#config-transparency)
- [Config Variant](#config-variant)
- [Config Transparency](#config-transparency)
- [Config Styles](#config-styles)
- [Config Highlights](#config-highlights)
- [Config Colors](#config-colors)
- [Config Plugins](#config-plugins)
- [Config Error Lens](#config-error-lens)
- [Lualine](#lualine)
- [Barbecue](#barbecue)
- [Api](#api)
- [Get Colors](#get-colors)
- [Color utils](#color-utils)
- [Contributing](#contributing)
- [Designed by](#designed-by)
- [Credits and Reference 🎉](#credits-and-reference-🎉)
- [Credits and Reference](#credits-and-reference)
<!--toc:end-->
## Features
@ -172,6 +171,10 @@ require('solarized').setup({
on_colors = nil,
palette = 'solarized', -- solarized (default) | selenized
variant = 'winter', -- "spring" | "summer" | "autumn" | "winter" (default)
error_lens = {
text = false,
symbol = false,
},
styles = {
types = {},
functions = {},
@ -217,7 +220,7 @@ require('solarized').setup({
vim.cmd.colorscheme = 'solarized'
```
## Config Variants
## Config Variant
Solarized includes four variants: spring, summer, autumn, and winter.
@ -358,6 +361,29 @@ return {
}
```
## Config Error Lens
Enables additional highlights for diagnostic virtual text and symbols.
```lua
return {
'maxmx03/solarized.nvim',
lazy = false,
priority = 1000,
---@type solarized.config
opts = {
error_lens = {
text = true,
symbol = true,
}
},
config = function(_, opts)
require('solarized').setup(opts)
vim.cmd.colorscheme 'solarized'
end,
}
```
## Lualine
```lua
@ -437,7 +463,7 @@ Pull requests are welcome and appreciated.
Ethan Schoonover
## Credits and Reference 🎉
## Credits and Reference
- [solarized-vim](https://github.com/altercation/vim-colors-solarized)
- [tokyonight](https://github.com/folke/tokyonight.nvim)

View file

@ -54,6 +54,10 @@
---@field leap? boolean
---@field mason? boolean
---@class solarized.error_lens
---@field text? boolean
---@field symbol? boolean
---@class solarized.config
---@field transparent? solarized.transparent
---@field on_highlights? fun(colors: solarized.palette, color: solarized.color): solarized.highlights
@ -62,6 +66,7 @@
---@field palette? "solarized" | "selenized"
---@field variant? "spring" | "summer" | "autumn" | "winter"
---@field plugins? solarized.plugins
---@field error_lens? solarized.error_lens
return {
transparent = {
enabled = false,
@ -79,6 +84,10 @@ return {
on_colors = nil,
palette = 'solarized',
variant = 'winter',
error_lens = {
text = false,
symbol = false,
},
styles = {
types = {},
functions = {},

View file

@ -403,6 +403,7 @@ end
---@class solarized.nvim_set_hl.config
---@field transparent? boolean
---@field styles? vim.api.keyset.highlight
---@field error_lens? boolean
---@param group_name string
---@param group_val vim.api.keyset.highlight
@ -419,6 +420,17 @@ local nvim_set_hl = function(group_name, group_val, config)
group_val = vim.tbl_extend('force', group_val, config.styles)
end
if config and config.error_lens then
local color = require 'solarized.color'
local editor = require('solarized.utils').nvim_get_hl 'Normal'
local ok, mix_color = pcall(color.blend, group_val.fg, editor.bg, 0.3)
if ok then
group_val.bg = mix_color
else
group_val.bg = color.shade(group_val.fg, 5)
end
end
val = vim.tbl_extend('force', val, group_val)
vim.api.nvim_set_hl(0, group_name, val)
else
@ -646,41 +658,81 @@ M.set_highlight = function(colors, config)
nvim_set_hl('@lsp.typemod.keyword.documentation', { link = 'Keyword' })
nvim_set_hl('@lsp.typemod.class.documentation', { link = 'Type' })
nvim_set_hl('@lsp.typemod.property.readonly', { link = 'Constant' })
nvim_set_hl('DiagnosticError', { fg = colors.diag_error })
nvim_set_hl('DiagnosticWarn', { fg = colors.diag_warning })
nvim_set_hl('DiagnosticInfo', { fg = colors.diag_info })
nvim_set_hl('DiagnosticHint', { fg = colors.diag_hint })
nvim_set_hl('DiagnosticOk', { fg = colors.diag_ok })
nvim_set_hl(
'DiagnosticError',
{ fg = colors.diag_error, bg = colors.mix_red },
{ transparent = config.transparent.enabled }
'DiagnosticVirtualTextError',
{ fg = colors.diag_error },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticWarn',
{ fg = colors.diag_warning, bg = colors.mix_yellow },
{ transparent = config.transparent.enabled }
'DiagnosticVirtualTextWarn',
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticInfo',
{ fg = colors.diag_info, bg = colors.mix_base1 },
{ transparent = config.transparent.enabled }
'DiagnosticVirtualTextInfo',
{ fg = colors.diag_info },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticHint',
{ fg = colors.diag_hint, bg = colors.mix_base1 },
{ transparent = config.transparent.enabled }
'DiagnosticVirtualTextHint',
{ fg = colors.diag_hint },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticOk',
{ fg = colors.diag_ok, bg = colors.mix_green },
{ transparent = config.transparent.enabled }
'DiagnosticVirtualTextOk',
{ fg = colors.diag_ok },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticUnderlineError',
{ fg = colors.diag_error, underline = true, sp = colors.diag_error }
)
nvim_set_hl(
'DiagnosticUnderlineWarn',
{ fg = colors.diag_warning, underline = true, sp = colors.diag_warning }
)
nvim_set_hl(
'DiagnosticUnderlineInfo',
{ fg = colors.diag_info, underline = true, sp = colors.diag_info }
)
nvim_set_hl(
'DiagnosticUnderlineHint',
{ fg = colors.diag_hint, underline = true, sp = colors.diag_hint }
)
nvim_set_hl(
'DiagnosticUnderlineOk',
{ fg = colors.diag_ok, underline = true, sp = colors.diag_ok }
)
nvim_set_hl(
'DiagnosticSignError',
{ fg = colors.diag_error, bg = colors.base02 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Error" signs in sign column.
nvim_set_hl(
'DiagnosticSignWarn',
{ fg = colors.diag_warning, bg = colors.base02 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Warn" signs in sign column.
nvim_set_hl(
'DiagnosticSignInfo',
{ fg = colors.diag_info, bg = colors.base02 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Info" signs in sign column.
nvim_set_hl(
'DiagnosticSignHint',
{ fg = colors.diag_hint, bg = colors.base02 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Hint" signs in sign column.
nvim_set_hl(
'DiagnosticSignOk',
{ fg = colors.diag_ok, bg = colors.base02 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
)
nvim_set_hl('DiagnosticVirtualTextError', { fg = colors.diag_error })
nvim_set_hl('DiagnosticVirtualTextWarn', { fg = colors.diag_warning })
nvim_set_hl('DiagnosticVirtualTextInfo', { fg = colors.diag_info })
nvim_set_hl('DiagnosticVirtualTextHint', { fg = colors.diag_hint })
nvim_set_hl('DiagnosticVirtualTextOk', { fg = colors.diag_ok })
nvim_set_hl('DiagnosticUnderlineError', { fg = colors.diag_error, underline = true })
nvim_set_hl('DiagnosticUnderlineWarn', { fg = colors.diag_warning, underline = true })
nvim_set_hl('DiagnosticUnderlineInfo', { fg = colors.diag_info, underline = true })
nvim_set_hl('DiagnosticUnderlineHint', { fg = colors.diag_hint, underline = true })
nvim_set_hl('DiagnosticUnderlineOk', { fg = colors.diag_ok, underline = true })
nvim_set_hl('LspReferenceText', { fg = colors.cyan, bg = colors.mix_cyan })
nvim_set_hl('LspReferenceRead', { fg = colors.green, bg = colors.mix_green })
nvim_set_hl('LspReferenceWrite', { fg = colors.green, bg = colors.mix_green })
@ -1049,14 +1101,38 @@ M.set_highlight = function(colors, config)
end
if config.plugins.coc then
nvim_set_hl('CocErrorSign', { fg = colors.diag_error })
nvim_set_hl('CocWarningSign', { fg = colors.diag_warning })
nvim_set_hl('CocInfoSign', { fg = colors.diag_info })
nvim_set_hl('CocHintSign', { fg = colors.diag_hint })
nvim_set_hl('CocErrorVirtualText', { fg = colors.diag_error, bg = colors.mix_red })
nvim_set_hl('CocWarningVirtualText', { fg = colors.diag_warning, bg = colors.mix_yellow })
nvim_set_hl('CocInfoVirtualText', { fg = colors.diag_info, bg = colors.mix_base1 })
nvim_set_hl('CocHintVirtualText', { fg = colors.diag_hint, bg = colors.mix_base1 })
nvim_set_hl(
'CocErrorSign',
{ fg = colors.diag_error },
{ error_lens = config.error_lens.symbol }
)
nvim_set_hl(
'CocWarningSign',
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.symbol }
)
nvim_set_hl('CocInfoSign', { fg = colors.diag_info }, { error_lens = config.error_lens.symbol })
nvim_set_hl('CocHintSign', { fg = colors.diag_hint }, { error_lens = config.error_lens.symbol })
nvim_set_hl(
'CocErrorVirtualText',
{ fg = colors.diag_error },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocWarningVirtualText',
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocInfoVirtualText',
{ fg = colors.diag_info },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocHintVirtualText',
{ fg = colors.diag_hint },
{ error_lens = config.error_lens.text }
)
end
if config.plugins.leap then

View file

@ -25,6 +25,17 @@ local nvim_set_hl = function(group_name, group_val, config)
group_val = vim.tbl_extend('force', group_val, config.styles)
end
if config and config.error_lens then
local color = require 'solarized.color'
local editor = require('solarized.utils').nvim_get_hl 'Normal'
local ok, mix_color = pcall(color.blend, group_val.fg, editor.bg, 0.1)
if ok then
group_val.bg = mix_color
else
group_val.bg = color.tint(group_val.fg, 7)
end
end
val = vim.tbl_extend('force', val, group_val)
vim.api.nvim_set_hl(0, group_name, val)
else
@ -257,61 +268,81 @@ M.set_highlight = function(colors, config)
nvim_set_hl('@lsp.typemod.keyword.documentation', { link = 'Statement' })
nvim_set_hl('@lsp.typemod.class.documentation', { link = 'Type' })
nvim_set_hl('@lsp.typemod.property.readonly', { link = 'Constant' })
nvim_set_hl(
'DiagnosticError',
{ fg = colors.diag_error, bg = colors.mix_red },
{ transparent = config.transparent.enabled }
)
nvim_set_hl(
'DiagnosticWarn',
{ fg = colors.diag_warning, bg = colors.mix_yellow },
{ transparent = config.transparent.enabled }
)
nvim_set_hl(
'DiagnosticInfo',
{ fg = colors.diag_info, bg = colors.mix_blue },
{ transparent = config.transparent.enabled }
)
nvim_set_hl(
'DiagnosticHint',
{ fg = colors.diag_hint, bg = colors.mix_blue },
{ transparent = config.transparent.enabled }
)
nvim_set_hl(
'DiagnosticOk',
{ fg = colors.diag_ok, bg = colors.mix_green },
{ transparent = config.transparent.enabled }
)
nvim_set_hl('DiagnosticError', { fg = colors.diag_error })
nvim_set_hl('DiagnosticWarn', { fg = colors.diag_warning })
nvim_set_hl('DiagnosticInfo', { fg = colors.diag_info })
nvim_set_hl('DiagnosticHint', { fg = colors.diag_hint })
nvim_set_hl('DiagnosticOk', { fg = colors.diag_ok })
nvim_set_hl(
'DiagnosticVirtualTextError',
{ fg = colors.diag_error, bg = colors.mix_red },
{ transparent = config.transparent.enabled }
{ fg = colors.diag_error },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticVirtualTextWarn',
{ fg = colors.diag_warning, bg = colors.mix_yellow },
{ transparent = config.transparent.enabled }
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticVirtualTextInfo',
{ fg = colors.diag_hint, bg = colors.mix_blue },
{ transparent = config.transparent.enabled }
{ fg = colors.diag_hint },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticVirtualTextHint',
{ fg = colors.diag_info, bg = colors.mix_blue },
{ transparent = config.transparent.enabled }
{ fg = colors.diag_info },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticVirtualTextOk',
{ fg = colors.diag_ok, bg = colors.mix_green },
{ fg = colors.diag_ok },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'DiagnosticUnderlineError',
{ fg = colors.diag_error, underline = true, sp = colors.diag_error }
)
nvim_set_hl(
'DiagnosticUnderlineWarn',
{ fg = colors.diag_warning, underline = true, sp = colors.diag_warning }
)
nvim_set_hl(
'DiagnosticUnderlineInfo',
{ fg = colors.diag_info, underline = true, sp = colors.diag_info }
)
nvim_set_hl(
'DiagnosticUnderlineHint',
{ fg = colors.diag_hint, underline = true, sp = colors.diag_hint }
)
nvim_set_hl(
'DiagnosticUnderlineOk',
{ fg = colors.diag_ok, underline = true, sp = colors.diag_ok }
)
nvim_set_hl(
'DiagnosticSignError',
{ fg = colors.diag_error, bg = colors.base2 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Error" signs in sign column.
nvim_set_hl(
'DiagnosticSignWarn',
{ fg = colors.diag_warning, bg = colors.base2 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Warn" signs in sign column.
nvim_set_hl(
'DiagnosticSignInfo',
{ fg = colors.diag_info, bg = colors.base2 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Info" signs in sign column.
nvim_set_hl(
'DiagnosticSignHint',
{ fg = colors.diag_hint, bg = colors.base2 },
{ transparent = config.transparent.enabled, error_lens = config.error_lens.symbol }
) -- Used for "Hint" signs in sign column.
nvim_set_hl(
'DiagnosticSignOk',
{ fg = colors.diag_ok, bg = colors.base2 },
{ transparent = config.transparent.enabled }
)
nvim_set_hl('DiagnosticUnderlineError', { fg = colors.diag_error, underline = true })
nvim_set_hl('DiagnosticUnderlineWarn', { fg = colors.diag_warning, underline = true })
nvim_set_hl('DiagnosticUnderlineInfo', { fg = colors.diag_info, underline = true })
nvim_set_hl('DiagnosticUnderlineHint', { fg = colors.diag_hint, underline = true })
nvim_set_hl('DiagnosticUnderlineOk', { fg = colors.diag_ok, underline = true })
nvim_set_hl('LspReferenceText', { fg = colors.cyan, bg = colors.mix_cyan })
nvim_set_hl('LspReferenceRead', { link = 'Visual' })
nvim_set_hl('LspReferenceWrite', { link = 'Visual' })
@ -679,14 +710,38 @@ M.set_highlight = function(colors, config)
end
if config.plugins.coc then
nvim_set_hl('CocErrorSign', { fg = colors.diag_error })
nvim_set_hl('CocWarningSign', { fg = colors.diag_warning })
nvim_set_hl('CocInfoSign', { fg = colors.diag_info })
nvim_set_hl('CocHintSign', { fg = colors.diag_hint })
nvim_set_hl('CocErrorVirtualText', { fg = colors.diag_error, bg = colors.mix_red })
nvim_set_hl('CocWarningVirtualText', { fg = colors.diag_warning, bg = colors.mix_yellow })
nvim_set_hl('CocInfoVirtualText', { fg = colors.diag_info, bg = colors.mix_blue })
nvim_set_hl('CocHintVirtualText', { fg = colors.diag_hint, bg = colors.mix_blue })
nvim_set_hl(
'CocErrorSign',
{ fg = colors.diag_error },
{ error_lens = config.error_lens.symbol }
)
nvim_set_hl(
'CocWarningSign',
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.symbol }
)
nvim_set_hl('CocInfoSign', { fg = colors.diag_info }, { error_lens = config.error_lens.symbol })
nvim_set_hl('CocHintSign', { fg = colors.diag_hint }, { error_lens = config.error_lens.symbol })
nvim_set_hl(
'CocErrorVirtualText',
{ fg = colors.diag_error },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocWarningVirtualText',
{ fg = colors.diag_warning },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocInfoVirtualText',
{ fg = colors.diag_info },
{ error_lens = config.error_lens.text }
)
nvim_set_hl(
'CocHintVirtualText',
{ fg = colors.diag_hint },
{ error_lens = config.error_lens.text }
)
end
if config.plugins.leap then