Skip to content

Commit 1e0dbb4

Browse files
authored
feat(treesitter): follow upstream highlight groups (#404)
with fallback highlight groups.
1 parent c114096 commit 1e0dbb4

File tree

1 file changed

+190
-112
lines changed

1 file changed

+190
-112
lines changed

lua/nightfox/group/modules/treesitter.lua

+190-112
Original file line numberDiff line numberDiff line change
@@ -5,129 +5,207 @@ function M.get(spec, config, opts)
55
local stl = config.styles
66
local P = spec.palette
77

8-
if vim.treesitter.highlighter.hl_map then
9-
require("nightfox.lib.log").warn([[nvim-treesitter integration requires neovim 0.8
10-
If you want to stay on nvim 0.7, disable the module, or pin to commit 15f3b5837a8d07f45cbe16753fbf13630bc167a3
11-
]])
12-
return {}
13-
end
14-
15-
-- stylua: ignore
16-
return {
17-
-- Misc
18-
["@comment"] = { link = "Comment" },
19-
["@error"] = { link = "Error" },
20-
["@preproc"] = { link = "PreProc" }, -- various preprocessor directives & shebangs
21-
["@define"] = { link = "Define" }, -- preprocessor definition directives
22-
["@operator"] = { link = "Operator" }, -- For any operator: +, but also -> and * in C.
23-
24-
-- Punctuation
25-
["@punctuation.delimiter"] = { fg = syn.bracket }, -- For delimiters ie: .
26-
["@punctuation.bracket"] = { fg = syn.bracket }, -- For brackets and parenthesis.
27-
["@punctuation.special"] = { fg = syn.builtin1, style = stl.operators }, -- For special punctutation that does not fall in the catagories before.
28-
29-
-- Literals
30-
["@string"] = { link = "String" }, -- For strings.
31-
["@string.regex"] = { fg = syn.regex, style = stl.strings }, -- Regular expression literals.
32-
["@string.escape"] = { fg = syn.regex, style = "bold" }, -- Escape characters within a string: `\n`, `\t`, etc.
33-
["@string.special"] = { link = "Special" }, -- other special strings (e.g. dates)
34-
35-
["@character"] = { link = "Character" }, -- character literals
36-
["@character.special"] = { link = "SpecialChar" }, -- special characters (e.g. wildcards)
37-
38-
["@boolean"] = { link = "Boolean" }, -- For booleans.
39-
["@number"] = { link = "Number" }, -- For all numbers
40-
["@float"] = { link = "Number" }, -- For floats.
41-
42-
-- Functions
43-
["@function"] = { link = "Function" }, -- For function (calls and definitions).
44-
["@function.builtin"] = { fg = syn.builtin0, style = stl.functions }, -- For builtin functions: table.insert in Lua.
45-
["@function.call"] = { link = "@function" }, -- function calls
46-
["@function.macro"] = { fg = syn.builtin0, style = stl.functions }, -- For macro defined functions (calls and definitions): each macro_rules in RusC.
47-
["@method"] = { link = "@function"}, -- For method calls and definitions.
48-
49-
["@method.call"] = { link = "@method" }, -- method calls
50-
51-
["@constructor"] = { fg = syn.ident }, -- For constructor calls and definitions: = { } in Lua, and Java constructors.
52-
["@parameter"] = { fg = syn.builtin1, stl.variables }, -- For parameters of a function.
53-
54-
-- Keywords
55-
["@keyword"] = { link = "Keyword" }, -- For keywords that don't fall in previous categories.
56-
["@keyword.function"] = { fg = syn.keyword, style = stl.functions }, -- Keywords used to define a function: `function` in Lua, `def` and `lambda` in Python.
57-
["@keyword.operator"] = { fg = syn.operator, style = stl.operators }, -- For new keyword operator
58-
["@keyword.return"] = { fg = syn.builtin0, style = stl.keywords },
59-
60-
["@conditional"] = { link = "Conditional" }, -- For keywords related to conditionnals.
61-
["@repeat"] = { link = "Repeat" }, -- For keywords related to loops.
62-
["@label"] = { link = "Label" }, -- For labels: label: in C and :label: in Lua.
63-
["@include"] = { link = "Include" }, -- For includes: #include in C, use or extern crate in Rust, or require in Lua.
64-
["@exception"] = { fg = syn.builtin0, style = stl.keywords }, -- Exception related keywords: `try`, `except`, `finally` in Python.
65-
66-
-- Types
67-
["@type"] = { link = "Type" }, -- For types.
68-
["@type.builtin"] = { fg = syn.builtin1, style = stl.types }, -- For builtin types.
69-
["@type.definition"] = { link = "@type" }, -- type definitions (e.g. `typedef` in C)
70-
["@type.qualifier"] = { link = "@type" }, -- type qualifiers (e.g. `const`)
71-
72-
["@storageclass"] = { link = "StorageClass" }, -- visibility/life-time/etc. modifiers (e.g. `static`)
73-
["@attribute"] = { link = "Constant" }, -- attribute annotations (e.g. Python decorators)
74-
["@field"] = { fg = syn.field }, -- For fields.
75-
["@property"] = { link = "@field" }, -- Same as @field.
76-
77-
-- Identifiers
78-
["@variable"] = { fg = syn.variable, style = stl.variables }, -- Any variable name that does not have another highlighC.
79-
["@variable.builtin"] = { fg = syn.builtin0, style = stl.variables }, -- Variable names that are defined by the languages, like this or self.
80-
81-
["@constant"] = { link = "Constant" }, -- For constants
82-
["@constant.builtin"] = { fg = syn.builtin2, style = stl.keywords }, -- For constant that are built in the language: nil in Lua.
83-
["@constant.macro"] = { link = "Macro" }, -- For constants that are defined by macros: NULL in C.
84-
85-
["@namespace"] = { fg = syn.builtin1, }, -- For identifiers referring to modules and namespaces.
86-
["@symbol"] = { fg = syn.preproc },
87-
88-
-- Text
89-
["@text"] = { fg = spec.fg1 }, -- For strings considerated text in a markup language.
90-
["@text.strong"] = { fg = P.red:subtle(), style = "bold" }, -- bold
91-
["@text.emphasis"] = { fg = P.red:subtle(), style = "italic" }, -- italic
92-
["@text.underline"] = { link = "Underline" }, -- underlined text
93-
["@text.strike"] = { fg = spec.fg1, style = "strikethrough" }, -- strikethrough text
94-
["@text.title"] = { link = "Title"}, -- titles like: # Example
95-
["@text.literal"] = { fg = syn.ident, style = "italic" }, -- used for inline code in markdown and for doc in python (""")
96-
["@text.uri"] = { fg = syn.const, style = "italic,underline" }, -- urls, links and emails
97-
["@text.math"] = { fg = syn.func }, -- math environments (e.g. `$ ... $` in LaTeX)
98-
["@text.environment"] = { fg = syn.preproc }, -- text environments of markup languages
99-
["@text.environment.name"] = { fg = syn.func }, -- text indicating the type of an environment
100-
["@text.reference"] = { fg = syn.keyword, style = "bold" }, -- references
101-
102-
["@text.todo"] = { fg = spec.bg1, bg = spec.diag.hint }, -- todo notes
103-
["@text.note"] = { fg = spec.bg1, bg = spec.diag.info },
104-
["@text.warning"] = { fg = spec.bg1, bg = spec.diag.warn },
105-
["@text.danger"] = { fg = spec.bg1, bg = spec.diag.error },
106-
["@text.todo.unchecked"] = { fg = spec.fg3 }, -- For brackets and parens.
107-
["@text.todo.checked"] = { fg = P.green.base }, -- For brackets and parens.
108-
109-
["@text.diff.add"] = { link = "diffAdded" }, -- added text (for diff files)
110-
["@text.diff.delete"] = { link = "diffRemoved" }, -- deleted text (for diff files)
111-
112-
-- Tags
113-
["@tag"] = { fg = syn.keyword }, -- Tags like html tag names.
114-
["@tag.attribute"] = { fg = syn.func, style = "italic" }, -- Tags like html tag names.
115-
["@tag.delimiter"] = { fg = syn.builtin1 }, -- Tag delimiter like < > /
8+
local hl = {
9+
-- Identifiers ------------------------------------------------------------
10+
["@variable"] = { syn.variable, style = stl.variables }, -- various variable names
11+
["@variable.builtin"] = { fg = syn.builtin0, style = stl.variables }, -- built-in variable names (e.g. `this`)
12+
["@variable.parameter"] = { fg = syn.builtin1, stl.variables }, -- parameters of a function
13+
["@variable.member"] = { fg = syn.field }, -- object and struct fields
14+
15+
["@constant"] = { link = "Constant" }, -- constant identifiers
16+
["@constant.builtin"] = { fg = syn.builtin2, style = stl.keywords }, -- built-in constant values
17+
["@constant.macro"] = { link = "Macro" }, -- constants defined by the preprocessor
18+
19+
["@module"] = { fg = syn.builtin1 }, -- modules or namespaces
20+
-- ["@module.builtin"] = { }, -- built-in modules or namespaces
21+
["@label"] = { link = "Label" }, -- GOTO and other labels (e.g. `label:` in C), including heredoc labels
22+
23+
-- Literals ---------------------------------------------------------------
24+
["@string"] = { link = "String" }, -- string literals
25+
-- ["@string.documentation"] = { }, -- string documenting code (e.g. Python docstrings)
26+
["@string.regexp"] = { fg = syn.regex, style = stl.strings }, -- regular expressions
27+
["@string.escape"] = { fg = syn.regex, style = "bold" }, -- escape sequences
28+
["@string.special"] = { link = "Special" }, -- other special strings (e.g. dates)
29+
-- ["@string.special.symbol"] = { }, -- symbols or atoms
30+
["@string.special.url"] = { fg = syn.const, style = "italic,underline" }, -- URIs (e.g. hyperlinks)
31+
-- ["@string.special.path"] = { }, -- filenames
32+
33+
["@character"] = { link = "Character" }, -- character literals
34+
["@character.special"] = { link = "SpecialChar" }, -- special characters (e.g. wildcards)
35+
36+
["@boolean"] = { link = "Boolean" }, -- boolean literals
37+
["@number"] = { link = "Number" }, -- numeric literals
38+
["@number.float"] = { link = "Float" }, -- floating-point number literals
39+
40+
-- Types ------------------------------------------------------------------
41+
["@type"] = { link = "Type" }, -- type or class definitions and annotations
42+
["@type.builtin"] = { fg = syn.builtin1, style = stl.types }, -- built-in types
43+
-- ["@type.definition"] = { }, -- identifiers in type definitions (e.g. `typedef <type> <identifier>` in C)
44+
-- ["@type.qualifier"] = { }, -- type qualifiers (e.g. `const`)
45+
46+
["@attribute"] = { link = "Constant" }, -- attribute annotations (e.g. Python decorators)
47+
["@property"] = { fg = syn.field }, -- the key in key/value pairs
48+
49+
-- Functions --------------------------------------------------------------
50+
["@function"] = { link = "Functions" }, -- function definitions
51+
["@function.builtin"] = { fg = syn.builtin0, style = stl.functions }, -- built-in functions
52+
-- ["@function.call"] = { }, -- function calls
53+
["@function.macro"] = { fg = syn.builtin0, style = stl.functions }, -- preprocessor macros
54+
55+
-- ["@function.method"] = { }, -- method definitions
56+
-- ["@function.method.call"] = { }, -- method calls
57+
58+
["@constructor"] = { fg = syn.ident }, -- constructor calls and definitions
59+
["@operator"] = { fg = syn.builtin1, stl.variables }, -- symbolic operators (e.g. `+` / `*`)
60+
61+
-- Keywords ---------------------------------------------------------------
62+
["@keyword"] = { link = "Keyword" }, -- keywords not fitting into specific categories
63+
-- ["@keyword.coroutine"] = { }, -- keywords related to coroutines (e.g. `go` in Go, `async/await` in Python)
64+
["@keyword.function"] = { fg = syn.keyword, style = stl.functions }, -- keywords that define a function (e.g. `func` in Go, `def` in Python)
65+
["@keyword.operator"] = { fg = syn.operator, style = stl.operators }, -- operators that are English words (e.g. `and` / `or`)
66+
["@keyword.import"] = { link = "Include" }, -- keywords for including modules (e.g. `import` / `from` in Python)
67+
["@keyword.storage"] = { link = "StorageClass" }, -- modifiers that affect storage in memory or life-time
68+
["@keyword.repeat"] = { link = "Repeat" }, -- keywords related to loops (e.g. `for` / `while`)
69+
["@keyword.return"] = { fg = syn.builtin0, style = stl.keywords }, -- keywords like `return` and `yield`
70+
-- ["@keyword.debug"] = { }, -- keywords related to debugging
71+
["@keyword.exception"] = { link = "Exception" }, -- keywords related to exceptions (e.g. `throw` / `catch`)
72+
73+
["@keyword.conditional"] = { link = "Conditional" }, -- keywords related to conditionals (e.g. `if` / `else`)
74+
["@keyword.conditional.ternary"] = { link = "Conditional" }, -- ternary operator (e.g. `?` / `:`)
75+
76+
-- ["@keyword.directive"] = { }, -- various preprocessor directives & shebangs
77+
-- ["@keyword.directive.define"] = { }, -- preprocessor definition directives
78+
79+
-- Punctuation ------------------------------------------------------------
80+
["@punctuation.delimiter"] = { fg = syn.bracket }, -- delimiters (e.g. `;` / `.` / `,`)
81+
["@punctuation.bracket"] = { fg = syn.bracket }, -- brackets (e.g. `()` / `{}` / `[]`)
82+
["@punctuation.special"] = { fg = syn.builtin1, style = stl.operators }, -- special symbols (e.g. `{}` in string interpolation)
83+
84+
-- Comments ---------------------------------------------------------------
85+
["@comment"] = { link = "Comment" }, -- line and block comments
86+
-- ["@comment.documentation"] = { link = "" }, -- comments documenting code
87+
88+
["@comment.error"] = { fg = spec.bg1, bg = spec.diag.error }, -- error-type comments (e.g. `ERROR`, `FIXME`, `DEPRECATED:`)
89+
["@comment.warning"] = { fg = spec.bg1, bg = spec.diag.warn }, -- warning-type comments (e.g. `WARNING:`, `FIX:`, `HACK:`)
90+
["@comment.todo"] = { fg = spec.bg1, bg = spec.diag.hint }, -- todo-type comments (e.g. `TODO:`, `WIP:`, `FIXME:`)
91+
["@comment.note"] = { fg = spec.bg1, bg = spec.diag.info }, -- note-type comments (e.g. `NOTE:`, `INFO:`, `XXX`)
92+
93+
-- Markup -----------------------------------------------------------------
94+
["@markup"] = { fg = spec.fg1 }, -- For strings considerated text in a markup language.
95+
["@markup.strong"] = { fg = P.red:subtle(), style = "bold" }, -- bold text
96+
["@markup.italic"] = { link = "" }, -- italic text
97+
["@markup.strikethrough"] = { fg = spec.fg1, style = "strikethrough" }, -- struck-through text
98+
["@markup.underline"] = { link = "Underline" }, -- underlined text (only for literal underline markup!)
99+
100+
["@markup.heading"] = { link = "Title" }, -- headings, titles (including markers)
101+
102+
-- ["@markup.quote"] = { }, -- block quotes
103+
-- ["@markup.math"] = { }, -- math environments (e.g. `$ ... $` in LaTeX)
104+
-- ["@markup.environment"] = { }, -- environments (e.g. in LaTeX)
105+
106+
-- ["@markup.link"] = { }, -- text references, footnotes, citations, etc.
107+
-- ["@markup.link.label"] = { }, -- link, reference descriptions
108+
-- ["@markup.link.url"] = { }, -- URL-style links
109+
110+
-- ["@markup.raw"] = { link = "" }, -- literal or verbatim text (e.g. inline code)
111+
-- ["@markup.raw.block"] = { link = "" }, -- literal or verbatim text as a stand-alone block (use priority 90 for blocks with injections)
112+
113+
-- ["@markup.list"] = { link = "" }, -- list markers
114+
-- ["@markup.list.checked"] = { link = "" }, -- checked todo-style list markers
115+
-- ["@markup.list.unchecked"] = { link = "" }, -- unchecked todo-style list markers
116+
117+
["@diff.plus"] = { link = "diffAdded" }, -- added text (for diff files)
118+
["@diff.minus"] = { link = "diffRemoved" }, -- deleted text (for diff files)
119+
["@diff.delta"] = { link = "diffChanged" }, -- changed text (for diff files)
120+
121+
["@tag"] = { fg = syn.keyword }, -- XML-style tag names (and similar)
122+
["@tag.attribute"] = { fg = syn.func, style = "italic" }, -- XML-style tag attributes
123+
["@tag.delimiter"] = { fg = syn.builtin1 }, -- XML-style tag delimiters
124+
125+
-- Misc -------------------------------------------------------------------
126+
-- ["@none"] = { }, -- completely disable the highlight
127+
-- ["@conceal"] = { }, -- captures that are only meant to be concealed
128+
129+
-- ["@spell"] = { }, -- for defining regions to be spellchecked
130+
-- ["@nospell"] = { }, -- for defining regions that should NOT be spellchecked
116131

117132
-- Language specific -------------------------------------------------------
118133

119134
-- json
120-
["@label.json"] = { fg = syn.func }, -- For labels: label: in C and :label: in Lua.
135+
["@label.json"] = { fg = syn.func }, -- For labels: label: in C and :label: in Lua.
121136

122137
-- lua
123-
["@constructor.lua"] = { fg = spec.fg2 }, -- For constructor calls and definitions: = { } in Lua, and Java constructors.
138+
["@constructor.lua"] = { fg = spec.fg2 }, -- Lua's constructor is { }
124139

125140
-- rust
126-
["@field.rust"] = { fg = spec.fg2 },
141+
["@field.rust"] = { fg = spec.fg2 },
127142

128143
-- yaml
129-
["@field.yaml"] = { fg = syn.func }, -- For fields.
144+
["@variable.member.yaml"] = { fg = syn.func }, -- For fields.
130145
}
146+
147+
-- Legacy highlights
148+
hl["@parameter"] = hl["@variable.parameter"]
149+
hl["@field"] = hl["@variable.member"]
150+
hl["@namespace"] = hl["@module"]
151+
hl["@float"] = hl["@number.float"]
152+
hl["@symbol"] = hl["@string.special.symbol"]
153+
hl["@string.regex"] = hl["@string.regexp"]
154+
155+
hl["@text"] = hl["@markup"]
156+
hl["@text.strong"] = hl["@markup.strong"]
157+
hl["@text.emphasis"] = hl["@markup.italic"]
158+
hl["@text.underline"] = hl["@markup.underline"]
159+
hl["@text.strike"] = hl["@markup.strikethrough"]
160+
hl["@text.uri"] = hl["@markup.link.url"]
161+
hl["@text.math"] = hl["@markup.math"]
162+
hl["@text.environment"] = hl["@markup.environment"]
163+
hl["@text.environment.name"] = hl["@markup.environment.name"]
164+
165+
hl["@text.title"] = hl["@markup.heading"]
166+
hl["@text.literal"] = hl["@markup.raw"]
167+
hl["@text.reference"] = hl["@markup.link"]
168+
169+
hl["@text.todo.checked"] = hl["@markup.list.checked"]
170+
hl["@text.todo.unchecked"] = hl["@markup.list.unchecked"]
171+
172+
hl["@comment.note"] = hl["@comment.hint"]
173+
174+
-- @text.todo is now for todo comments, not todo notes like in markdown
175+
hl["@text.todo"] = hl["@comment.todo"]
176+
hl["@text.warning"] = hl["@comment.warning"]
177+
hl["@text.note"] = hl["@comment.note"]
178+
hl["@text.danger"] = hl["@comment.error"]
179+
180+
-- @text.uri is now
181+
-- > @markup.link.url in markup links
182+
-- > @string.special.url outside of markup
183+
hl["@text.uri"] = hl["@markup.link.uri"]
184+
185+
hl["@method"] = hl["@function.method"]
186+
hl["@method.call"] = hl["@function.method.call"]
187+
188+
hl["@text.diff.add"] = hl["@diff.plus"]
189+
hl["@text.diff.delete"] = hl["@diff.minus"]
190+
191+
hl["@define"] = hl["@keyword.directive.define"]
192+
hl["@preproc"] = hl["@keyword.directive"]
193+
hl["@storageclass"] = hl["@keyword.storage"]
194+
hl["@conditional"] = hl["@keyword.conditional"]
195+
hl["@exception"] = hl["@keyword.exception"]
196+
hl["@include"] = hl["@keyword.import"]
197+
hl["@repeat"] = hl["@keyword.repeat"]
198+
199+
hl["@variable.member.yaml"] = hl["@field.yaml"]
200+
201+
hl["@text.title.1.markdown"] = hl["@markup.heading.1.markdown"]
202+
hl["@text.title.2.markdown"] = hl["@markup.heading.2.markdown"]
203+
hl["@text.title.3.markdown"] = hl["@markup.heading.3.markdown"]
204+
hl["@text.title.4.markdown"] = hl["@markup.heading.4.markdown"]
205+
hl["@text.title.5.markdown"] = hl["@markup.heading.5.markdown"]
206+
hl["@text.title.6.markdown"] = hl["@markup.heading.6.markdown"]
207+
208+
return hl
131209
end
132210

133211
return M

0 commit comments

Comments
 (0)