fix: Configuring highlight of type "@variable" #69

feat: github workflows, vusted, stylua
This commit is contained in:
Max Miliano 2024-03-28 11:24:54 -03:00
parent a0f02268bb
commit 6a34504272
15 changed files with 404 additions and 38 deletions

61
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,61 @@
name: Test
on: [push]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Stylua
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .
docs:
runs-on: ubuntu-latest
name: pandoc to vimdoc
steps:
- uses: actions/checkout@v3
- name: panvimdoc
uses: kdheepak/panvimdoc@main
with:
vimdoc: solarized.nvim
treesitter: true
version: "NVIM v0.9.4"
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore(doc): auto generate docs'
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
test:
name: Run Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
- name: luajit
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"
- name: luarocks
uses: leafo/gh-actions-luarocks@v4
- name: run test
shell: bash
run: |
luarocks install luacheck
luarocks install vusted
vusted ./tests

3
.luarc.json Normal file
View file

@ -0,0 +1,3 @@
{
"diagnostics.disable": ["undefined-field"]
}

7
Dockerfile Normal file
View file

@ -0,0 +1,7 @@
FROM archlinux
WORKDIR /dracula
COPY . .
RUN pacman -Syu --noconfirm
RUN pacman -S luarocks neovim gcc lua51 --noconfirm
RUN luarocks install luacheck && luarocks --lua-version=5.1 install vusted
CMD [ "vusted", "./tests" ]

View file

@ -11,8 +11,13 @@ function M.custom_hl(highlights)
for highlight_name, highlight_value in pairs(highlights) do
local highlight = get_hl(highlight_name)
local val = {}
local val = vim.tbl_extend('force', highlight, highlight_value)
if highlight_value.link then
val = highlight_value
else
val = vim.tbl_extend('force', highlight, highlight_value)
end
vim.api.nvim_set_hl(0, highlight_name, val)
end

View file

@ -6,43 +6,43 @@ return function(c, config)
'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'
set_hl('Number', { fg = c.magenta }, { styles = config.styles.numbers }) -- a number constant: 234, 0xff
set_hl('Boolean', { link = 'Constant' }) -- a boolean constant: TRUE, false
set_hl('Float', { link = 'Number' }) -- a floating point constant: 2.3e10
) -- 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'
set_hl('Number', { fg = c.magenta }, { styles = config.styles.numbers }) -- a number constant: 234, 0xff
set_hl('Boolean', { link = 'Constant' }) -- a boolean constant: TRUE, false
set_hl('Float', { link = 'Number' }) -- a floating point constant: 2.3e10
set_hl('Identifier', { fg = c.blue }, { styles = config.styles.variables }) -- any variable name
set_hl('Function', { fg = c.blue }, { styles = config.styles.functions }) -- function name (also: methods for classes)
set_hl('Statement', { fg = c.green }) -- any statement
set_hl('Conditional', { link = 'Statement' }) -- if, then, else, endif, switch, etc.
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('Function', { fg = c.blue }, { styles = config.styles.functions }) -- function name (also: methods for classes)
set_hl('Statement', { fg = c.green }) -- any statement
set_hl('Conditional', { link = 'Statement' }) -- if, then, else, endif, switch, etc.
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('Exception', { link = 'Statement' }) -- try, catch, throw
set_hl('PreProc', { fg = c.orange }) -- generic Preprocessor
set_hl('Include', { link = 'PreProc' }) -- preprocessor #include
set_hl('Define', { link = 'PreProc' }) -- preprocessor #define
set_hl('Macro', { link = 'PreProc' }) -- same as Define
set_hl('PreCondit', { link = 'PreProc' }) -- preprocessor #if, #else, #endif, etc.
) -- 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
set_hl('Define', { link = 'PreProc' }) -- preprocessor #define
set_hl('Macro', { link = 'PreProc' }) -- same as Define
set_hl('PreCondit', { link = 'PreProc' }) -- preprocessor #if, #else, #endif, etc.
set_hl('Type', { fg = c.yellow }, { styles = config.styles.types }) -- int, long, char, etc.
set_hl('StorageClass', { fg = c.yellow }) -- static, register, volatile, etc.
set_hl('Structure', { fg = c.yellow }) -- struct, union, enum, etc.
set_hl('Typedef', { fg = c.yellow }) -- A typedef
set_hl('Special', { fg = c.red }) -- special symbol
set_hl('SpecialChar', { link = 'Special' }) -- special character in a constant
set_hl('Tag', { link = 'Special' }) -- you can use CTRL-] on this
set_hl('Delimiter', { fg = c.base00 }) -- character that needs attention
set_hl('SpecialComment', { link = 'Special' }) -- special things inside a comment
set_hl('Debug', { link = 'Special' }) -- debugging statements
set_hl('Underlined', { fg = c.violet }) --text that stands out, HTML links
set_hl('Ignore') --left blank, hidden |hl-Ignore|
set_hl('Error', { fg = c.error, bold = true }) --any erroneous construct
set_hl('Todo', { fg = c.magenta, bold = true }) --anything that needs extra attention; mostly the keywords TODO FIXME and XXX
set_hl('StorageClass', { fg = c.yellow }) -- static, register, volatile, etc.
set_hl('Structure', { fg = c.yellow }) -- struct, union, enum, etc.
set_hl('Typedef', { fg = c.yellow }) -- A typedef
set_hl('Special', { fg = c.red }) -- special symbol
set_hl('SpecialChar', { link = 'Special' }) -- special character in a constant
set_hl('Tag', { link = 'Special' }) -- you can use CTRL-] on this
set_hl('Delimiter', { fg = c.base00 }) -- character that needs attention
set_hl('SpecialComment', { link = 'Special' }) -- special things inside a comment
set_hl('Debug', { link = 'Special' }) -- debugging statements
set_hl('Underlined', { fg = c.violet }) --text that stands out, HTML links
set_hl('Ignore') --left blank, hidden |hl-Ignore|
set_hl('Error', { fg = c.error, bold = true }) --any erroneous construct
set_hl('Todo', { fg = c.magenta, bold = true }) --anything that needs extra attention; mostly the keywords TODO FIXME and XXX
end

View file

@ -2,7 +2,8 @@ return function(c, config)
local utils = require('solarized.utils')
local set_hl = utils.set_hl
--[[ Highlight capture names as of nvim-treesitter commit `6806d7a` ]]--
--[[ Highlight capture names as of nvim-treesitter commit `6806d7a` ]]
--
-- Identifiers
set_hl('@variable', { link = 'Identifier' }) -- various variable names
@ -28,7 +29,7 @@ return function(c, config)
set_hl('@string.special', { link = 'SpecialChar' }) -- other special strings (e.g. dates)
set_hl('@string.special.symbol', { fg = c.violet }) -- symbols or atoms
set_hl('@string.special.url', { link = 'Underlined' }) -- URIs (e.g. hyperlinks)
set_hl('@string.special.path', { link = 'Underlined'}) -- filenames
set_hl('@string.special.path', { link = 'Underlined' }) -- filenames
set_hl('@character', { link = 'String' }) -- character literals
set_hl('@character.special', { link = '@string.special' }) -- special characters (e.g. wildcards)
set_hl('@boolean', { link = 'Boolean' }) -- boolean literals

View file

@ -2,7 +2,8 @@ return function(c, config)
local utils = require('solarized.utils')
local set_hl = utils.set_hl
--[[ Highlight capture names as of nvim-treesitter commit `6806d7a` ]]--
--[[ Highlight capture names as of nvim-treesitter commit `6806d7a` ]]
--
-- Identifiers
set_hl('@variable', { link = 'Identifier' }) -- various variable names
@ -28,7 +29,7 @@ return function(c, config)
set_hl('@string.special', { link = 'Constant' }) -- other special strings (e.g. dates)
set_hl('@string.special.symbol', { fg = c.violet }) -- symbols or atoms
set_hl('@string.special.url', { link = 'Underlined' }) -- URIs (e.g. hyperlinks)
set_hl('@string.special.path', { link = 'Underlined'}) -- filenames
set_hl('@string.special.path', { link = 'Underlined' }) -- filenames
set_hl('@character', { link = 'String' }) -- character literals
set_hl('@character.special', { link = 'Constant' }) -- special characters (e.g. wildcards)
set_hl('@boolean', { link = 'Constant' }) -- boolean literals

7
stylua.toml Normal file
View file

@ -0,0 +1,7 @@
column_width = 80
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
call_parentheses = "Always"
collapse_simple_statement = "ConditionalOnly"

27
test.py Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/python3
import subprocess
import sys
def run_commands(commands):
for command in commands:
process = subprocess.Popen(command, shell=True)
process.wait()
if __name__ == '__main__':
install_dependencies = False
if len(sys.argv) > 1 and sys.argv[1] == '--install':
install_dependencies = True
commands = []
if install_dependencies:
commands.append('cargo install stylua')
commands.append('sudo luarocks install luacheck')
commands.append('sudo luarocks install vusted')
commands.append('stylua . -f ./stylua.toml')
commands.append('vusted ./tests')
run_commands(commands)

19
tests/autocmd_spec.lua Normal file
View file

@ -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)

47
tests/colors_spec.lua Normal file
View file

@ -0,0 +1,47 @@
local colorhelper = require('solarized.utils.colors')
local solarized_palette = require('solarized.palette')
describe('Color Conversions', function()
test('Convert hex to RGB', function()
local colors = solarized_palette.get_colors()
local red, green, blue = colorhelper.hex_to_rgb(colors.yellow)
local expect = { red = 181, green = 137, blue = 0 }
assert.are.same(expect.red, red)
assert.are.same(expect.green, green)
assert.are.same(expect.blue, blue)
end)
test('Convert RGB to hex', function()
local colors = solarized_palette.get_colors()
local yellow = { red = 181, green = 137, blue = 0 }
local output = colorhelper.rgb_to_hex(yellow.red, yellow.green, yellow.blue)
local expect = colors.yellow
assert.equals(expect, string.lower(output))
end)
test('Darken the color by percentage', function()
local colors = solarized_palette.get_colors()
local output = colorhelper.darken(colors.green, 100)
local expect = '#000000'
assert.equals(expect, output)
end)
test('Lighten the color by percentage', function()
local colors = solarized_palette.get_colors()
local output = colorhelper.lighten(colors.green, 100)
local expect = '#ffffff'
assert.equals(expect, output)
end)
test('Blend colors', function()
local blend = require('solarized.utils.colors').blend
local alpha = 0.15
local expect = '#27383f'
local output = blend('#73daca', '#1a1b26', alpha)
assert.equals(output, expect)
end)
end)

34
tests/config_spec.lua Normal file
View file

@ -0,0 +1,34 @@
describe('Configuration', function()
local default_config = require('solarized.config').default_config()
test('Default configuration', function()
local expect = 'table'
assert.equals(expect, type(default_config))
end)
test('Unique configuration table instances', function()
local config1 = require('solarized.config').default_config()
local config2 = require('solarized.config').default_config()
assert.are_not.equals(config1, config2)
end)
test('Extend default configuration', function()
local user_config = {
transparent = true,
styles = {},
}
local config = vim.tbl_deep_extend('force', default_config, user_config)
local expect = 'table'
local expect2 = true
assert.equals(expect, type(config.styles.comments))
assert.equals(expect, type(config.styles.functions))
assert.equals(expect, type(config.styles.variables))
assert.equals(expect, type(config.styles.numbers))
assert.equals(expect, type(config.colors))
assert.equals(expect, type(config.highlights))
assert.equals(expect2, config.transparent)
end)
end)

30
tests/load_spec.lua Normal file
View file

@ -0,0 +1,30 @@
local utils = require('solarized.utils.test')
local to_hex = utils.to_hex
describe('Initialization', function()
setup(function()
vim.o.background = 'light'
vim.cmd.colorscheme('solarized')
end)
test('Loads without encountering any errors', function()
assert.equal('solarized', vim.g.colors_name)
assert.is_true(vim.o.termguicolors)
end)
test('Background is set to light', function()
local output = vim.api.nvim_get_hl(0, { name = 'Normal' })
local expect = '#fdf6e3'
assert.equals(expect, to_hex(output.bg))
end)
test('Selenized is being loaded', function()
require('solarized').setup({ palette = 'selenized' })
vim.cmd.colorscheme('solarized')
local output = vim.api.nvim_get_hl(0, { name = 'Normal' })
local expect = '#fbf3db'
assert.equals(expect, to_hex(output.bg))
end)
end)

39
tests/palette_spec.lua Normal file
View file

@ -0,0 +1,39 @@
local solarized_palette = require('solarized.palette')
describe('Palette', function()
test('Extend solarized color palette', function()
local default_colors = solarized_palette.get_colors()
local custom_colors = {
blue2 = '#c7e8f3',
purple = '#cf9aca',
magenta2 = '#8e4162',
}
local output =
solarized_palette.extend_colors(default_colors, custom_colors)
local expect = vim.deepcopy(default_colors)
expect.blue2 = custom_colors.blue2
expect.purple = custom_colors.purple
expect.magenta2 = custom_colors.magenta2
assert.are.same(expect, output)
end)
test(
'Correct any invalid colors when extending the solarized palette',
function()
local default_colors = solarized_palette.get_colors()
local custom_colors = {
white = '#aaaaaaa',
pink = '#cf9',
purple = '#8e4',
}
local output =
solarized_palette.extend_colors(default_colors, custom_colors)
local expect = vim.deepcopy(default_colors)
expect.pink = '#cf9cf9'
expect.purple = '#8e48e4'
assert.are.same(expect, output)
end
)
end)

85
tests/setup_spec.lua Normal file
View file

@ -0,0 +1,85 @@
local solarized_palette = require('solarized.palette')
local utils = require('solarized.utils.test')
local to_hex = utils.to_hex
describe('Setup', function()
setup(function()
local solarized = require('solarized')
solarized.setup({
theme = 'neo',
colors = function(c, helper)
return {
fg = '#c7e8f3',
bg = '#000',
yellow2 = helper.darken(c.yellow, 20),
}
end,
styles = {
comments = { italic = false, bold = true, underline = true },
functions = { italic = true },
},
highlights = function(c)
return {
Normal = { fg = c.fg, bg = c.bg },
Function = { italic = false },
Type = { fg = c.yellow2 },
['@function.builtin'] = { link = 'Special' },
}
end,
})
vim.cmd.colorscheme('solarized')
end)
test('Customizing Highlight Groups', function()
local colors = solarized_palette.get_colors()
local output1 = vim.api.nvim_get_hl(0, { name = 'Normal' })
local output2 = vim.api.nvim_get_hl(0, { name = 'Function' })
assert.equals('#c7e8f3', to_hex(output1.fg))
assert.equals('#000000', to_hex(output1.bg))
assert.are_not.same(colors.yellow, to_hex(output2.fg))
end)
test('Changing Comment Style', function()
local output = vim.api.nvim_get_hl(0, { name = 'Comment' })
assert.is_true(output.bold)
assert.is_true(output.underline)
assert.is_nil(output.italic)
end)
test('Changing Function Style', function()
local output = vim.api.nvim_get_hl(0, { name = 'Function' })
assert.is_true(output.cterm.italic)
end)
test(
'Customizable Highlight Groups Without Losing Previous Configuration',
function()
local output = vim.api.nvim_get_hl(0, { name = 'Function' })
local default_colors = solarized_palette.get_colors()
assert.is_nil(output.italic)
assert.equals(default_colors.blue, to_hex(output.fg))
end
)
test('Ability to Change the Default Theme', function()
local colors = solarized_palette.get_colors()
local output = vim.api.nvim_get_hl(0, { name = 'Directory' })
assert.equals(colors.orange, to_hex(output.fg))
end)
test(
'Function.builtin in linked to special, but doesnt have guifg',
function()
local output = vim.api.nvim_get_hl(0, { name = '@function.builtin' })
local expected = { link = 'Special' }
assert.are.same(expected, output)
end
)
end)