Skip to content

Commit 1d7dc5a

Browse files
committed
fix: fix incorrect syntax highlighting
Syntax highlighting is still not 100% accurate (due mostly to highlighting differences between different languages which need 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. Fixes projekt0n#252
1 parent 8b41023 commit 1d7dc5a

11 files changed

+281
-170
lines changed

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

+116-99
Large diffs are not rendered by default.

lua/github-theme/group/syntax.lua

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

7+
---Clears nvim's default highlighting for a capture-group.
8+
local NONE = {}
9+
710
-- TODO:
811
-- (1) add Commented style settings in config module
912
-- stylua: ignore
@@ -39,6 +42,7 @@ function M.get(spec, config)
3942
-- Structure = { link = 'Type' }, -- struct, union, enum, etc.
4043
-- Typedef = { link = 'Type' }, -- A typedef
4144

45+
Special = NONE, -- (preferred) any special symbol
4246
-- Special = { fg = syn.ident }, -- (preferred) any special symbol
4347
-- SpecialChar = { link = 'Special' }, -- special character in a constant
4448
-- Tag = { link = 'Special' }, -- you can use CTRL-] on this

lua/github-theme/palette/github_dark.lua

+15-5
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
@@ -192,18 +197,18 @@ local function generate_spec(pal)
192197
conditional = pal.scale.red[4], -- Conditional and loop
193198
const = pal.scale.blue[3], -- Constants, imports and booleans
194199
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.purple[3], -- Field
200+
field = pl.syntax.constant, -- Field
196201
func = pal.scale.purple[2], -- Functions and Titles
197202
ident = pal.scale.blue[3], -- Identifiers
198203
keyword = pal.scale.red[4], -- Keywords
199204
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.green[2], -- Parameters
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
202207
preproc = pal.scale.red[4], -- PreProc
203208
regex = pal.scale.blue[3], -- Regex
204209
statement = pal.scale.red[4], -- Statements
205210
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.red[4], -- Types
211+
type = pl.syntax.variable, -- Types
207212
tag = pal.scale.green[2], -- Tags
208213
variable = spec.fg1, -- Variables
209214
}
@@ -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

+15-5
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
@@ -192,18 +197,18 @@ local function generate_spec(pal)
192197
conditional = pal.scale.red[4], -- Conditional and loop
193198
const = pal.scale.blue[3], -- Constants, imports and booleans
194199
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.orange[3], -- Field
200+
field = pl.syntax.constant, -- Field
196201
func = pal.scale.purple[3], -- Functions and Titles
197202
ident = pal.scale.blue[3], -- Identifiers
198203
keyword = pal.scale.red[4], -- Keywords
199204
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.orange[2], -- Parameters
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
202207
preproc = pal.scale.red[4], -- PreProc
203208
regex = pal.scale.blue[3], -- Regex
204209
statement = pal.scale.red[4], -- Statements
205210
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.orange[3], -- Types
211+
type = pl.syntax.variable, -- Types
207212
tag = pal.scale.blue[3], -- Tags
208213
variable = spec.fg1, -- Variables
209214
}
@@ -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_dimmed.lua

+16-6
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 Dimmed scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_dimmed.ts
1015
-- stylua: ignore
@@ -184,26 +189,26 @@ local function generate_spec(pal)
184189
}
185190

186191
spec.syntax = {
187-
bracket = pal.scale.green[4], -- Brackets and Punctuation
192+
bracket = spec.fg1, -- Brackets and Punctuation
188193
builtin0 = pal.scale.red[4], -- Builtin variable (Return Keywords, Regex, etc.)
189194
builtin1 = pal.scale.red[4], -- Builtin type
190195
builtin2 = pal.scale.blue[3], -- Builtin const
191196
comment = pal.scale.gray[5], -- Comment
192197
conditional = pal.scale.red[4], -- Conditional and loop
193198
const = pal.scale.blue[3], -- Constants, imports and booleans
194199
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.purple[3], -- Field
200+
field = pl.syntax.constant, -- Field
196201
func = pal.scale.purple[2], -- Functions and Titles
197202
ident = pal.scale.blue[3], -- Identifiers
198203
keyword = pal.scale.red[4], -- Keywords
199204
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.orange[3], -- Parameters
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
202207
preproc = pal.scale.red[4], -- PreProc
203208
regex = pal.scale.blue[3], -- Regex
204209
statement = pal.scale.red[4], -- Statements
205210
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.red[4], -- Types
211+
type = pl.syntax.variable, -- Types
207212
tag = pal.scale.green[2], -- Tags
208213
variable = spec.fg1, -- Variables
209214
}
@@ -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_high_contrast.lua

+15-5
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 High Contrast scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_high_contrast.ts
1015
-- stylua: ignore
@@ -192,18 +197,18 @@ local function generate_spec(pal)
192197
conditional = pal.scale.red[4], -- Conditional and loop
193198
const = pal.scale.blue[3], -- Constants, imports and booleans
194199
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.purple[3], -- Field
200+
field = pl.syntax.constant, -- Field
196201
func = pal.scale.purple[2], -- Functions and Titles
197202
ident = pal.scale.blue[3], -- Identifiers
198203
keyword = pal.scale.red[4], -- Keywords
199204
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.orange[3], -- Parameters
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
202207
preproc = pal.scale.red[4], -- PreProc
203208
regex = pal.scale.blue[3], -- Regex
204209
statement = pal.scale.red[4], -- Statements
205210
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.red[4], -- Types
211+
type = pl.syntax.variable, -- Types
207212
tag = pal.scale.green[2], -- Tags
208213
variable = spec.fg1, -- Variables
209214
}
@@ -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_tritanopia.lua

+15-5
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 Tritanopia scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/dark_tritanopia.ts
1015
-- stylua: ignore
@@ -192,18 +197,18 @@ local function generate_spec(pal)
192197
conditional = pal.scale.red[4], -- Conditional and loop
193198
const = pal.scale.blue[3], -- Constants, imports and booleans
194199
dep = pal.scale.red[3], -- Deprecated
195-
field = pal.scale.orange[3], -- Field
200+
field = pl.syntax.constant, -- Field
196201
func = pal.scale.purple[3], -- Functions and Titles
197202
ident = pal.scale.blue[3], -- Identifiers
198203
keyword = pal.scale.red[4], -- Keywords
199204
number = pal.scale.blue[3], -- Numbers
200-
operator = pal.scale.red[4], -- Operators
201-
param = pal.scale.orange[2], -- Parameters
205+
operator = pl.syntax.constant, -- Operators
206+
param = spec.fg1, -- Parameters
202207
preproc = pal.scale.red[4], -- PreProc
203208
regex = pal.scale.blue[3], -- Regex
204209
statement = pal.scale.red[4], -- Statements
205210
string = pal.scale.blue[2], -- Strings
206-
type = pal.scale.orange[3], -- Types
211+
type = pl.syntax.variable, -- Types
207212
tag = pal.scale.blue[3], -- Tags
208213
variable = spec.fg1, -- Variables
209214
}
@@ -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_light.lua

+16-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ local meta = {
55
light = true,
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 Light scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/light.ts
1015
-- stylua: ignore
@@ -185,26 +190,26 @@ local function generate_spec(pal)
185190
}
186191

187192
spec.syntax = {
188-
bracket = pal.scale.orange[5], -- Brackets and Punctuation
193+
bracket = spec.fg1, -- Brackets and Punctuation
189194
builtin0 = pal.scale.red[6], -- Builtin variable
190195
builtin1 = pal.scale.red[6], -- Builtin type
191196
builtin2 = pal.scale.blue[7], -- Builtin const
192197
comment = pal.scale.gray[6], -- Comment
193198
conditional = pal.scale.red[6], -- Conditional and loop
194199
const = pal.scale.blue[6], -- Constants, imports and booleans
195200
dep = pal.scale.red[8], -- Deprecated
196-
field = spec.fg1, -- Field
201+
field = pl.syntax.constant, -- Field
197202
func = pal.scale.purple[6], -- Functions and Titles
198203
ident = pal.scale.blue[9], -- Identifiers
199204
keyword = pal.scale.red[6], -- Keywords
200205
number = pal.scale.blue[7], -- Numbers
201-
operator = pal.scale.red[6], -- Operators
202-
param = pal.scale.orange[5], -- PreProc
206+
operator = pl.syntax.constant, -- Operators
207+
param = spec.fg1, -- Parameters
203208
preproc = pal.scale.red[6], -- PreProc
204209
regex = pal.scale.blue[9], -- Regex
205210
statement = pal.scale.red[6], -- Statements
206211
string = pal.scale.blue[8], -- Strings
207-
type = pal.scale.red[6], -- Types
212+
type = pl.syntax.variable, -- Types
208213
tag = pal.scale.green[6], -- Tags
209214
variable = spec.fg1, -- Variables
210215
}
@@ -242,4 +247,9 @@ local function generate_spec(pal)
242247
return spec
243248
end
244249

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

lua/github-theme/palette/github_light_colorblind.lua

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ local meta = {
55
light = true,
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 Light scale variables
914
---source: https://github.com/primer/primitives/blob/main/data/colors/themes/light_colorblind.ts
1015
-- stylua: ignore
@@ -193,18 +198,18 @@ local function generate_spec(pal)
193198
conditional = pal.scale.red[6], -- Conditional and loop
194199
const = pal.scale.blue[6], -- Constants, imports and booleans
195200
dep = pal.scale.red[8], -- Deprecated
196-
field = pal.scale.orange[8], -- Field
201+
field = pl.syntax.constant, -- Field
197202
func = pal.scale.purple[6], -- Functions and Titles
198203
ident = pal.scale.blue[9], -- Identifiers
199204
keyword = pal.scale.red[6], -- Keywords
200205
number = pal.scale.blue[7], -- Numbers
201-
operator = pal.scale.red[6], -- Operators
202-
param = pal.scale.orange[5], -- PreProc
206+
operator = pl.syntax.constant, -- Operators
207+
param = spec.fg1, -- Parameters
203208
preproc = pal.scale.red[6], -- PreProc
204209
regex = pal.scale.blue[9], -- Regex
205210
statement = pal.scale.red[6], -- Statements
206211
string = pal.scale.blue[8], -- Strings
207-
type = pal.scale.orange[5], -- Types
212+
type = pl.syntax.variable, -- Types
208213
tag = pal.scale.green[6], -- Tags
209214
variable = spec.fg1, -- Variables
210215
}
@@ -242,4 +247,9 @@ local function generate_spec(pal)
242247
return spec
243248
end
244249

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

0 commit comments

Comments
 (0)