Skip to content

Commit

Permalink
feat: highlight token
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmx03 committed Dec 21, 2023
1 parent a700128 commit c7a03f3
Show file tree
Hide file tree
Showing 35 changed files with 369 additions and 101 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ require('solarized').setup({
enables = {
bufferline = true,
cmp = true,
custom = true, -- solarized's custom highlights
diagnostic = true,
dashboard = true,
editor = true,
Expand Down
35 changes: 35 additions & 0 deletions lua/solarized/autocmd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token
local buffer = args.buf
local text = vim.api.nvim_buf_get_text(
buffer,
token.line,
token.start_col,
token.line,
token.end_col,
{}
)[1]

local highlights = {
'TODO',
'WARN',
'TEST',
'PERF',
'NOTE',
'HACK',
}
local name = 'SolarizedTodo'

for _, group_name in pairs(highlights) do
if text ~= nil and text:match('%' .. group_name) then
vim.lsp.semantic_tokens.highlight_token(
token,
buffer,
args.data.client_id,
name .. group_name
)
end
end
end,
})
8 changes: 4 additions & 4 deletions lua/solarized/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ local subcommands = {
}
local desc = colors_desc[color]

if not desc then
return ''
end
if not desc then return '' end

return desc
end

local function set_lines(color, hex, line)
vim.api.nvim_buf_set_lines(buf, line, (line + 1), false, {
color .. string.rep('.', max_length - #color) .. ' = "' .. tostring(hex) .. '" ' .. color_desc(color),
color .. string.rep('.', max_length - #color) .. ' = "' .. tostring(
hex
) .. '" ' .. color_desc(color),
})
return line + 1
end
Expand Down
15 changes: 8 additions & 7 deletions lua/solarized/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function M.default_config()
enables = {
bufferline = true,
cmp = true,
custom = true,
diagnostic = true,
dashboard = true,
editor = true,
Expand All @@ -50,17 +51,16 @@ function M.default_config()
highlights = {},
colors = {},
theme = 'default',
extras = {
highlight_token = false,
},
}
end

function M.load()
if vim.g.colors_name then
vim.cmd('hi clear')
end
if vim.g.colors_name then vim.cmd('hi clear') end

if vim.fn.exists('syntax_on') then
vim.cmd('syntax reset')
end
if vim.fn.exists('syntax_on') then vim.cmd('syntax reset') end

vim.o.termguicolors = true
vim.g.colors_name = 'solarized'
Expand Down Expand Up @@ -94,7 +94,8 @@ function M.setup(opts)
M.colors = palette.extend_colors(colors, M.config.colors)
end,
fnc = function()
M.colors = palette.extend_colors(colors, M.config.colors(colors, colorhelper))
M.colors =
palette.extend_colors(colors, M.config.colors(colors, colorhelper))
end,
}, M.config.colors)
end
Expand Down
7 changes: 6 additions & 1 deletion lua/solarized/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ end
function M.load_plugins(colors, config)
for plugin, enabled in pairs(config.enables) do
if enabled then
local highlight_groups = require(string.format('solarized.themes.%s.%s', config.theme, plugin))
local highlight_groups =
require(string.format('solarized.themes.%s.%s', config.theme, plugin))

highlight_groups(colors, config)
end
Expand All @@ -44,6 +45,10 @@ function M.highlights(colors, config)
M.load_plugins(colors, config)
end

if vim.fn.has('nvim-0.9.4') and config.extras.highlight_token then
require('solarized.autocmd')
end

utils.on_config({
tbl = function()
M.custom_hl(config.highlights)
Expand Down
11 changes: 11 additions & 0 deletions lua/solarized/themes/default/custom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return function(c)
local set_hl = require('solarized.utils').set_hl

set_hl('SolarizedTodoTODO', { fg = c.info })
set_hl('SolarizedTodoWARN', { fg = c.warning })
set_hl('SolarizedTodoTEST', { fg = c.violet })
set_hl('SolarizedTodoPERF', { fg = c.magenta })
set_hl('SolarizedTodoNOTE', { fg = c.hint })
set_hl('SolarizedTodoHACK', { fg = c.cyan })
set_hl('SolarizedTodoFIX', { fg = c.error })
end
30 changes: 25 additions & 5 deletions lua/solarized/themes/default/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,31 @@ return function(c, config)
-- set_hl('DiagnosticFloatingInfo') -- Used to color "Info" diagnostic messages in diagnostics float.
-- set_hl('DiagnosticFloatingHint') -- Used to color "Hint" diagnostic messages in diagnostics float.
-- set_hl('DiagnosticFloatingOk') -- Used to color "Ok" diagnostic messages in diagnostics float.
set_hl('DiagnosticSignError', { fg = c.error, bg = c.base02 }, { transparent = config.transparent }) -- Used for "Error" signs in sign column.
set_hl('DiagnosticSignWarn', { fg = c.warning, bg = c.base02 }, { transparent = config.transparent }) -- Used for "Warn" signs in sign column.
set_hl('DiagnosticSignInfo', { fg = c.info, bg = c.base02 }, { transparent = config.transparent }) -- Used for "Info" signs in sign column.
set_hl('DiagnosticSignHint', { fg = c.hint, bg = c.base02 }, { transparent = config.transparent }) -- Used for "Hint" signs in sign column.
set_hl('DiagnosticSignOk', { fg = c.cyan, bg = c.base02 }, { transparent = config.transparent }) -- Used for "Ok" signs in sign column.
set_hl(
'DiagnosticSignError',
{ fg = c.error, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for "Error" signs in sign column.
set_hl(
'DiagnosticSignWarn',
{ fg = c.warning, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for "Warn" signs in sign column.
set_hl(
'DiagnosticSignInfo',
{ fg = c.info, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for "Info" signs in sign column.
set_hl(
'DiagnosticSignHint',
{ fg = c.hint, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for "Hint" signs in sign column.
set_hl(
'DiagnosticSignOk',
{ fg = c.cyan, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for "Ok" signs in sign column.
-- set_hl('DiagnosticDeprecated') -- Used for deprecated or obsolete code.
-- set_hl('DiagnosticUnnecessary') -- Used for unnecessary or unused code.
end
56 changes: 46 additions & 10 deletions lua/solarized/themes/default/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,35 @@ return function(c, config)
set_hl('TermCursor', { link = 'Cursor' }) -- Cursor in a focused terminal
set_hl('TermCursorNC', { fg = c.base03, bg = c.base0 }) -- Cursor in an unfocused terminal
set_hl('ErrorMsg', { fg = c.error, reverse = true }) -- Error messages on the command line
set_hl('WinSeparator', { fg = c.base00, bg = c.base02 }, { transparent = config.transparent }) -- Separators between window splits
set_hl('Folded', { fg = c.base0, bg = c.base02, underline = true, bold = true }) -- Line used for closed folds
set_hl(
'WinSeparator',
{ fg = c.base00, bg = c.base02 },
{ transparent = config.transparent }
) -- Separators between window splits
set_hl(
'Folded',
{ fg = c.base0, bg = c.base02, underline = true, bold = true }
) -- Line used for closed folds
set_hl('FoldColumn', { fg = c.base0, bg = c.base02, bold = true }) -- 'foldcolumn'
set_hl('SignColumn', { fg = c.base0, bg = c.base02 }, { transparent = config.transparent }) -- Column were signs are displayed
set_hl(
'SignColumn',
{ fg = c.base0, bg = c.base02 },
{ transparent = config.transparent }
) -- Column were signs are displayed
set_hl('IncSearch', { fg = c.orange, standout = true }) -- 'incsearch' highlighting, also for the text replaced
set_hl('Substitute', { link = 'IncSearch' }) -- :substitute replacement text highlight
set_hl('LineNr', { fg = c.base01, bg = c.base02 }, { transparent = config.transparent }) -- Line number for ":number" and ":#" commands
set_hl(
'LineNr',
{ fg = c.base01, bg = c.base02 },
{ transparent = config.transparent }
) -- Line number for ":number" and ":#" commands
set_hl('LineNrAbove', { link = 'LineNr' }) -- Line number, above the cursor line
set_hl('LineNrBelow', { link = 'LineNr' }) -- Line number, below the cursor
set_hl('CursorLineNr', { fg = c.base1, bg = c.base02, bold = true }, { transparent = config.transparent }) -- Like LineNr when 'cursorline' is set
set_hl(
'CursorLineNr',
{ fg = c.base1, bg = c.base02, bold = true },
{ transparent = config.transparent }
) -- Like LineNr when 'cursorline' is set
set_hl('CursorLineFold', { link = 'FoldColumn' }) -- Like FoldColumn when 'cursorline' is set
set_hl('CursorLineSign', { link = 'SignColumn' }) -- Like SignColumn when 'cursorline' is set
set_hl('MatchParen', { fg = c.red, bg = c.base01, bold = true }) -- Character under the cursor or just before it
Expand All @@ -37,12 +56,20 @@ return function(c, config)
set_hl('MsgSeparator', { link = 'Normal' }) -- Separator for scrolled messages msgsep.
set_hl('MoreMsg', { fg = c.blue }) -- more-prompt
set_hl('NonText', { fg = c.base1, bold = true }) -- '@' at the end of the window
set_hl('Normal', { fg = c.base0, bg = c.base03 }, { transparent = config.transparent }) -- Normal text
set_hl(
'Normal',
{ fg = c.base0, bg = c.base03 },
{ transparent = config.transparent }
) -- Normal text
set_hl('NormalFloat', { fg = c.base0, bg = c.base02 }) -- Normal text in floating windows
set_hl('FloatBorder', { link = 'WinSeparator', bold = true }) -- Border of floating windows.
set_hl('FloatTitle', { fg = c.orange }) -- Title of float windows.
set_hl('NormalNC', { link = 'Normal' }) -- Normal text in non-current windows.
set_hl('Pmenu', { fg = c.base0, bg = c.base02 }, { transparent = config.transparent }) -- Popup menu: Normal item
set_hl(
'Pmenu',
{ fg = c.base0, bg = c.base02 },
{ transparent = config.transparent }
) -- Popup menu: Normal item
set_hl('PmenuSel', { fg = c.base2, bg = c.base01 }) -- Popup menu: Selected item
set_hl('PmenuKind', { link = 'Pmenu' }) -- Popup menu: Normal item kind
set_hl('PmenuKindSel', { link = 'PmenuSel' }) -- Popup menu: Selected item kind
Expand All @@ -60,9 +87,18 @@ return function(c, config)
set_hl('SpellRare', { sp = c.cyan, undercurl = true }) -- Word that is recognized by the spellchecker as one that is hardly ever used.
set_hl('StatusLine', { fg = c.base02, bg = c.base1 }) -- Status line of current window.
set_hl('StatusLineNC', { fg = c.base02, bg = c.base00 }) -- Status lines of not-current windows.
set_hl('TabLine', { fg = c.base0, bg = c.base02, sp = c.base0, underline = true }) -- Tab pages line, not active tab page label.
set_hl('TabLineFill', { fg = c.base0, bg = c.base02, sp = c.base0, underline = true }) -- Tab pages line, where there are no labels.
set_hl('TabLineSel', { fg = c.base2, bg = c.base01, sp = c.base0, underline = true }) -- Tab pages line, active tab page label.
set_hl(
'TabLine',
{ fg = c.base0, bg = c.base02, sp = c.base0, underline = true }
) -- Tab pages line, not active tab page label.
set_hl(
'TabLineFill',
{ fg = c.base0, bg = c.base02, sp = c.base0, underline = true }
) -- Tab pages line, where there are no labels.
set_hl(
'TabLineSel',
{ fg = c.base2, bg = c.base01, sp = c.base0, underline = true }
) -- Tab pages line, active tab page label.
set_hl('Title', { fg = c.orange, bold = true }) -- Titles for output from ":set all", ":autocmd" etc.
set_hl('Visual', { bg = c.base02, standout = true }) -- Visual mode selection.
set_hl('VisualNOS', { link = 'Visual' }) -- Visual mode selection when vim is "Not Owning the Selection".
Expand Down
18 changes: 15 additions & 3 deletions lua/solarized/themes/default/gitsign.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ return function(c, config)
local utils = require('solarized.utils')
local set_hl = utils.set_hl

set_hl('GitSignsAdd', { fg = c.add, bg = c.base02 }, { transparent = config.transparent }) -- Used for the text of 'add' signs
set_hl('GitSignsChange', { fg = c.change, bg = c.base02 }, { transparent = config.transparent }) -- Used for the text of 'change' signs
set_hl('GitSignsDelete', { fg = c.delete, bg = c.base02 }, { transparent = config.transparent }) -- Used for the text of 'delete' signs
set_hl(
'GitSignsAdd',
{ fg = c.add, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for the text of 'add' signs
set_hl(
'GitSignsChange',
{ fg = c.change, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for the text of 'change' signs
set_hl(
'GitSignsDelete',
{ fg = c.delete, bg = c.base02 },
{ transparent = config.transparent }
) -- Used for the text of 'delete' signs
end
5 changes: 4 additions & 1 deletion lua/solarized/themes/default/indentblankline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ return function(c)
set_hl('IndentBlanklineChar', { fg = c.base01 }) -- Highlight of indent character. Default: Whitespace
set_hl('IndentBlanklineSpaceChar', { link = 'IndentBlanklineChar' }) -- Highlight of space character. Default: Whitespace
set_hl('IndentBlanklineContextChar', { fg = c.base0 }) -- Highlight of indent character when base of current context. Default: Label
set_hl('IndentBlanklineContextSpaceChar', { link = 'IndentBlanklineContextChar' }) -- Highlight of space characters one indent level of the current context. Default: Label
set_hl(
'IndentBlanklineContextSpaceChar',
{ link = 'IndentBlanklineContextChar' }
) -- Highlight of space characters one indent level of the current context. Default: Label
set_hl('IblIndent', { fg = c.base0, nocombine = true })
set_hl('IblScope', { fg = c.base01, nocombine = true })

Expand Down
6 changes: 5 additions & 1 deletion lua/solarized/themes/default/lspsaga.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ return function(c, config)

-- Float window
set_hl('SagaNormal', { link = 'Pmenu' })
set_hl('TitleString', { fg = c.orange, bold = true, bg = c.base02 }, { transparent = config.transparent })
set_hl(
'TitleString',
{ fg = c.orange, bold = true, bg = c.base02 },
{ transparent = config.transparent }
)

-- Outline
set_hl('OutlineIndent', { fg = c.green })
Expand Down
15 changes: 12 additions & 3 deletions lua/solarized/themes/default/neogit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ return function(c)
set_hl('NeogitCursorLine', { link = 'CursorLine' })
set_hl('NeogitBranch', { fg = c.magenta })
set_hl('NeogitRemote', { fg = c.violet })
set_hl('NeogitHunkHeader', { fg = c.orange, bg = blend(c.orange, c.base03, alpha) })
set_hl(
'NeogitHunkHeader',
{ fg = c.orange, bg = blend(c.orange, c.base03, alpha) }
)
set_hl('NeogitHunkHeaderHighlight', { link = 'Title' })
set_hl('NeogitDiffContextHighlight', { fg = c.base00, bg = c.base03 })
set_hl('NeogitDiffContext', { fg = c.base00, bg = c.base03 })
set_hl('NeogitDiffDeleteHighlight', { fg = c.red, bg = blend(c.red, c.base03, alpha) })
set_hl(
'NeogitDiffDeleteHighlight',
{ fg = c.red, bg = blend(c.red, c.base03, alpha) }
)
set_hl('NeogitDiffDelete', { fg = c.red })
set_hl('NeogitDiffAddHighlight', { fg = c.green, bg = blend(c.green, c.base03, alpha) })
set_hl(
'NeogitDiffAddHighlight',
{ fg = c.green, bg = blend(c.green, c.base03, alpha) }
)
set_hl('NeogitDiffAdd', { fg = c.green })
end
6 changes: 5 additions & 1 deletion lua/solarized/themes/default/semantic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ return function(c, config)
set_hl('@lsp.type.macro', { link = 'Macro' }) -- Keyword
set_hl('@lsp.type.method', { link = 'Function' }) -- Function
set_hl('@lsp.type.namespace', { link = '@namespace' }) -- Namespace
set_hl('@lsp.type.parameter', { fg = c.base0, italic = true }, { styles = config.styles.parameters })
set_hl(
'@lsp.type.parameter',
{ fg = c.base0, italic = true },
{ styles = config.styles.parameters }
)
set_hl('@lsp.type.property', { link = '@field' }) -- Property
set_hl('@lsp.type.struct', { link = 'Structure' }) -- Structure
set_hl('@lsp.type.type', { link = 'Type' }) -- Type
Expand Down
12 changes: 10 additions & 2 deletions lua/solarized/themes/default/syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ return function(c, config)
local utils = require('solarized.utils')
local set_hl = utils.set_hl

set_hl('Comment', { fg = c.base01, italic = true }, { styles = config.styles.comments }) -- any comment
set_hl(
'Comment',
{ fg = c.base01, italic = true },
{ styles = config.styles.comments }
) -- any comment
set_hl('Constant', { fg = c.cyan }, { styles = config.styles.constants }) -- any constant
set_hl('String', { fg = c.cyan }) -- a string constant: "this is a string"
set_hl('Character', { link = 'String' }) -- a character constant: 'c', '\n'
Expand All @@ -16,7 +20,11 @@ return function(c, config)
set_hl('Repeat', { link = 'Statement' }) -- for, do, while, etc.
set_hl('Label', { link = 'Statement' }) -- case, default, etc.
set_hl('Operator', { link = 'Statement' }) -- "sizeof", "+", "*", etc.
set_hl('Keyword', { fg = c.base1, bold = true }, { styles = config.styles.keywords }) -- any other keyword
set_hl(
'Keyword',
{ fg = c.base1, bold = true },
{ styles = config.styles.keywords }
) -- any other keyword
set_hl('Exception', { link = 'Statement' }) -- try, catch, throw
set_hl('PreProc', { fg = c.orange }) -- generic Preprocessor
set_hl('Include', { link = 'PreProc' }) -- preprocessor #include
Expand Down
6 changes: 5 additions & 1 deletion lua/solarized/themes/default/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ return function(c, config)
set_hl('TelescopeMultiIcon', { fg = c.cyan })

-- "Normal" in the floating windows created by telescope.
set_hl('TelescopeNormal', { fg = c.base0, bg = c.base02 }, { transparent = config.transparent })
set_hl(
'TelescopeNormal',
{ fg = c.base0, bg = c.base02 },
{ transparent = config.transparent }
)
set_hl('TelescopePreviewNormal', { link = 'TelescopeNormal' })
set_hl('TelescopePromptNormal', { link = 'TelescopeNormal' })
set_hl('TelescopeResultsNormal', { link = 'TelescopeNormal' })
Expand Down
Loading

0 comments on commit c7a03f3

Please sign in to comment.