Skip to content

Commit

Permalink
Merge pull request #259 from tmillr/fix-incorrect-highlights
Browse files Browse the repository at this point in the history
fix: incorrect syntax highlighting
  • Loading branch information
ful1e5 committed Jun 18, 2023
2 parents 464ff89 + cb601d8 commit 777851c
Show file tree
Hide file tree
Showing 19 changed files with 617 additions and 392 deletions.
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
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ require('github-theme').setup({
dim_inactive = false, -- Non focused panes set to alternative background
module_default = true, -- Default enable value for modules
styles = { -- Style to be applied to different syntax groups
comments = 'italic', -- Value is any valid attr-list value `:help attr-list`
comments = 'NONE', -- Value is any valid attr-list value `:help attr-list`
functions = 'NONE',
keywords = 'italic',
keywords = 'NONE',
variables = 'NONE',
conditionals = 'NONE',
constants = 'NONE',
Expand Down Expand Up @@ -263,15 +263,13 @@ require('github-theme').setup({
vim.cmd('colorscheme github_dark')
```

If you would like to change any of the default options above you only have to define the options that change. If an
option is not present in your options table the default option will be used. For example if changing the styles of
certain syntax is the only desired change then your options table would look like:
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:

```lua
require('github-theme').setup({
options = {
styles = {
comments = 'NONE',
comments = 'italic',
keywords = 'bold',
types = 'italic,bold',
}
Expand Down Expand Up @@ -303,14 +301,11 @@ local palettes = {
all = {
-- Each palette defines these colors:
-- black, gray, blue, green, magenta, pink, red, white, yellow, cyan

--
-- These colors have 2 shades: base, and bright
--
-- Defining just a color defines it's base color
red = {
base = '#ff0000'
},

-- Passing a string sets the base
red = '#ff0000',
},
github_dark = {
-- Defining multiple shades is done by passing a table
Expand Down Expand Up @@ -371,7 +366,7 @@ local specs = {
}

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

## Syntax highlight groups

This section will help you determine what highlight group is being applied to a piece of syntax. These sections will
output the highlight group for the value under the cursor.
This section will help you determine what highlight group is being applied to a piece of syntax. These methods
show which highlight group(s) is in use at the current screen position of the cursor (under the cursor).

> **Note** On Neovim v0.9.0 and later, you can use the command `:Inspect`, or the Lua function `vim.show_pos()`.
#### Treesitter highlighting

Expand Down
2 changes: 1 addition & 1 deletion Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Current list of modules are:
### Neovim specific modules

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
are liked to by other modules. This also means that they will still be enabled when setting `module_default` to `false`.
are linked to by other modules. This also means that they will still be enabled when setting `module_default` to `false`.

### Extended modules

Expand Down
2 changes: 1 addition & 1 deletion doc/github-nvim-theme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ NEOVIM SPECIFIC MODULES ~

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 are liked to by other modules. This also means that they will
experience and are linked to by other modules. This also means that they will
still be enabled when setting `module_default` to `false`.


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,
}
Loading

0 comments on commit 777851c

Please sign in to comment.