Skip to content

Commit

Permalink
refactor(syntax)!: reimplement the syntax highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jint-lzxy committed Jul 17, 2023
1 parent bfe91df commit 1f76a94
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 58 deletions.
4 changes: 2 additions & 2 deletions lua/catppuccin/groups/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function M.get()
PmenuThumb = { bg = C.overlay0 }, -- Popup menu: Thumb of the scrollbar.
Question = { fg = C.blue }, -- |hit-enter| prompt and yes/no questions
QuickFixLine = { bg = C.surface1, style = { "bold" } }, -- Current |quickfix| item in the quickfix window. Combined with |hl-CursorLine| when the cursor is there.
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.
IncSearch = { bg = U.darken(C.sky, 0.90, C.base), fg = C.mantle }, -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
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.
IncSearch = { bg = C.pink, fg = C.surface1 }, -- 'incsearch' highlighting; also used for the text replaced with ":s///c"
CurSearch = { bg = C.red, fg = C.mantle }, -- 'cursearch' highlighting: highlights the current search you're on differently
SpecialKey = { link = "NonText" }, -- Unprintable characters: text displayed differently from what it really is. But not 'listchars' textspace. |hl-Whitespace|
SpellBad = { sp = C.red, style = { "undercurl" } }, -- Word that is not recognized by the spellchecker. |spell| Combined with the highlighting used otherwise.
Expand Down
2 changes: 1 addition & 1 deletion lua/catppuccin/groups/integrations/native_lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function M.get()
local error = C.red
local warning = C.yellow
local info = C.sky
local hint = C.teal
local hint = C.rosewater
local darkening_percentage = 0.095

return {
Expand Down
32 changes: 17 additions & 15 deletions lua/catppuccin/groups/integrations/semantic_tokens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,37 @@ If you want to stay on nvim 0.7, disable the integration.
return {}
end
return {
["@lsp.type.boolean"] = { link = "@boolean" },
["@lsp.type.builtinType"] = { link = "@type.builtin" },
["@lsp.type.class"] = { link = "@type" },
["@lsp.type.comment"] = { link = "@comment" },
["@lsp.type.enum"] = { link = "@type" },
["@lsp.type.enumMember"] = { link = "@constant" },
["@lsp.type.escapeSequence"] = { link = "@string.escape" },
["@lsp.type.formatSpecifier"] = { link = "@punctuation.special" },
["@lsp.type.interface"] = { fg = C.flamingo },
["@lsp.type.event"] = { link = "@event" },
["@lsp.type.formatSpecifier"] = { link = "@string.special" },
["@lsp.type.interface"] = { link = "@type" },
["@lsp.type.keyword"] = { link = "@keyword" },
["@lsp.type.modifier"] = { link = "@keyword" },
["@lsp.type.namespace"] = { link = "@namespace" },
["@lsp.type.number"] = { link = "@number" },
["@lsp.type.operator"] = { link = "@operator" },
["@lsp.type.parameter"] = { link = "@parameter" },
["@lsp.type.property"] = { link = "@property" },
["@lsp.type.property.cpp"] = { link = "@property.cpp" },
["@lsp.type.regex"] = { link = "@string.regex" },
["@lsp.type.selfKeyword"] = { link = "@variable.builtin" },
["@lsp.type.typeAlias"] = { link = "@type.definition" },
["@lsp.type.unresolvedReference"] = { link = "@error" },
["@lsp.type.struct"] = { link = "@type" },
["@lsp.type.typeParameter.cpp"] = { link = "@parameter" },
["@lsp.type.variable"] = {}, -- use treesitter styles for regular variables
["@lsp.typemod.class.defaultLibrary"] = { link = "@type.builtin" },
["@lsp.typemod.enum.defaultLibrary"] = { link = "@type.builtin" },
["@lsp.typemod.enumMember.defaultLibrary"] = { link = "@constant.builtin" },
["@lsp.typemod.function.defaultLibrary"] = { link = "@function.builtin" },
["@lsp.typemod.keyword.async"] = { link = "@keyword.coroutine" },
["@lsp.typemod.macro.defaultLibrary"] = { link = "@function.builtin" },
["@lsp.typemod.method.defaultLibrary"] = { link = "@function.builtin" },
["@lsp.typemod.enum.defaultLibrary"] = { link = "@type" },
["@lsp.typemod.enumMember.defaultLibrary"] = { link = "@constant" },
["@lsp.typemod.function.defaultLibrary"] = { link = "@function" },
["@lsp.typemod.keyword.async"] = { link = "@keyword" },
["@lsp.typemod.macro.defaultLibrary"] = { link = "@constant.macro" },
["@lsp.typemod.method.defaultLibrary"] = { link = "@function" },
["@lsp.typemod.operator.injected"] = { link = "@operator" },
["@lsp.typemod.string.injected"] = { link = "@string" },
["@lsp.typemod.type.defaultLibrary"] = { link = "@type.builtin" },
["@lsp.typemod.variable.defaultLibrary"] = { link = "@variable.builtin" },
["@lsp.typemod.type.defaultLibrary"] = { link = "@type" },
["@lsp.typemod.variable.defaultLibrary"] = { link = "@variable" },
["@lsp.typemod.variable.injected"] = { link = "@variable" },
}
end
Expand Down
66 changes: 37 additions & 29 deletions lua/catppuccin/groups/integrations/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
["@operator"] = { link = "Operator" }, -- For any operator: +, but also -> and * in C.

-- Punctuation
["@punctuation.delimiter"] = { link = "Delimiter" }, -- For delimiters ie: .
["@punctuation.delimiter"] = { link = "Delimiter" }, -- For delimiters (e.g. `;` / `.` / `,`).
["@punctuation.bracket"] = { fg = C.overlay2 }, -- For brackets and parenthesis.
["@punctuation.special"] = { link = "Special" }, -- For special punctutation that does not fall in the categories before.
["@punctuation.special"] = { link = "Special" }, -- For special punctuation that does not fall in the categories before (e.g. `{}` in string interpolation).

-- Literals
["@string"] = { link = "String" }, -- For strings.
Expand All @@ -43,21 +43,20 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
["@function"] = { link = "Function" }, -- For function (calls and definitions).
["@function.builtin"] = { fg = C.peach, style = O.styles.functions or {} }, -- For builtin functions: table.insert in Lua.
["@function.call"] = { link = "Function" }, -- function calls
["@function.macro"] = { fg = C.teal, style = O.styles.functions or {} }, -- For macro defined functions (calls and definitions): each macro_rules in RusC.
["@method"] = { link = "Function" }, -- For method calls and definitions.

["@method.call"] = { link = "Function" }, -- method calls
["@function.macro"] = { link = "Constant" }, -- For macro defined functions (calls and definitions): each macro_rules in RusC.
["@method"] = { link = "Function" }, -- For method definitions.
["@method.call"] = { link = "Function" }, -- For method calls.

["@constructor"] = { fg = C.sapphire }, -- For constructor calls and definitions: = { } in Lua, and Java constructors.
["@parameter"] = { fg = C.maroon, style = { "italic" } }, -- For parameters of a function.
["@parameter"] = { fg = C.rosewater, style = O.styles.variables or {} }, -- For parameters of a function.

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

["@conditional"] = { link = "Conditional" }, -- For keywords related to conditionnals.
["@repeat"] = { link = "Repeat" }, -- For keywords related to loops.
Expand All @@ -67,31 +66,28 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
["@exception"] = { link = "Exception" }, -- For exception related keywords.

-- Types

["@type"] = { link = "Type" }, -- For types.
["@type.builtin"] = { fg = C.yellow, style = O.styles.properties or "italic" }, -- For builtin types.
["@type.definition"] = { link = "@type" }, -- type definitions (e.g. `typedef` in C)
["@type.qualifier"] = { link = "@type" }, -- type qualifiers (e.g. `const`)
["@type.builtin"] = { fg = C.yellow, style = O.styles.properties or { "italic" } }, -- For builtin types.
["@type.definition"] = { link = "Type" }, -- type definitions (e.g. `typedef` in C)
["@type.qualifier"] = { link = "Keyword" }, -- type qualifiers (e.g. `const`)

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

-- Identifiers

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

["@constant"] = { link = "Constant" }, -- For constants
["@constant.builtin"] = { fg = C.peach, style = O.styles.keywords or {} }, -- For constant that are built in the language: nil in Lua.
["@constant.builtin"] = { fg = C.lavender, style = O.styles.properties or {} }, -- For constant that are built in the language: nil in Lua.
["@constant.macro"] = { link = "Macro" }, -- For constants that are defined by macros: NULL in C.

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

-- Text

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

["@text.todo"] = { fg = C.base, bg = C.yellow }, -- todo notes
["@text.todo.checked"] = { fg = C.green }, -- todo notes
Expand All @@ -121,6 +117,8 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
["@tag.delimiter"] = { fg = C.sky }, -- Tag delimiter like < > /

-- Language specific:
-- bash
["@function.builtin.bash"] = { fg = C.red, style = { "italic" } },

-- markdown
["@text.title.2.markdown"] = { link = "rainbow2" },
Expand All @@ -139,35 +137,45 @@ If you want to stay on nvim 0.7, either disable the integration or pin catppucci
["@string.plain.css"] = { fg = C.peach },
["@number.css"] = { fg = C.peach },

-- java
["@constant.java"] = { fg = C.teal },

-- toml
["@property.toml"] = { fg = C.blue }, -- Differentiates between string and properties

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

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

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

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

-- cpp
["@property.cpp"] = { fg = C.rosewater },

-- yaml
["@field.yaml"] = { fg = C.blue }, -- For fields.

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

-- PHP
["@type.qualifier.php"] = { link = "Keyword" }, -- type qualifiers (e.g. `const`)
["@method.php"] = { link = "Function" },
["@method.call.php"] = { link = "Function" },

-- C/CPP
["@type.builtin.c"] = { style = {} },
["@property.cpp"] = { fg = C.text },
["@type.builtin.cpp"] = { style = {} },

-- Misc
gitcommitSummary = { fg = C.rosewater, style = { "italic" } },
zshKSHFunction = { link = "Function" },
}
end

Expand Down
21 changes: 10 additions & 11 deletions lua/catppuccin/groups/syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,30 @@ function M.get()
Number = { fg = C.peach, style = O.styles.numbers or {} }, -- a number constant: 234, 0xff
Float = { link = "Number" }, -- a floating point constant: 2.3e10
Boolean = { fg = C.peach, style = O.styles.booleans or {} }, -- a boolean constant: TRUE, false
Identifier = { fg = C.flamingo, style = O.styles.variables or {} }, -- (preferred) any variable name
Identifier = { fg = C.text, style = O.styles.variables or {} }, -- (preferred) any variable name
Function = { fg = C.blue, style = O.styles.functions or {} }, -- function name (also: methods for classes)
Statement = { fg = C.mauve }, -- (preferred) any statement
Conditional = { fg = C.mauve, style = O.styles.conditionals or {} }, -- if, then, else, endif, switch, etc.
Repeat = { fg = C.mauve, style = O.styles.loops or {} }, -- for, do, while, etc.
Label = { fg = C.sapphire }, -- case, default, etc.
Label = { fg = C.rosewater }, -- case, default, etc.
Operator = { fg = C.sky, style = O.styles.operators or {} }, -- "sizeof", "+", "*", etc.
Keyword = { fg = C.mauve, style = O.styles.keywords or {} }, -- any other keyword
Array = { fg = C.lavender },
Exception = { fg = C.mauve, style = O.styles.keywords or {} }, -- try, catch, throw
Keyword = { fg = C.maroon, style = O.styles.keywords or {} }, -- any other keyword
Exception = { fg = C.peach, style = O.styles.keywords or {} }, -- try, catch, throw

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

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

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

0 comments on commit 1f76a94

Please sign in to comment.