feat!: remove obsolete TS* highlight groups

This commit is contained in:
Christian Clason 2022-10-16 14:52:15 +02:00 committed by Christian Clason
parent 4cccb6f494
commit 42ab95d5e1
8 changed files with 25 additions and 572 deletions

View file

@ -63,7 +63,7 @@ For more detailed information on setting these up, see ["Advanced setup"](#advan
## Requirements
- **Neovim 0.7.0 or later** built with **tree-sitter 0.20.3+** (latest [nightly](https://github.com/neovim/neovim#install-from-source) recommended)
- **Neovim 0.8.0 or later** built with **tree-sitter 0.20.3+** (latest [nightly](https://github.com/neovim/neovim#install-from-source) recommended)
- `tar` and `curl` in your path (or alternatively `git`)
- A C compiler in your path and libstdc++ installed ([Windows users please read this!](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support)).

View file

@ -476,307 +476,6 @@ Note: This is highly experimental, and folding can break on some types of
edits. If you encounter such breakage, hiting `zx` should fix folding.
In any case, feel free to open an issue with the reproducing steps.
==============================================================================
HIGHLIGHTS *nvim-treesitter-highlights*
The following is a list of highlights groups, the syntactic elements they
apply to, and some examples.
*hl-TSAttribute*
`TSAttribute`
Annotations that can be attached to the code to denote some kind of meta
information. e.g. C++/Dart attributes.
*hl-TSBoolean*
`TSBoolean`
Boolean literals: `True` and `False` in Python.
*hl-TSCharacter*
`TSCharacter`
Character literals: `'a'` in C.
*hl-TSCharacterSpecial*
`TSCharacterSpecial`
Special characters.
*hl-TSComment*
`TSComment`
Line comments and block comments.
*hl-TSConditional*
`TSConditional`
Keywords related to conditionals: `if`, `when`, `cond`, etc.
*hl-TSConstant*
`TSConstant`
Constants identifiers. These might not be semantically constant.
E.g. uppercase variables in Python.
*hl-TSConstBuiltin*
`TSConstBuiltin`
Built-in constant values: `nil` in Lua.
*hl-TSConstMacro*
`TSConstMacro`
Constants defined by macros: `NULL` in C.
*hl-TSConstructor*
`TSConstructor`
Constructor calls and definitions: `{}` in Lua, and Java constructors.
*hl-TSDebug*
`TSDebug`
Debugging statements.
*hl-TSDefine*
`TSDefine`
Preprocessor #define statements.
*hl-TSError*
`TSError`
Syntax/parser errors. This might highlight large sections of code while the
user is typing still incomplete code, use a sensible highlight.
*hl-TSException*
`TSException`
Exception related keywords: `try`, `except`, `finally` in Python.
*hl-TSField*
`TSField`
Object and struct fields.
*hl-TSFloat*
`TSFloat`
Floating-point number literals.
*hl-TSFunction*
`TSFunction`
Function definitions.
*hl-TSFunctionCall*
`TSFunctionCall`
Function calls.
*hl-TSFuncBuiltin*
`TSFuncBuiltin`
Built-in functions: `print` in Lua.
*hl-TSFuncMacro*
`TSFuncMacro`
Macro defined functions (calls and definitions): each `macro_rules` in
Rust.
*hl-TSInclude*
`TSInclude`
File or module inclusion keywords: `#include` in C, `use` or `extern crate` in
Rust.
*hl-TSKeyword*
`TSKeyword`
Keywords that don't fit into other categories.
*hl-TSKeywordFunction*
`TSKeywordFunction`
Keywords used to define a function: `function` in Lua, `def` and `lambda` in
Python.
*hl-TSKeywordOperator*
`TSKeywordOperator`
Unary and binary operators that are English words: `and`, `or` in Python;
`sizeof` in C.
*hl-TSKeywordReturn*
`TSKeywordReturn`
Keywords like `return` and `yield`.
*hl-TSLabel*
`TSLabel`
GOTO labels: `label:` in C, and `::label::` in Lua.
*hl-TSMethod*
`TSMethod`
Method definitions.
*hl-TSMethodCall*
`TSMethodCall`
Method calls.
*hl-TSNamespace*
`TSNamespace`
Identifiers referring to modules and namespaces.
*hl-None*
`TSNone`
No highlighting (sets all highlight arguments to `NONE`). This group is used
to clear certain ranges, for example, string interpolations. Don't change the
values of this highlight group.
*hl-TSNumber*
`TSNumber`
Numeric literals that don't fit into other categories.
*hl-TSOperator*
`TSOperator`
Binary or unary operators: `+`, and also `->` and `*` in C.
*hl-TSParameter*
`TSParameter`
Parameters of a function.
*hl-TSParameterReference*
`TSParameterReference`
References to parameters of a function.
*hl-TSPreProc*
`TSPreProc`
Preprocessor #if, #else, #endif, etc.
*hl-TSProperty*
`TSProperty`
Same as `TSField`.
*hl-TSPunctDelimiter*
`TSPunctDelimiter`
Punctuation delimiters: Periods, commas, semicolons, etc.
*hl-TSPunctBracket*
`TSPunctBracket`
Brackets, braces, parentheses, etc.
*hl-TSPunctSpecial*
`TSPunctSpecial`
Special punctuation that doesn't fit into the previous categories.
*hl-TSRepeat*
`TSRepeat`
Keywords related to loops: `for`, `while`, etc.
*hl-StorageClass*
`TSStorageClass`
Keywords that affect how a variable is stored: `static`, `comptime`, `extern`,
etc.
*hl-TSString*
`TSString`
String literals.
*hl-TSStringRegex*
`TSStringRegex`
Regular expression literals.
*hl-TSStringEscape*
`TSStringEscape`
Escape characters within a string: `\n`, `\t`, etc.
*hl-TSStringSpecial*
`TSStringSpecial`
Strings with special meaning that don't fit into the previous categories.
*hl-TSSymbol*
`TSSymbol`
Identifiers referring to symbols or atoms.
*hl-TSTag*
`TSTag`
Tags like HTML tag names.
*hl-TSTagAttribute*
`TSTagAttribute`
HTML tag attributes.
*hl-TSTagDelimiter*
`TSTagDelimiter`
Tag delimiters like `<` `>` `/`.
*hl-TSText*
`TSText`
Non-structured text. Like text in a markup language.
*hl-TSSTrong*
`TSStrong`
Text to be represented in bold.
*hl-TSEmphasis*
`TSEmphasis`
Text to be represented with emphasis.
*hl-TSUnderline*
`TSUnderline`
Text to be represented with an underline.
*hl-TSStrike*
`TSStrike`
Strikethrough text.
*hl-TSTitle*
`TSTitle`
Text that is part of a title.
*hl-TSLiteral*
`TSLiteral`
Literal or verbatim text.
*hl-TSURI*
`TSURI`
URIs like hyperlinks or email addresses.
*hl-TSMath*
`TSMath`
Math environments like LaTeX's `$ ... $`.
*hl-TSTextReference*
`TSTextReference`
Footnotes, text references, citations, etc.
*hl-TSEnvironment*
`TSEnvironment`
Text environments of markup languages.
*hl-TSEnvironmentName*
`TSEnvironmentName`
Text/string indicating the type of text environment. Like the name of a
`\begin` block in LaTeX.
*hl-TSNote*
`TSNote`
Text representation of an informational note.
*TSWarning*
`TSWarning`
Text representation of a warning note.
*TSDanger*
`TSDanger`
Text representation of a danger note.
*hl-TSTodo*
`TSTodo`
Anything that needs extra attention, such as keywords like TODO or FIXME.
*hl-TSType*
`TSType`
Type (and class) definitions and annotations.
*hl-TSTypeBuiltin*
`TSTypeBuiltin`
Built-in types: `i32` in Rust.
*hl-TSTypeQualifier*
`TSTypeQualifier`
Qualifiers on types, e.g. `const` or `volatile` in C or `mut` in Rust.
*hl-TSTypeDefinition*
`TSTypeDefinition`
Type definitions, e.g. `typedef` in C.
*hl-TSVariable*
`TSVariable`
Variable names that don't fit into other categories.
*hl-TSVariableBuiltin*
`TSVariableBuiltin`
Variable names defined by the language: `this` or `self` in Javascript.
==============================================================================
PERFORMANCE *nvim-treesitter-performance*

View file

@ -6,140 +6,6 @@ local configs = require "nvim-treesitter.configs"
local M = {}
-- nvim-treesitter Highlight Group Mappings
-- Note: Some highlight groups may not be applied upstream, some may be experimental
-- TODO(clason): deprecated and will be removed for Nvim 0.8
M.default_map = {
["annotation"] = "TSAnnotation",
["attribute"] = "TSAttribute",
["boolean"] = "TSBoolean",
["character"] = "TSCharacter",
["character.special"] = "TSCharacterSpecial",
["comment"] = "TSComment",
["conditional"] = "TSConditional",
["constant"] = "TSConstant",
["constant.builtin"] = "TSConstBuiltin",
["constant.macro"] = "TSConstMacro",
["constructor"] = "TSConstructor",
["debug"] = "TSDebug",
["define"] = "TSDefine",
["error"] = "TSError",
["exception"] = "TSException",
["field"] = "TSField",
["float"] = "TSFloat",
["function"] = "TSFunction",
["function.call"] = "TSFunctionCall",
["function.builtin"] = "TSFuncBuiltin",
["function.macro"] = "TSFuncMacro",
["include"] = "TSInclude",
["keyword"] = "TSKeyword",
["keyword.function"] = "TSKeywordFunction",
["keyword.operator"] = "TSKeywordOperator",
["keyword.return"] = "TSKeywordReturn",
["label"] = "TSLabel",
["method"] = "TSMethod",
["method.call"] = "TSMethodCall",
["namespace"] = "TSNamespace",
["none"] = "TSNone",
["number"] = "TSNumber",
["operator"] = "TSOperator",
["parameter"] = "TSParameter",
["parameter.reference"] = "TSParameterReference",
["preproc"] = "TSPreProc",
["property"] = "TSProperty",
["punctuation.delimiter"] = "TSPunctDelimiter",
["punctuation.bracket"] = "TSPunctBracket",
["punctuation.special"] = "TSPunctSpecial",
["repeat"] = "TSRepeat",
["storageclass"] = "TSStorageClass",
["string"] = "TSString",
["string.regex"] = "TSStringRegex",
["string.escape"] = "TSStringEscape",
["string.special"] = "TSStringSpecial",
["symbol"] = "TSSymbol",
["tag"] = "TSTag",
["tag.attribute"] = "TSTagAttribute",
["tag.delimiter"] = "TSTagDelimiter",
["text"] = "TSText",
["text.strong"] = "TSStrong",
["text.emphasis"] = "TSEmphasis",
["text.underline"] = "TSUnderline",
["text.strike"] = "TSStrike",
["text.title"] = "TSTitle",
["text.literal"] = "TSLiteral",
["text.uri"] = "TSURI",
["text.math"] = "TSMath",
["text.reference"] = "TSTextReference",
["text.environment"] = "TSEnvironment",
["text.environment.name"] = "TSEnvironmentName",
["text.note"] = "TSNote",
["text.warning"] = "TSWarning",
["text.danger"] = "TSDanger",
["todo"] = "TSTodo",
["type"] = "TSType",
["type.builtin"] = "TSTypeBuiltin",
["type.qualifier"] = "TSTypeQualifier",
["type.definition"] = "TSTypeDefinition",
["variable"] = "TSVariable",
["variable.builtin"] = "TSVariableBuiltin",
}
-- compatibility shim
local link_captures
if ts.highlighter.hl_map then
link_captures = function(capture, hlgroup)
ts.highlighter.hl_map[capture] = hlgroup
end
elseif not vim.g.skip_ts_default_groups then
link_captures = function(capture, hlgroup)
api.nvim_set_hl(0, "@" .. capture, { link = hlgroup, default = true })
end
end
local function link_all_captures()
if link_captures then
for capture, hlgroup in pairs(M.default_map) do
link_captures(capture, hlgroup)
end
end
end
link_all_captures()
local function should_enable_vim_regex(config, lang)
local additional_hl = config.additional_vim_regex_highlighting
local is_table = type(additional_hl) == "table"
@ -175,104 +41,4 @@ function M.detach(bufnr)
enable_syntax(bufnr)
end
-- TODO(clason): remove obsolete function after bump to 0.8
function M.set_custom_captures(captures)
for capture, hlgroup in pairs(captures) do
link_captures(capture, hlgroup)
end
end
function M.set_default_hlgroups()
if not ts.highlighter.hl_map and not vim.g.skip_ts_default_groups then
link_all_captures()
end
local highlights = {
TSNone = { default = true },
TSPunctDelimiter = { link = "Delimiter", default = true },
TSPunctBracket = { link = "Delimiter", default = true },
TSPunctSpecial = { link = "Delimiter", default = true },
TSConstant = { link = "Constant", default = true },
TSConstBuiltin = { link = "Special", default = true },
TSConstMacro = { link = "Define", default = true },
TSString = { link = "String", default = true },
TSStringRegex = { link = "String", default = true },
TSStringEscape = { link = "SpecialChar", default = true },
TSStringSpecial = { link = "SpecialChar", default = true },
TSCharacter = { link = "Character", default = true },
TSCharacterSpecial = { link = "SpecialChar", default = true },
TSNumber = { link = "Number", default = true },
TSBoolean = { link = "Boolean", default = true },
TSFloat = { link = "Float", default = true },
TSFunction = { link = "Function", default = true },
TSFunctionCall = { link = "TSFunction", default = true },
TSFuncBuiltin = { link = "Special", default = true },
TSFuncMacro = { link = "Macro", default = true },
TSParameter = { link = "Identifier", default = true },
TSParameterReference = { link = "TSParameter", default = true },
TSMethod = { link = "Function", default = true },
TSMethodCall = { link = "TSMethod", default = true },
TSField = { link = "Identifier", default = true },
TSProperty = { link = "Identifier", default = true },
TSConstructor = { link = "Special", default = true },
TSAnnotation = { link = "PreProc", default = true },
TSAttribute = { link = "PreProc", default = true },
TSNamespace = { link = "Include", default = true },
TSSymbol = { link = "Identifier", default = true },
TSConditional = { link = "Conditional", default = true },
TSRepeat = { link = "Repeat", default = true },
TSLabel = { link = "Label", default = true },
TSOperator = { link = "Operator", default = true },
TSKeyword = { link = "Keyword", default = true },
TSKeywordFunction = { link = "Keyword", default = true },
TSKeywordOperator = { link = "TSOperator", default = true },
TSKeywordReturn = { link = "TSKeyword", default = true },
TSException = { link = "Exception", default = true },
TSDebug = { link = "Debug", default = true },
TSDefine = { link = "Define", default = true },
TSPreProc = { link = "PreProc", default = true },
TSStorageClass = { link = "StorageClass", default = true },
TSTodo = { link = "Todo", default = true },
TSType = { link = "Type", default = true },
TSTypeBuiltin = { link = "Type", default = true },
TSTypeQualifier = { link = "Type", default = true },
TSTypeDefinition = { link = "Typedef", default = true },
TSInclude = { link = "Include", default = true },
TSVariableBuiltin = { link = "Special", default = true },
TSText = { link = "TSNone", default = true },
TSStrong = { bold = true, default = true },
TSEmphasis = { italic = true, default = true },
TSUnderline = { underline = true },
TSStrike = { strikethrough = true },
TSMath = { link = "Special", default = true },
TSTextReference = { link = "Constant", default = true },
TSEnvironment = { link = "Macro", default = true },
TSEnvironmentName = { link = "Type", default = true },
TSTitle = { link = "Title", default = true },
TSLiteral = { link = "String", default = true },
TSURI = { link = "Underlined", default = true },
TSComment = { link = "Comment", default = true },
TSNote = { link = "SpecialComment", default = true },
TSWarning = { link = "Todo", default = true },
TSDanger = { link = "WarningMsg", default = true },
TSTag = { link = "Label", default = true },
TSTagDelimiter = { link = "Delimiter", default = true },
TSTagAttribute = { link = "TSProperty", default = true },
}
for k, v in pairs(highlights) do
api.nvim_set_hl(0, k, v)
end
end
return M

View file

@ -9,7 +9,6 @@ vim.g.loaded_nvim_treesitter = true
require("nvim-treesitter").setup()
local api = vim.api
local highlight = require "nvim-treesitter.highlight"
-- define autocommands
local augroup = api.nvim_create_augroup("NvimTreesitter", {})
@ -33,12 +32,3 @@ api.nvim_create_autocmd("Filetype", {
end,
desc = "Reload query",
})
api.nvim_create_autocmd("ColorScheme", {
group = augroup,
callback = highlight.set_default_hlgroups,
desc = "Set default highlights",
})
-- define highlights
highlight.set_default_hlgroups()

View file

@ -5,8 +5,8 @@
auto main( int argc, char** argv ) -> int
// ^ parameter
// ^ type
// ^ TSType
// ^ type
// ^ type
// ^ operator
{
std::cout << "Hello world!" << std::endl;

View file

@ -1,13 +1,13 @@
local a = { 1, 2, 3, 4, 5 }
-- ^ TSNumber ^ TSPunctBracket
-- ^ TSVariable
-- ^ number ^ punctuation.bracket
-- ^ variable
local _ = next(a)
-- ^ TSFuncBuiltin
-- ^ TSKeyword
-- ^ function.builtin
-- ^ keyword
_ = next(a)
-- ^ TSFuncBuiltin
-- ^ function.builtin
next(a)
-- ^ TSFuncBuiltin
-- ^ function.builtin

View file

@ -1,28 +1,28 @@
# H1
<!-- <- TSPunctSpecial -->
<!-- <- punctuation.special -->
## H2
<!-- <- TSPunctSpecial -->
<!-- <- punctuation.special -->
- Item 1
- Item 2
<!-- <- TSPunctSpecial -->
<!-- <- punctuation.special -->
1. Item 1
2. Item 2
<!-- <- TSPunctSpecial -->
<!-- <- punctuation.special -->
----![image_description](https://example.com/image.jpg "awesome image title")
<!-- ^ TSTextReference -->
<!-- ^ TSURI -->
<!-- ^ TSLiteral -->
<!--^ TSPunctDelimiter -->
<!-- ^ TSPunctDelimiter -->
<!-- //TODO: currently disabled TSPunctDelimiter -->
<!-- ^ text.reference -->
<!-- ^ text.uri -->
<!-- ^ text.literal -->
<!--^ punctuation.delimiter -->
<!-- ^ punctuation.delimiter -->
<!-- //TODO: currently disabled punctuation.delimiter -->
[link_text](#local_reference "link go brr...")
<!-- ^ TSTextReference -->
<!-- ^ TSURI -->
<!-- ^ TSLiteral -->
<!-- <- TSPunctDelimiter -->
<!-- //TODO: currently disabled TSPunctDelimiter -->
<!-- ^ text.reference -->
<!-- ^ text.uri -->
<!-- ^ text.literal -->
<!-- <- punctuation.delimiter -->
<!-- //TODO: currently disabled punctuation.delimiter -->

View file

@ -1,4 +1,3 @@
local ts_highlight = require "nvim-treesitter.highlight" -- yes, this is necessary to set the hlmap
local highlighter = require "vim.treesitter.highlighter"
local ts_utils = require "nvim-treesitter.ts_utils"
local parsers = require "nvim-treesitter.parsers"
@ -72,8 +71,7 @@ local function check_assertions(file)
local c = query._query.captures[capture] -- name of the capture in the query
if c ~= nil and c ~= "spell" and c ~= "conceal" then
captures[c] = true
local general_hl = ts_highlight.default_map[c]
highlights[general_hl] = true
highlights[c] = true
end
end
end