Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect syntax highlighting #259

Merged
merged 8 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update-color-primitives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
packages: read
pull-requests: write
statuses: write

steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions lua/github-theme/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ local defaults = {
dim_inactive = false,
module_default = true,
styles = {
comments = 'italic',
comments = 'NONE',
functions = 'NONE',
keywords = 'italic',
keywords = 'NONE',
variables = 'NONE',
conditionals = 'NONE',
constants = 'NONE',
Expand Down
272 changes: 168 additions & 104 deletions lua/github-theme/group/modules/treesitter.lua

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions lua/github-theme/group/syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ function M.get(spec, config)
local syn = spec.syntax
local stl = config.styles

---Clears nvim's default highlighting for a highlight-group and allows
---falling-back to another hl-group when multiple highlights/groups are
---assigned/stacked at a particular screen position. This is just an empty
---table.
---
---NOTE: assigning this to a group is different from explicitly setting a
---group's foreground color to the global/default foreground color. When
---multiple highlights are stacked/assigned to the same screen position, this
---will allow the other highlights/groups to take effect, whereas explicitly
---setting a hl-group's `fg` will not.
---
---| Setting | Fallback |
---| ------------------------------------------------------------ | -------- |
---| `GROUP = FALLBACK_OR_NONE` (i.e. set to this variable) (Lua) | true |
---| Link to `@none`, `Fg`, or `NONE` | true |
---| `GROUP = { fg = DEFAULT_FG }` (Lua) | false |
---| `hi! clear GROUP` (Vim command) | false |
---| `hi! GROUP NONE` (Vim command) | false |
local FALLBACK_OR_NONE = setmetatable({}, {
__newindex = function()
error('attempt to set index of readonly table', 2)
end,
})

-- TODO:
-- (1) add Commented style settings in config module
-- stylua: ignore
Expand Down Expand Up @@ -35,16 +59,17 @@ function M.get(spec, config)
PreCondit = { link = 'PreProc' }, -- preprocessor #if, #else, #endif, etc.

Type = { fg = syn.type, style = stl.types }, -- (preferred) int, long, char, etc.
StorageClass = { link = 'Type' }, -- static, register, volatile, etc.
Structure = { link = 'Type' }, -- struct, union, enum, etc.
Typedef = { link = 'Type' }, -- A typedef

Special = { fg = syn.ident }, -- (preferred) any special symbol
SpecialChar = { link = 'Special' }, -- special character in a constant
Tag = { link = 'Special' }, -- you can use CTRL-] on this
Delimiter = { link = 'Special' }, -- character that needs attention
SpecialComment = { link = 'Special' }, -- special things inside a comment
Debug = { link = 'Special' }, -- debugging statements
-- StorageClass = { link = 'Type' }, -- static, register, volatile, etc.
-- Structure = { link = 'Type' }, -- struct, union, enum, etc.
-- Typedef = { link = 'Type' }, -- A typedef

Special = { fg = spec.fg1 }, -- (preferred) any special symbol
-- Special = { fg = syn.ident }, -- (preferred) any special symbol
-- SpecialChar = { link = 'Special' }, -- special character in a constant
-- Tag = { link = 'Special' }, -- you can use CTRL-] on this
-- Delimiter = { link = 'Special' }, -- character that needs attention
-- SpecialComment = { link = 'Special' }, -- special things inside a comment
-- Debug = { link = 'Special' }, -- debugging statements

Underlined = { style = 'underline' }, -- (preferred) text that stands out, HTML links
Bold = { style = 'bold' },
Expand Down
70 changes: 40 additions & 30 deletions lua/github-theme/palette/github_dark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local meta = {
light = false,
}

local primitives =
require('github-theme.palette.primitives.' .. meta.name:gsub('^github%W*', '', 1))

local pl = primitives.prettylights

---Github Dark scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark.ts
-- stylua: ignore
Expand Down Expand Up @@ -173,39 +178,39 @@ local function generate_spec(pal)
bg3 = pal.scale.gray[6], -- Lighter bg (cursor line)
bg4 = pal.scale.gray[4], -- Conceal

fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)

sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
}

spec.syntax = {
bracket = pal.scale.orange[3], -- Brackets and Punctuation
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
builtin1 = pal.scale.red[4], -- Builtin type
builtin2 = pal.scale.blue[3], -- Builtin const
comment = pal.scale.gray[5], -- Comment
conditional = pal.scale.red[4], -- Conditional and loop
const = pal.scale.blue[3], -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pal.scale.purple[3], -- Field
func = pal.scale.purple[2], -- Functions and Titles
ident = pal.scale.blue[3], -- Identifiers
keyword = pal.scale.red[4], -- Keywords
number = pal.scale.blue[3], -- Numbers
operator = pal.scale.red[4], -- Operators
param = pal.scale.green[2], -- Parameters
preproc = pal.scale.red[4], -- PreProc
regex = pal.scale.blue[3], -- Regex
statement = pal.scale.red[4], -- Statements
string = pal.scale.blue[2], -- Strings
type = pal.scale.red[4], -- Types
tag = pal.scale.green[2], -- Tags
variable = spec.fg1, -- Variables
bracket = spec.fg1, -- Brackets and Punctuation
builtin0 = pl.syntax.constant, -- Builtin variable
builtin1 = pl.syntax.keyword, -- Builtin type
builtin2 = pl.syntax.constant, -- Builtin const
comment = pl.syntax.comment, -- Comment
conditional = pl.syntax.keyword, -- Conditional and loop
const = pl.syntax.constant, -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pl.syntax.constant, -- Field
func = pl.syntax.entity, -- Functions and Titles
ident = spec.fg1, -- Identifiers
keyword = pl.syntax.keyword, -- Keywords
number = pl.syntax.constant, -- Numbers
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- Parameters
preproc = pl.syntax.keyword, -- PreProc
regex = pl.syntax.string, -- Regex
statement = pl.syntax.keyword, -- Statements
string = pl.syntax.string, -- Strings
type = pl.syntax.variable, -- Types
tag = pl.syntax.entityTag, -- Tags
variable = spec.fg1, -- Variables
}

spec.diag = {
Expand Down Expand Up @@ -241,4 +246,9 @@ local function generate_spec(pal)
return spec
end

return { meta = meta, palette = palette, generate_spec = generate_spec }
return {
meta = meta,
primitives = primitives,
palette = palette,
generate_spec = generate_spec,
}
70 changes: 40 additions & 30 deletions lua/github-theme/palette/github_dark_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local meta = {
light = false,
}

local primitives =
require('github-theme.palette.primitives.' .. meta.name:gsub('^github%W*', '', 1))

local pl = primitives.prettylights

---Github Dark Colorblind scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_colorblind.ts
-- stylua: ignore
Expand Down Expand Up @@ -173,39 +178,39 @@ local function generate_spec(pal)
bg3 = pal.scale.gray[9], -- Lighter bg (cursor line)
bg4 = pal.scale.gray[4], -- Conceal

fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)

sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
}

spec.syntax = {
bracket = pal.scale.orange[3], -- Brackets and Punctuation
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
builtin1 = pal.scale.red[4], -- Builtin type
builtin2 = pal.scale.blue[3], -- Builtin const
comment = pal.scale.gray[5], -- Comment
conditional = pal.scale.red[4], -- Conditional and loop
const = pal.scale.blue[3], -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pal.scale.orange[3], -- Field
func = pal.scale.purple[3], -- Functions and Titles
ident = pal.scale.blue[3], -- Identifiers
keyword = pal.scale.red[4], -- Keywords
number = pal.scale.blue[3], -- Numbers
operator = pal.scale.red[4], -- Operators
param = pal.scale.orange[2], -- Parameters
preproc = pal.scale.red[4], -- PreProc
regex = pal.scale.blue[3], -- Regex
statement = pal.scale.red[4], -- Statements
string = pal.scale.blue[2], -- Strings
type = pal.scale.orange[3], -- Types
tag = pal.scale.blue[3], -- Tags
variable = spec.fg1, -- Variables
bracket = spec.fg1, -- Brackets and Punctuation
builtin0 = pl.syntax.constant, -- Builtin variable
builtin1 = pl.syntax.keyword, -- Builtin type
builtin2 = pl.syntax.constant, -- Builtin const
comment = pl.syntax.comment, -- Comment
conditional = pl.syntax.keyword, -- Conditional and loop
const = pl.syntax.constant, -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pl.syntax.constant, -- Field
func = pl.syntax.entity, -- Functions and Titles
ident = spec.fg1, -- Identifiers
keyword = pl.syntax.keyword, -- Keywords
number = pl.syntax.constant, -- Numbers
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- Parameters
preproc = pl.syntax.keyword, -- PreProc
regex = pl.syntax.string, -- Regex
statement = pl.syntax.keyword, -- Statements
string = pl.syntax.string, -- Strings
type = pl.syntax.variable, -- Types
tag = pl.syntax.entityTag, -- Tags
variable = spec.fg1, -- Variables
}

spec.diag = {
Expand Down Expand Up @@ -241,4 +246,9 @@ local function generate_spec(pal)
return spec
end

return { meta = meta, palette = palette, generate_spec = generate_spec }
return {
meta = meta,
primitives = primitives,
palette = palette,
generate_spec = generate_spec,
}
70 changes: 40 additions & 30 deletions lua/github-theme/palette/github_dark_dimmed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local meta = {
light = false,
}

local primitives =
require('github-theme.palette.primitives.' .. meta.name:gsub('^github%W*', '', 1))

local pl = primitives.prettylights

---Github Dark Dimmed scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_dimmed.ts
-- stylua: ignore
Expand Down Expand Up @@ -173,39 +178,39 @@ local function generate_spec(pal)
bg3 = alpha(C(pal.fg.default), 0.1), -- Lighter bg (cursor line)
bg4 = pal.scale.gray[4], -- Conceal

fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
fg0 = pal.fg.subtle, -- Lighter fg
fg1 = pal.fg.default, -- Default fg
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)

sel0 = alpha(C(pal.accent.fg), 0.40), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
sel0 = alpha(C(pal.accent.fg), 0.40), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
}

spec.syntax = {
bracket = pal.scale.green[4], -- Brackets and Punctuation
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
builtin1 = pal.scale.red[4], -- Builtin type
builtin2 = pal.scale.blue[3], -- Builtin const
comment = pal.scale.gray[5], -- Comment
conditional = pal.scale.red[4], -- Conditional and loop
const = pal.scale.blue[3], -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pal.scale.purple[3], -- Field
func = pal.scale.purple[2], -- Functions and Titles
ident = pal.scale.blue[3], -- Identifiers
keyword = pal.scale.red[4], -- Keywords
number = pal.scale.blue[3], -- Numbers
operator = pal.scale.red[4], -- Operators
param = pal.scale.orange[3], -- Parameters
preproc = pal.scale.red[4], -- PreProc
regex = pal.scale.blue[3], -- Regex
statement = pal.scale.red[4], -- Statements
string = pal.scale.blue[2], -- Strings
type = pal.scale.red[4], -- Types
tag = pal.scale.green[2], -- Tags
variable = spec.fg1, -- Variables
bracket = spec.fg1, -- Brackets and Punctuation
builtin0 = pl.syntax.constant, -- Builtin variable
builtin1 = pl.syntax.keyword, -- Builtin type
builtin2 = pl.syntax.constant, -- Builtin const
comment = pl.syntax.comment, -- Comment
conditional = pl.syntax.keyword, -- Conditional and loop
const = pl.syntax.constant, -- Constants, imports and booleans
dep = pal.scale.red[3], -- Deprecated
field = pl.syntax.constant, -- Field
func = pl.syntax.entity, -- Functions and Titles
ident = spec.fg1, -- Identifiers
keyword = pl.syntax.keyword, -- Keywords
number = pl.syntax.constant, -- Numbers
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- Parameters
preproc = pl.syntax.keyword, -- PreProc
regex = pl.syntax.string, -- Regex
statement = pl.syntax.keyword, -- Statements
string = pl.syntax.string, -- Strings
type = pl.syntax.variable, -- Types
tag = pl.syntax.entityTag, -- Tags
variable = spec.fg1, -- Variables
}

spec.diag = {
Expand Down Expand Up @@ -241,4 +246,9 @@ local function generate_spec(pal)
return spec
end

return { meta = meta, palette = palette, generate_spec = generate_spec }
return {
meta = meta,
primitives = primitives,
palette = palette,
generate_spec = generate_spec,
}
Loading