Skip to content

Commit

Permalink
The 'BREAKING CHANGE: extras' table has been renamed to 'autocmd = tr…
Browse files Browse the repository at this point in the history
…ue'.
  • Loading branch information
maxmx03 committed Dec 22, 2023
1 parent 6aea953 commit 13119a1
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 67 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ require('solarized').setup({
enables = {
bufferline = true,
cmp = true,
custom = true, -- solarized's custom highlights
diagnostic = true,
dashboard = true,
editor = true,
Expand All @@ -126,9 +125,7 @@ require('solarized').setup({
highlights = {},
colors = {},
theme = 'default', -- or 'neo'
extras = {
highlight_token = false,
},
autocmd = true,
})

vim.cmd.colorscheme = 'solarized'
Expand Down Expand Up @@ -246,6 +243,10 @@ require('solarized').setup {
}
```

## Config Autocmd

This option enhances highlighting by enabling Solarized's autocmd feature.

## Lualine

```lua
Expand Down
102 changes: 67 additions & 35 deletions lua/solarized/autocmd.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,68 @@
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',
'FIX',
}
local name = 'SolarizedTodo'

for _, group_name in pairs(highlights) do
if text ~= nil and token.type == 'comment' and text:match(group_name) then
vim.lsp.semantic_tokens.highlight_token(
token,
buffer,
args.data.client_id,
name .. group_name
)
local M = {}

function M.load_autocmd()
local group = vim.api.nvim_create_augroup('solarized', { clear = true })

vim.api.nvim_create_autocmd('ColorSchemePre', {
group = group,
callback = function()
vim.api.nvim_del_augroup_by_id(group)
end,
})

vim.api.nvim_create_autocmd('LspTokenUpdate', {
group = group,
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',
'FIX',
}
local name = 'SolarizedTodo'

for _, group_name in pairs(highlights) do
if
text ~= nil
and token.type == 'comment'
and text:match(group_name)
then
vim.lsp.semantic_tokens.highlight_token(
token,
buffer,
args.data.client_id,
name .. group_name
)
end
end
end
end,
})
end,
})
end

function M.load_autocmd_highlights(c)
local set_hl = require('solarized.utils').set_hl

set_hl('SolarizedTokenTODO', { fg = c.info })
set_hl('SolarizedTokenWARN', { fg = c.warning })
set_hl('SolarizedTokenTEST', { fg = c.violet })
set_hl('SolarizedTokenPERF', { fg = c.magenta })
set_hl('SolarizedTokenNOTE', { fg = c.hint })
set_hl('SolarizedTokenHACK', { fg = c.cyan })
set_hl('SolarizedTokenFIX', { fg = c.error })
end

return M
5 changes: 1 addition & 4 deletions lua/solarized/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function M.default_config()
enables = {
bufferline = true,
cmp = true,
custom = true,
diagnostic = true,
dashboard = true,
editor = true,
Expand All @@ -51,9 +50,7 @@ function M.default_config()
highlights = {},
colors = {},
theme = 'default',
extras = {
highlight_token = false,
},
autocmd = true,
}
end

Expand Down
6 changes: 4 additions & 2 deletions lua/solarized/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +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')
if vim.fn.has('nvim-0.9.4') and config.autocmd then
local extras = require('solarized.autocmd')
extras.load_autocmd()
extras.load_autocmd_highlights(colors)
end

utils.on_config({
Expand Down
11 changes: 0 additions & 11 deletions lua/solarized/themes/default/custom.lua

This file was deleted.

11 changes: 0 additions & 11 deletions lua/solarized/themes/neo/custom.lua

This file was deleted.

19 changes: 19 additions & 0 deletions tests/autocmd_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('Autocmd', function()
test('Solarized Highlights is being created', function()
vim.cmd.colorscheme('solarized')
local todo = {
'TODO',
'WARN',
'TEST',
'PERF',
'NOTE',
'HACK',
'FIX',
}

for _, name in pairs(todo) do
local output = vim.api.nvim_get_hl(0, { name = 'SolarizedToken' .. name })
assert.is_true(type(output.fg) == 'number')
end
end)
end)

0 comments on commit 13119a1

Please sign in to comment.