Skip to content

Commit 777851c

Browse files
authored
Merge pull request #259 from tmillr/fix-incorrect-highlights
fix: incorrect syntax highlighting
2 parents 464ff89 + cb601d8 commit 777851c

19 files changed

+617
-392
lines changed

.github/workflows/update-color-primitives.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
packages: read
2323
pull-requests: write
2424
statuses: write
25-
25+
2626
steps:
2727
- uses: actions/checkout@v3
2828

README.md

+12-15
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ require('github-theme').setup({
227227
dim_inactive = false, -- Non focused panes set to alternative background
228228
module_default = true, -- Default enable value for modules
229229
styles = { -- Style to be applied to different syntax groups
230-
comments = 'italic', -- Value is any valid attr-list value `:help attr-list`
230+
comments = 'NONE', -- Value is any valid attr-list value `:help attr-list`
231231
functions = 'NONE',
232-
keywords = 'italic',
232+
keywords = 'NONE',
233233
variables = 'NONE',
234234
conditionals = 'NONE',
235235
constants = 'NONE',
@@ -263,15 +263,13 @@ require('github-theme').setup({
263263
vim.cmd('colorscheme github_dark')
264264
```
265265

266-
If you would like to change any of the default options above you only have to define the options that change. If an
267-
option is not present in your options table the default option will be used. For example if changing the styles of
268-
certain syntax is the only desired change then your options table would look like:
266+
If you would like to change any of the default options above, simply specify the options that you'd like to change. Unspecified options will use their default value. For example, if you only wanted to change the styles of certain syntax items:
269267

270268
```lua
271269
require('github-theme').setup({
272270
options = {
273271
styles = {
274-
comments = 'NONE',
272+
comments = 'italic',
275273
keywords = 'bold',
276274
types = 'italic,bold',
277275
}
@@ -303,14 +301,11 @@ local palettes = {
303301
all = {
304302
-- Each palette defines these colors:
305303
-- black, gray, blue, green, magenta, pink, red, white, yellow, cyan
306-
307304
--
308305
-- These colors have 2 shades: base, and bright
309-
--
310-
-- Defining just a color defines it's base color
311-
red = {
312-
base = '#ff0000'
313-
},
306+
307+
-- Passing a string sets the base
308+
red = '#ff0000',
314309
},
315310
github_dark = {
316311
-- Defining multiple shades is done by passing a table
@@ -371,7 +366,7 @@ local specs = {
371366
}
372367

373368
-- Groups are the highlight group definitions. The keys of this table are the name of the highlight
374-
-- groups that will be overridden. The value is a table with the following values:
369+
-- groups that will be overridden. The value is a table with the following keys:
375370
-- - fg, bg, style, sp, link,
376371
--
377372
-- Just like `spec` groups support templates. This time the template is based on a spec object.
@@ -601,8 +596,10 @@ Set your airline colorscheme with `:AirlineThemes` vim command.
601596

602597
## Syntax highlight groups
603598

604-
This section will help you determine what highlight group is being applied to a piece of syntax. These sections will
605-
output the highlight group for the value under the cursor.
599+
This section will help you determine what highlight group is being applied to a piece of syntax. These methods
600+
show which highlight group(s) is in use at the current screen position of the cursor (under the cursor).
601+
602+
> **Note** On Neovim v0.9.0 and later, you can use the command `:Inspect`, or the Lua function `vim.show_pos()`.
606603
607604
#### Treesitter highlighting
608605

Usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ Current list of modules are:
410410
### Neovim specific modules
411411

412412
The following modules are enabled by default only when on neovim, `diagnostic`, `native_lsp`, `treesitter`. These modules are part of the core neovim experience and
413-
are liked to by other modules. This also means that they will still be enabled when setting `module_default` to `false`.
413+
are linked to by other modules. This also means that they will still be enabled when setting `module_default` to `false`.
414414

415415
### Extended modules
416416

doc/github-nvim-theme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ NEOVIM SPECIFIC MODULES ~
509509

510510
The following modules are enabled by default only when on neovim, `diagnostic`,
511511
`native_lsp`, `treesitter`. These modules are part of the core neovim
512-
experience and are liked to by other modules. This also means that they will
512+
experience and are linked to by other modules. This also means that they will
513513
still be enabled when setting `module_default` to `false`.
514514

515515

lua/github-theme/config.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ local defaults = {
1313
dim_inactive = false,
1414
module_default = true,
1515
styles = {
16-
comments = 'italic',
16+
comments = 'NONE',
1717
functions = 'NONE',
18-
keywords = 'italic',
18+
keywords = 'NONE',
1919
variables = 'NONE',
2020
conditionals = 'NONE',
2121
constants = 'NONE',

lua/github-theme/group/modules/treesitter.lua

+168-104
Large diffs are not rendered by default.

lua/github-theme/group/syntax.lua

+35-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ function M.get(spec, config)
44
local syn = spec.syntax
55
local stl = config.styles
66

7+
---Clears nvim's default highlighting for a highlight-group and allows
8+
---falling-back to another hl-group when multiple highlights/groups are
9+
---assigned/stacked at a particular screen position. This is just an empty
10+
---table.
11+
---
12+
---NOTE: assigning this to a group is different from explicitly setting a
13+
---group's foreground color to the global/default foreground color. When
14+
---multiple highlights are stacked/assigned to the same screen position, this
15+
---will allow the other highlights/groups to take effect, whereas explicitly
16+
---setting a hl-group's `fg` will not.
17+
---
18+
---| Setting | Fallback |
19+
---| ------------------------------------------------------------ | -------- |
20+
---| `GROUP = FALLBACK_OR_NONE` (i.e. set to this variable) (Lua) | true |
21+
---| Link to `@none`, `Fg`, or `NONE` | true |
22+
---| `GROUP = { fg = DEFAULT_FG }` (Lua) | false |
23+
---| `hi! clear GROUP` (Vim command) | false |
24+
---| `hi! GROUP NONE` (Vim command) | false |
25+
local FALLBACK_OR_NONE = setmetatable({}, {
26+
__newindex = function()
27+
error('attempt to set index of readonly table', 2)
28+
end,
29+
})
30+
731
-- TODO:
832
-- (1) add Commented style settings in config module
933
-- stylua: ignore
@@ -35,16 +59,17 @@ function M.get(spec, config)
3559
PreCondit = { link = 'PreProc' }, -- preprocessor #if, #else, #endif, etc.
3660

3761
Type = { fg = syn.type, style = stl.types }, -- (preferred) int, long, char, etc.
38-
StorageClass = { link = 'Type' }, -- static, register, volatile, etc.
39-
Structure = { link = 'Type' }, -- struct, union, enum, etc.
40-
Typedef = { link = 'Type' }, -- A typedef
41-
42-
Special = { fg = syn.ident }, -- (preferred) any special symbol
43-
SpecialChar = { link = 'Special' }, -- special character in a constant
44-
Tag = { link = 'Special' }, -- you can use CTRL-] on this
45-
Delimiter = { link = 'Special' }, -- character that needs attention
46-
SpecialComment = { link = 'Special' }, -- special things inside a comment
47-
Debug = { link = 'Special' }, -- debugging statements
62+
-- StorageClass = { link = 'Type' }, -- static, register, volatile, etc.
63+
-- Structure = { link = 'Type' }, -- struct, union, enum, etc.
64+
-- Typedef = { link = 'Type' }, -- A typedef
65+
66+
Special = { fg = spec.fg1 }, -- (preferred) any special symbol
67+
-- Special = { fg = syn.ident }, -- (preferred) any special symbol
68+
-- SpecialChar = { link = 'Special' }, -- special character in a constant
69+
-- Tag = { link = 'Special' }, -- you can use CTRL-] on this
70+
-- Delimiter = { link = 'Special' }, -- character that needs attention
71+
-- SpecialComment = { link = 'Special' }, -- special things inside a comment
72+
-- Debug = { link = 'Special' }, -- debugging statements
4873

4974
Underlined = { style = 'underline' }, -- (preferred) text that stands out, HTML links
5075
Bold = { style = 'bold' },

lua/github-theme/palette/github_dark.lua

+40-30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ local meta = {
55
light = false,
66
}
77

8+
local primitives =
9+
require('github-theme.palette.primitives.' .. meta.name:gsub('^github%W*', '', 1))
10+
11+
local pl = primitives.prettylights
12+
813
---Github Dark scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark.ts
1015
-- stylua: ignore
@@ -173,39 +178,39 @@ local function generate_spec(pal)
173178
bg3 = pal.scale.gray[6], -- Lighter bg (cursor line)
174179
bg4 = pal.scale.gray[4], -- Conceal
175180

176-
fg0 = pal.fg.subtle, -- Lighter fg
177-
fg1 = pal.fg.default, -- Default fg
178-
fg2 = pal.fg.muted, -- Darker fg (status line)
179-
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
181+
fg0 = pal.fg.subtle, -- Lighter fg
182+
fg1 = pal.fg.default, -- Default fg
183+
fg2 = pal.fg.muted, -- Darker fg (status line)
184+
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
180185

181-
sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
182-
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
183-
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
186+
sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
187+
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
188+
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
184189
}
185190

186191
spec.syntax = {
187-
bracket = pal.scale.orange[3], -- Brackets and Punctuation
188-
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
189-
builtin1 = pal.scale.red[4], -- Builtin type
190-
builtin2 = pal.scale.blue[3], -- Builtin const
191-
comment = pal.scale.gray[5], -- Comment
192-
conditional = pal.scale.red[4], -- Conditional and loop
193-
const = pal.scale.blue[3], -- Constants, imports and booleans
194-
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.purple[3], -- Field
196-
func = pal.scale.purple[2], -- Functions and Titles
197-
ident = pal.scale.blue[3], -- Identifiers
198-
keyword = pal.scale.red[4], -- Keywords
199-
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.green[2], -- Parameters
202-
preproc = pal.scale.red[4], -- PreProc
203-
regex = pal.scale.blue[3], -- Regex
204-
statement = pal.scale.red[4], -- Statements
205-
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.red[4], -- Types
207-
tag = pal.scale.green[2], -- Tags
208-
variable = spec.fg1, -- Variables
192+
bracket = spec.fg1, -- Brackets and Punctuation
193+
builtin0 = pl.syntax.constant, -- Builtin variable
194+
builtin1 = pl.syntax.keyword, -- Builtin type
195+
builtin2 = pl.syntax.constant, -- Builtin const
196+
comment = pl.syntax.comment, -- Comment
197+
conditional = pl.syntax.keyword, -- Conditional and loop
198+
const = pl.syntax.constant, -- Constants, imports and booleans
199+
dep = pal.scale.red[3], -- Deprecated
200+
field = pl.syntax.constant, -- Field
201+
func = pl.syntax.entity, -- Functions and Titles
202+
ident = spec.fg1, -- Identifiers
203+
keyword = pl.syntax.keyword, -- Keywords
204+
number = pl.syntax.constant, -- Numbers
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
207+
preproc = pl.syntax.keyword, -- PreProc
208+
regex = pl.syntax.string, -- Regex
209+
statement = pl.syntax.keyword, -- Statements
210+
string = pl.syntax.string, -- Strings
211+
type = pl.syntax.variable, -- Types
212+
tag = pl.syntax.entityTag, -- Tags
213+
variable = spec.fg1, -- Variables
209214
}
210215

211216
spec.diag = {
@@ -241,4 +246,9 @@ local function generate_spec(pal)
241246
return spec
242247
end
243248

244-
return { meta = meta, palette = palette, generate_spec = generate_spec }
249+
return {
250+
meta = meta,
251+
primitives = primitives,
252+
palette = palette,
253+
generate_spec = generate_spec,
254+
}

lua/github-theme/palette/github_dark_colorblind.lua

+40-30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ local meta = {
55
light = false,
66
}
77

8+
local primitives =
9+
require('github-theme.palette.primitives.' .. meta.name:gsub('^github%W*', '', 1))
10+
11+
local pl = primitives.prettylights
12+
813
---Github Dark Colorblind scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_colorblind.ts
1015
-- stylua: ignore
@@ -173,39 +178,39 @@ local function generate_spec(pal)
173178
bg3 = pal.scale.gray[9], -- Lighter bg (cursor line)
174179
bg4 = pal.scale.gray[4], -- Conceal
175180

176-
fg0 = pal.fg.subtle, -- Lighter fg
177-
fg1 = pal.fg.default, -- Default fg
178-
fg2 = pal.fg.muted, -- Darker fg (status line)
179-
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
181+
fg0 = pal.fg.subtle, -- Lighter fg
182+
fg1 = pal.fg.default, -- Default fg
183+
fg2 = pal.fg.muted, -- Darker fg (status line)
184+
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
180185

181-
sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
182-
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
183-
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
186+
sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
187+
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
188+
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
184189
}
185190

186191
spec.syntax = {
187-
bracket = pal.scale.orange[3], -- Brackets and Punctuation
188-
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
189-
builtin1 = pal.scale.red[4], -- Builtin type
190-
builtin2 = pal.scale.blue[3], -- Builtin const
191-
comment = pal.scale.gray[5], -- Comment
192-
conditional = pal.scale.red[4], -- Conditional and loop
193-
const = pal.scale.blue[3], -- Constants, imports and booleans
194-
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.orange[3], -- Field
196-
func = pal.scale.purple[3], -- Functions and Titles
197-
ident = pal.scale.blue[3], -- Identifiers
198-
keyword = pal.scale.red[4], -- Keywords
199-
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.orange[2], -- Parameters
202-
preproc = pal.scale.red[4], -- PreProc
203-
regex = pal.scale.blue[3], -- Regex
204-
statement = pal.scale.red[4], -- Statements
205-
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.orange[3], -- Types
207-
tag = pal.scale.blue[3], -- Tags
208-
variable = spec.fg1, -- Variables
192+
bracket = spec.fg1, -- Brackets and Punctuation
193+
builtin0 = pl.syntax.constant, -- Builtin variable
194+
builtin1 = pl.syntax.keyword, -- Builtin type
195+
builtin2 = pl.syntax.constant, -- Builtin const
196+
comment = pl.syntax.comment, -- Comment
197+
conditional = pl.syntax.keyword, -- Conditional and loop
198+
const = pl.syntax.constant, -- Constants, imports and booleans
199+
dep = pal.scale.red[3], -- Deprecated
200+
field = pl.syntax.constant, -- Field
201+
func = pl.syntax.entity, -- Functions and Titles
202+
ident = spec.fg1, -- Identifiers
203+
keyword = pl.syntax.keyword, -- Keywords
204+
number = pl.syntax.constant, -- Numbers
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
207+
preproc = pl.syntax.keyword, -- PreProc
208+
regex = pl.syntax.string, -- Regex
209+
statement = pl.syntax.keyword, -- Statements
210+
string = pl.syntax.string, -- Strings
211+
type = pl.syntax.variable, -- Types
212+
tag = pl.syntax.entityTag, -- Tags
213+
variable = spec.fg1, -- Variables
209214
}
210215

211216
spec.diag = {
@@ -241,4 +246,9 @@ local function generate_spec(pal)
241246
return spec
242247
end
243248

244-
return { meta = meta, palette = palette, generate_spec = generate_spec }
249+
return {
250+
meta = meta,
251+
primitives = primitives,
252+
palette = palette,
253+
generate_spec = generate_spec,
254+
}

0 commit comments

Comments
 (0)