Skip to content

Commit

Permalink
fix: incorrect syntax highlighting
Browse files Browse the repository at this point in the history
Syntax highlighting is still not 100% accurate (due mostly to
highlighting differences between different languages which require
particular consideration), however, the accuracy of the highlights have
been improved, both overall, and in terms of common languages such as:
rust, ruby, ecma, c, c#, go, html, css, make, python, and lua.

See projekt0n#252
  • Loading branch information
tmillr committed Jun 1, 2023
1 parent 1651ccd commit f59fce7
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 169 deletions.
248 changes: 150 additions & 98 deletions lua/github-theme/group/modules/treesitter.lua

Large diffs are not rendered by default.

25 changes: 25 additions & 0 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 @@ -39,6 +63,7 @@ function M.get(spec, config)
-- 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
Expand Down
20 changes: 15 additions & 5 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 @@ -192,18 +197,18 @@ local function generate_spec(pal)
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
field = pl.syntax.constant, -- 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
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- 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
type = pl.syntax.variable, -- Types
tag = pal.scale.green[2], -- Tags
variable = spec.fg1, -- Variables
}
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,
}
20 changes: 15 additions & 5 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 @@ -192,18 +197,18 @@ local function generate_spec(pal)
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
field = pl.syntax.constant, -- 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
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- 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
type = pl.syntax.variable, -- Types
tag = pal.scale.blue[3], -- Tags
variable = spec.fg1, -- Variables
}
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,
}
22 changes: 16 additions & 6 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 @@ -184,26 +189,26 @@ local function generate_spec(pal)
}

spec.syntax = {
bracket = pal.scale.green[4], -- Brackets and Punctuation
bracket = spec.fg1, -- 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
field = pl.syntax.constant, -- 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
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- 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
type = pl.syntax.variable, -- Types
tag = pal.scale.green[2], -- Tags
variable = spec.fg1, -- Variables
}
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,
}
20 changes: 15 additions & 5 deletions lua/github-theme/palette/github_dark_high_contrast.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 High Contrast scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_high_contrast.ts
-- stylua: ignore
Expand Down Expand Up @@ -192,18 +197,18 @@ local function generate_spec(pal)
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
field = pl.syntax.constant, -- 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
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- 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
type = pl.syntax.variable, -- Types
tag = pal.scale.green[2], -- Tags
variable = spec.fg1, -- Variables
}
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,
}
20 changes: 15 additions & 5 deletions lua/github-theme/palette/github_dark_tritanopia.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 Tritanopia scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_tritanopia.ts
-- stylua: ignore
Expand Down Expand Up @@ -192,18 +197,18 @@ local function generate_spec(pal)
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
field = pl.syntax.constant, -- 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
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- 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
type = pl.syntax.variable, -- Types
tag = pal.scale.blue[3], -- Tags
variable = spec.fg1, -- Variables
}
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,
}
22 changes: 16 additions & 6 deletions lua/github-theme/palette/github_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local meta = {
light = true,
}

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

local pl = primitives.prettylights

---Github Light scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/light.ts
-- stylua: ignore
Expand Down Expand Up @@ -185,26 +190,26 @@ local function generate_spec(pal)
}

spec.syntax = {
bracket = pal.scale.orange[5], -- Brackets and Punctuation
bracket = spec.fg1, -- Brackets and Punctuation
builtin0 = pal.scale.red[6], -- Builtin variable
builtin1 = pal.scale.red[6], -- Builtin type
builtin2 = pal.scale.blue[7], -- Builtin const
comment = pal.scale.gray[6], -- Comment
conditional = pal.scale.red[6], -- Conditional and loop
const = pal.scale.blue[6], -- Constants, imports and booleans
dep = pal.scale.red[8], -- Deprecated
field = spec.fg1, -- Field
field = pl.syntax.constant, -- Field
func = pal.scale.purple[6], -- Functions and Titles
ident = pal.scale.blue[9], -- Identifiers
keyword = pal.scale.red[6], -- Keywords
number = pal.scale.blue[7], -- Numbers
operator = pal.scale.red[6], -- Operators
param = pal.scale.orange[5], -- PreProc
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- Parameters
preproc = pal.scale.red[6], -- PreProc
regex = pal.scale.blue[9], -- Regex
statement = pal.scale.red[6], -- Statements
string = pal.scale.blue[8], -- Strings
type = pal.scale.red[6], -- Types
type = pl.syntax.variable, -- Types
tag = pal.scale.green[6], -- Tags
variable = spec.fg1, -- Variables
}
Expand Down Expand Up @@ -242,4 +247,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,
}
20 changes: 15 additions & 5 deletions lua/github-theme/palette/github_light_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local meta = {
light = true,
}

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

local pl = primitives.prettylights

---Github Light scale variables
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/light_colorblind.ts
-- stylua: ignore
Expand Down Expand Up @@ -193,18 +198,18 @@ local function generate_spec(pal)
conditional = pal.scale.red[6], -- Conditional and loop
const = pal.scale.blue[6], -- Constants, imports and booleans
dep = pal.scale.red[8], -- Deprecated
field = pal.scale.orange[8], -- Field
field = pl.syntax.constant, -- Field
func = pal.scale.purple[6], -- Functions and Titles
ident = pal.scale.blue[9], -- Identifiers
keyword = pal.scale.red[6], -- Keywords
number = pal.scale.blue[7], -- Numbers
operator = pal.scale.red[6], -- Operators
param = pal.scale.orange[5], -- PreProc
operator = pl.syntax.constant, -- Operators
param = spec.fg1, -- Parameters
preproc = pal.scale.red[6], -- PreProc
regex = pal.scale.blue[9], -- Regex
statement = pal.scale.red[6], -- Statements
string = pal.scale.blue[8], -- Strings
type = pal.scale.orange[5], -- Types
type = pl.syntax.variable, -- Types
tag = pal.scale.green[6], -- Tags
variable = spec.fg1, -- Variables
}
Expand Down Expand Up @@ -242,4 +247,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

0 comments on commit f59fce7

Please sign in to comment.