Skip to content

Commit

Permalink
fix: Configuring highlight of type "@variable" #69
Browse files Browse the repository at this point in the history
feat: github workflows, vusted, stylua
  • Loading branch information
maxmx03 committed Mar 28, 2024
1 parent a0f0226 commit 6a34504
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 38 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"diagnostics.disable": ["undefined-field"]
}
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
7 changes: 6 additions & 1 deletion lua/solarized/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 33 additions & 33 deletions lua/solarized/themes/default/syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions lua/solarized/themes/default/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lua/solarized/themes/neo/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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 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)
47 changes: 47 additions & 0 deletions tests/colors_spec.lua
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions tests/config_spec.lua
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions tests/load_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 6a34504

Please sign in to comment.