Skip to content

Commit 4d74b52

Browse files
committed
refactor(syntax)!: reimplement the syntax highlighter
1 parent b2f566d commit 4d74b52

File tree

5 files changed

+72
-70
lines changed

5 files changed

+72
-70
lines changed

lua/catppuccin/groups/editor.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function M.get()
5050
PmenuThumb = { bg = C.overlay0 }, -- Popup menu: Thumb of the scrollbar.
5151
Question = { fg = C.blue }, -- |hit-enter| prompt and yes/no questions
5252
QuickFixLine = { bg = C.surface1, style = { "bold" } }, -- Current |quickfix| item in the quickfix window. Combined with |hl-CursorLine| when the cursor is there.
53-
Search = { bg = U.darken(C.sky, 0.30, C.base), fg = C.text }, -- Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out.
54-
IncSearch = { bg = U.darken(C.sky, 0.90, C.base), fg = C.mantle }, -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
53+
Search = { bg = C.surface1, fg = C.pink, style = { "bold" } }, -- Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out.
54+
IncSearch = { bg = C.pink, fg = C.surface1 }, -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
5555
CurSearch = { bg = C.red, fg = C.mantle }, -- 'cursearch' highlighting: highlights the current search you're on differently
5656
SpecialKey = { fg = C.text }, -- Unprintable characters: text displayed differently from what it really is. But not 'listchars' textspace. |hl-Whitespace|
5757
SpellBad = { sp = C.red, style = { "undercurl" } }, -- Word that is not recognized by the spellchecker. |spell| Combined with the highlighting used otherwise.

lua/catppuccin/groups/integrations/native_lsp.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function M.get()
77
local error = C.red
88
local warning = C.yellow
99
local info = C.sky
10-
local hint = C.teal
10+
local hint = C.rosewater
1111
local darkening_percentage = 0.095
1212

1313
return {

lua/catppuccin/groups/integrations/semantic_tokens.lua

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@ local M = {}
22

33
function M.get()
44
return {
5+
["@lsp.type.class"] = { link = "@type" },
56
["@lsp.type.comment"] = { link = "@comment" },
67
["@lsp.type.enum"] = { link = "@type" },
78
["@lsp.type.enumMember"] = { link = "@constant" },
89
["@lsp.type.escapeSequence"] = { link = "@string.escape" },
9-
["@lsp.type.formatSpecifier"] = { link = "@punctuation.special" },
10-
["@lsp.type.interface"] = { link = "@interface" },
10+
["@lsp.type.event"] = { link = "@event" },
11+
["@lsp.type.formatSpecifier"] = { link = "@string.special" },
12+
["@lsp.type.interface"] = { link = "@type" },
1113
["@lsp.type.keyword"] = { link = "@keyword" },
14+
["@lsp.type.modifier"] = { link = "@keyword" },
1215
["@lsp.type.namespace"] = { link = "@namespace" },
1316
["@lsp.type.operator"] = { link = "@operator" },
1417
["@lsp.type.parameter"] = { link = "@parameter" },
1518
["@lsp.type.property"] = { link = "@property" },
19+
["@lsp.type.property.cpp"] = { link = "@property.cpp" },
20+
["@lsp.type.regex"] = { link = "@string.regex" },
1621
["@lsp.type.selfKeyword"] = { link = "@variable.builtin" },
22+
["@lsp.type.struct"] = { link = "@type" },
1723
["@lsp.type.variable"] = {}, -- use treesitter styles for regular variables
18-
["@lsp.typemod.enum.defaultLibrary"] = { link = "@type.builtin" },
19-
["@lsp.typemod.enumMember.defaultLibrary"] = { link = "@constant.builtin" },
20-
["@lsp.typemod.function.defaultLibrary"] = { link = "@function.builtin" },
21-
["@lsp.typemod.keyword.async"] = { link = "@keyword.coroutine" },
22-
["@lsp.typemod.macro.defaultLibrary"] = { link = "@function.builtin" },
23-
["@lsp.typemod.method.defaultLibrary"] = { link = "@function.builtin" },
24+
["@lsp.typemod.enum.defaultLibrary"] = { link = "@type" },
25+
["@lsp.typemod.enumMember.defaultLibrary"] = { link = "@constant" },
26+
["@lsp.typemod.function.defaultLibrary"] = { link = "@function" },
27+
["@lsp.typemod.keyword.async"] = { link = "@keyword" },
28+
["@lsp.typemod.macro.defaultLibrary"] = { link = "@constant.macro" },
29+
["@lsp.typemod.method.defaultLibrary"] = { link = "@function" },
2430
["@lsp.typemod.operator.injected"] = { link = "@operator" },
2531
["@lsp.typemod.string.injected"] = { link = "@string" },
26-
["@lsp.typemod.type.defaultLibrary"] = { link = "@type.builtin" },
27-
["@lsp.typemod.variable.defaultLibrary"] = { link = "@variable.builtin" },
32+
["@lsp.typemod.type.defaultLibrary"] = { link = "@type" },
33+
["@lsp.typemod.variable.defaultLibrary"] = { link = "@variable" },
2834
["@lsp.typemod.variable.injected"] = { link = "@variable" },
2935
}
3036
end

lua/catppuccin/groups/integrations/treesitter.lua

+42-46
Original file line numberDiff line numberDiff line change
@@ -22,76 +22,72 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
2222
["@operator"] = { link = "Operator" }, -- For any operator: +, but also -> and * in C.
2323

2424
-- Punctuation
25-
["@punctuation.delimiter"] = { fg = C.overlay2 }, -- For delimiters ie: .
25+
["@punctuation.delimiter"] = { link = "Delimiter" }, -- For delimiters (e.g. `;` / `.` / `,`).
2626
["@punctuation.bracket"] = { fg = C.overlay2 }, -- For brackets and parenthesis.
27-
["@punctuation.special"] = { fg = C.sky, style = O.styles.operators or {} }, -- For special punctutation that does not fall in the catagories before.
27+
["@punctuation.special"] = { link = "Special" }, -- For special punctuation that does not fall in the categories before (e.g. `{}` in string interpolation).
2828

2929
-- Literals
3030
["@string"] = { link = "String" }, -- For strings.
3131
["@string.regex"] = { fg = C.peach, style = O.styles.strings or {} }, -- For regexes.
3232
["@string.escape"] = { fg = C.pink, style = O.styles.strings }, -- For escape characters within a string.
33-
["@string.special"] = { fg = C.blue }, -- other special strings (e.g. dates)
33+
["@string.special"] = { link = "Special" }, -- other special strings (e.g. dates)
3434

3535
["@character"] = { link = "Character" }, -- character literals
3636
["@character.special"] = { link = "SpecialChar" }, -- special characters (e.g. wildcards)
3737

3838
["@boolean"] = { link = "Boolean" }, -- For booleans.
3939
["@number"] = { link = "Number" }, -- For all numbers
40-
["@float"] = { link = "Number" }, -- For floats.
40+
["@float"] = { link = "Float" }, -- For floats.
4141

4242
-- Functions
4343
["@function"] = { link = "Function" }, -- For function (calls and definitions).
4444
["@function.builtin"] = { fg = C.peach, style = O.styles.functions or {} }, -- For builtin functions: table.insert in Lua.
45-
["@function.call"] = { link = "@function" }, -- function calls
46-
["@function.macro"] = { fg = C.teal, style = O.styles.functions or {} }, -- For macro defined functions (calls and definitions): each macro_rules in RusC.
47-
["@method"] = { fg = C.peach, style = O.styles.functions or {} }, -- For method calls and definitions.
48-
49-
["@method.call"] = { link = "@method" }, -- method calls
45+
["@function.call"] = { link = "Function" }, -- function calls
46+
["@function.macro"] = { link = "Constant" }, -- For macro defined functions (calls and definitions): each macro_rules in RusC.
47+
["@method"] = { link = "Function" }, -- For method definitions.
48+
["@method.call"] = { link = "Function" }, -- For method calls.
5049

5150
["@constructor"] = { fg = C.sapphire }, -- For constructor calls and definitions: = { } in Lua, and Java constructors.
52-
["@parameter"] = { fg = C.maroon, style = { "italic" } }, -- For parameters of a function.
51+
["@parameter"] = { fg = C.rosewater, style = { "italic" } }, -- For parameters of a function.
5352

5453
-- Keywords
5554
["@keyword"] = { link = "Keyword" }, -- For keywords that don't fall in previous categories.
56-
["@keyword.function"] = { fg = C.mauve, style = O.styles.keywords or {} }, -- For keywords used to define a function.
57-
["@keyword.operator"] = { fg = C.mauve, style = O.styles.operators or {} }, -- For new keyword operator
58-
["@keyword.return"] = { fg = C.mauve, style = O.styles.keywords or {} },
55+
["@keyword.function"] = { fg = C.maroon, style = O.styles.keywords or {} }, -- For keywords used to define a function.
56+
["@keyword.operator"] = { link = "Operator" }, -- For new keyword operator
57+
["@keyword.return"] = { fg = C.pink, style = O.styles.keywords or {} },
5958
-- JS & derivative
60-
["@keyword.export"] = { fg = C.sky, style = { "bold" } },
59+
["@keyword.export"] = { fg = C.sky, style = O.styles.keywords },
6160

6261
["@conditional"] = { link = "Conditional" }, -- For keywords related to conditionnals.
6362
["@repeat"] = { link = "Repeat" }, -- For keywords related to loops.
6463
-- @debug ; keywords related to debugging
6564
["@label"] = { link = "Label" }, -- For labels: label: in C and :label: in Lua.
6665
["@include"] = { link = "Include" }, -- For includes: #include in C, use or extern crate in Rust, or require in Lua.
67-
["@exception"] = { fg = C.mauve, style = O.styles.keywords or {} }, -- For exception related keywords.
66+
["@exception"] = { link = "Exception" }, -- For exception related keywords.
6867

6968
-- Types
70-
7169
["@type"] = { link = "Type" }, -- For types.
72-
["@type.builtin"] = { fg = C.yellow, style = O.styles.properties or "italic" }, -- For builtin types.
73-
["@type.definition"] = { link = "@type" }, -- type definitions (e.g. `typedef` in C)
74-
["@type.qualifier"] = { link = "@type" }, -- type qualifiers (e.g. `const`)
70+
["@type.builtin"] = { fg = C.yellow, style = O.styles.properties or { "italic" } }, -- For builtin types.
71+
["@type.definition"] = { link = "Type" }, -- type definitions (e.g. `typedef` in C)
72+
["@type.qualifier"] = { link = "Keyword" }, -- type qualifiers (e.g. `const`)
7573

7674
["@storageclass"] = { link = "StorageClass" }, -- visibility/life-time/etc. modifiers (e.g. `static`)
7775
["@attribute"] = { link = "Constant" }, -- attribute annotations (e.g. Python decorators)
78-
["@field"] = { fg = C.lavender }, -- For fields.
79-
["@property"] = { fg = C.lavender, style = O.styles.properties or {} }, -- Same as TSField.
76+
["@field"] = { fg = C.rosewater }, -- For fields.
77+
["@property"] = { fg = C.rosewater, style = O.styles.properties or {} }, -- Same as TSField.
8078

8179
-- Identifiers
80+
["@variable"] = { link = "Identifier" }, -- Any variable name that does not have another highlight.
81+
["@variable.builtin"] = { fg = C.red, style = O.styles.properties or {} }, -- Variable names that are defined by the languages, like this or self.
8282

83-
["@variable"] = { fg = C.text, style = O.styles.variables or {} }, -- Any variable name that does not have another highlight.
84-
["@variable.builtin"] = { fg = C.red }, -- Variable names that are defined by the languages, like this or self.
85-
86-
["@constant"] = { fg = C.peach }, -- For constants
87-
["@constant.builtin"] = { fg = C.peach, style = O.styles.keywords or {} }, -- For constant that are built in the language: nil in Lua.
83+
["@constant"] = { link = "Constant" }, -- For constants
84+
["@constant.builtin"] = { fg = C.lavender, style = O.styles.properties or {} }, -- For constant that are built in the language: nil in Lua.
8885
["@constant.macro"] = { link = "Macro" }, -- For constants that are defined by macros: NULL in C.
8986

90-
["@namespace"] = { fg = C.lavender, style = { "italic" } }, -- For identifiers referring to modules and namespaces.
87+
["@namespace"] = { fg = C.rosewater }, -- For identifiers referring to modules and namespaces.
9188
["@symbol"] = { fg = C.flamingo },
9289

9390
-- Text
94-
9591
["@text"] = { fg = C.text }, -- For strings considerated text in a markup language.
9692
["@text.strong"] = { fg = C.maroon, style = { "bold" } }, -- bold
9793
["@text.emphasis"] = { fg = C.maroon, style = { "italic" } }, -- italic
@@ -103,7 +99,7 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
10399
["@text.math"] = { fg = C.blue }, -- math environments (e.g. `$ ... $` in LaTeX)
104100
["@text.environment"] = { fg = C.pink }, -- text environments of markup languages
105101
["@text.environment.name"] = { fg = C.blue }, -- text indicating the type of an environment
106-
["@text.reference"] = { fg = C.lavender, style = { "bold" } }, -- references
102+
["@text.reference"] = { link = "Tag" }, -- text references, footnotes, citations, etc.
107103

108104
["@text.todo"] = { fg = C.base, bg = C.yellow }, -- todo notes
109105
["@text.todo.checked"] = { fg = C.green }, -- todo notes
@@ -120,19 +116,9 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
120116
["@tag.attribute"] = { fg = C.teal, style = { "italic" } }, -- Tags like html tag names.
121117
["@tag.delimiter"] = { fg = C.sky }, -- Tag delimiter like < > /
122118

123-
-- Semantic tokens
124-
["@class"] = { fg = C.blue },
125-
["@struct"] = { fg = C.blue },
126-
["@enum"] = { fg = C.teal },
127-
["@enumMember"] = { fg = C.flamingo },
128-
["@event"] = { fg = C.flamingo },
129-
["@interface"] = { fg = C.flamingo },
130-
["@modifier"] = { fg = C.flamingo },
131-
["@regexp"] = { fg = C.pink },
132-
["@typeParameter"] = { fg = C.yellow },
133-
["@decorator"] = { fg = C.flamingo },
134-
135119
-- Language specific:
120+
-- bash
121+
["@function.builtin.bash"] = { fg = C.red, style = { "italic" } },
136122

137123
-- css
138124
["@property.css"] = { fg = C.lavender },
@@ -143,35 +129,45 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
143129
["@string.plain.css"] = { fg = C.peach },
144130
["@number.css"] = { fg = C.peach },
145131

132+
-- java
133+
["@constant.java"] = { fg = C.teal },
134+
146135
-- toml
147136
["@property.toml"] = { fg = C.blue }, -- Differentiates between string and properties
148137

149138
-- json
150139
["@label.json"] = { fg = C.blue }, -- For labels: label: in C and :label: in Lua.
151140

152141
-- lua
153-
["@constructor.lua"] = { fg = C.flamingo }, -- For constructor calls and definitions: = { } in Lua, and Java constructors.
142+
["@constructor.lua"] = { fg = C.flamingo }, -- For constructor calls and definitions: = { } in Lua.
143+
["@field.lua"] = { fg = C.lavender },
154144

155145
-- typescript
146+
["@property.typescript"] = { fg = C.lavender, style = O.styles.properties or {} },
156147
["@constructor.typescript"] = { fg = C.lavender },
157148

158149
-- TSX (Typescript React)
159150
["@constructor.tsx"] = { fg = C.lavender },
160151
["@tag.attribute.tsx"] = { fg = C.mauve, style = { "italic" } },
161152

162-
-- cpp
163-
["@property.cpp"] = { fg = C.rosewater },
164-
165153
-- yaml
166154
["@field.yaml"] = { fg = C.blue }, -- For fields.
167155

168156
-- Ruby
169157
["@symbol.ruby"] = { fg = C.flamingo },
170158

171159
-- PHP
172-
["@type.qualifier.php"] = { link = "Keyword" }, -- type qualifiers (e.g. `const`)
173160
["@method.php"] = { link = "Function" },
174161
["@method.call.php"] = { link = "Function" },
162+
163+
-- C/CPP
164+
["@type.builtin.c"] = { style = {} },
165+
["@property.cpp"] = { fg = C.text },
166+
["@type.builtin.cpp"] = { style = {} },
167+
168+
-- Misc
169+
gitcommitSummary = { fg = C.rosewater, style = { "italic" } },
170+
zshKSHFunction = { link = "Function" },
175171
}
176172
end
177173

lua/catppuccin/groups/syntax.lua

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ function M.get()
88
String = { fg = C.green, style = O.styles.strings or {} }, -- a string constant: "this is a string"
99
Character = { fg = C.teal }, -- a character constant: 'c', '\n'
1010
Number = { fg = C.peach, style = O.styles.numbers or {} }, -- a number constant: 234, 0xff
11-
Float = { fg = C.peach, style = O.styles.numbers or {} }, -- a floating point constant: 2.3e10
11+
Float = { link = "Number" }, -- a floating point constant: 2.3e10
1212
Boolean = { fg = C.peach, style = O.styles.booleans or {} }, -- a boolean constant: TRUE, false
13-
Identifier = { fg = C.flamingo, style = O.styles.variables or {} }, -- (preferred) any variable name
13+
Identifier = { fg = C.text, style = O.styles.variables or {} }, -- (preferred) any variable name
1414
Function = { fg = C.blue, style = O.styles.functions or {} }, -- function name (also: methods for classes)
1515
Statement = { fg = C.mauve }, -- (preferred) any statement
1616
Conditional = { fg = C.mauve, style = O.styles.conditionals or {} }, -- if, then, else, endif, switch, etc.
1717
Repeat = { fg = C.mauve, style = O.styles.loops or {} }, -- for, do, while, etc.
18-
Label = { fg = C.sapphire }, -- case, default, etc.
18+
Label = { fg = C.rosewater }, -- case, default, etc.
1919
Operator = { fg = C.sky, style = O.styles.operators or {} }, -- "sizeof", "+", "*", etc.
20-
Keyword = { fg = C.mauve, style = O.styles.keywords or {} }, -- any other keyword
21-
-- Exception = { }, -- try, catch, throw
20+
Keyword = { fg = C.maroon, style = O.styles.keywords or {} }, -- any other keyword
21+
Exception = { fg = C.peach, style = O.styles.keywords or {} }, -- try, catch, throw
2222

2323
PreProc = { fg = C.pink }, -- (preferred) generic Preprocessor
24-
Include = { fg = C.mauve, style = O.styles.keywords or {} }, -- preprocessor #include
24+
Include = { fg = C.teal, style = O.styles.keywords or {} }, -- preprocessor #include
2525
Define = { link = "PreProc" }, -- preprocessor #define
26-
Macro = { fg = C.mauve }, -- same as Define
26+
Macro = { link = "Constant" }, -- same as Define
2727
PreCondit = { link = "PreProc" }, -- preprocessor #if, #else, #endif, etc.
2828

29-
StorageClass = { fg = C.yellow }, -- static, register, volatile, etc.
30-
Structure = { fg = C.yellow }, -- struct, union, enum, etc.
29+
StorageClass = { link = "Keyword" }, -- static, register, volatile, etc.
30+
Structure = { link = "Keyword" }, -- struct, union, enum, etc.
3131
Special = { fg = C.pink }, -- (preferred) any special symbol
3232
Type = { fg = C.yellow, style = O.styles.types or {} }, -- (preferred) int, long, char, etc.
3333
Typedef = { link = "Type" }, -- A typedef
3434
SpecialChar = { link = "Special" }, -- special character in a constant
35-
Tag = { link = "Special" }, -- you can use CTRL-] on this
36-
Delimiter = { link = "Special" }, -- character that needs attention
35+
Tag = { fg = C.lavender, style = { "bold" } }, -- you can use CTRL-] on this
36+
Delimiter = { fg = C.teal }, -- delimiters (e.g. `;` / `.` / `,`)
3737
Debug = { link = "Special" }, -- debugging statements
3838

3939
Underlined = { style = { "underline" } }, -- (preferred) text that stands out, HTML links

0 commit comments

Comments
 (0)