diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2022-08-25 15:55:19 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-08-26 06:04:07 -0700 |
| commit | 1baf751fb0b03015c4c9883a87923cc4a7a4812e (patch) | |
| tree | f5066af1d959882e6ef6dabb33fc5df5aa90d19f /lua | |
| parent | feat: allow to fold markdown sections (diff) | |
| download | nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar.gz nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar.bz2 nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar.lz nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar.xz nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.tar.zst nvim-treesitter-1baf751fb0b03015c4c9883a87923cc4a7a4812e.zip | |
fix(hl_map): adapt to upstream changes on master
https://github.com/neovim/neovim/pull/19931 adds direct support for
highlighting capture groups (with fallback), obviating the need for
`vim.treesitter.highlighter.hl_map`. Instead of
`hl_map["@keyword"] = "TSKeyword"`
users can simply
`hi link TSKeyword @keyword`
Check for the existence of `hl_map` and either use the former or the
latter.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/highlight.lua | 170 |
1 files changed, 94 insertions, 76 deletions
diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua index b75dc7bf9..c9a269568 100644 --- a/lua/nvim-treesitter/highlight.lua +++ b/lua/nvim-treesitter/highlight.lua @@ -6,116 +6,133 @@ local configs = require "nvim-treesitter.configs" local M = {} -local hlmap = vim.treesitter.highlighter.hl_map - -- 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 + +local default_map = { + ["annotation"] = "TSAnnotation", -hlmap["annotation"] = "TSAnnotation" + ["attribute"] = "TSAttribute", -hlmap["attribute"] = "TSAttribute" + ["boolean"] = "TSBoolean", -hlmap["boolean"] = "TSBoolean" + ["character"] = "TSCharacter", + ["character.special"] = "TSCharacterSpecial", -hlmap["character"] = "TSCharacter" -hlmap["character.special"] = "TSCharacterSpecial" + ["comment"] = "TSComment", -hlmap["comment"] = "TSComment" + ["conditional"] = "TSConditional", -hlmap["conditional"] = "TSConditional" + ["constant"] = "TSConstant", + ["constant.builtin"] = "TSConstBuiltin", + ["constant.macro"] = "TSConstMacro", -hlmap["constant"] = "TSConstant" -hlmap["constant.builtin"] = "TSConstBuiltin" -hlmap["constant.macro"] = "TSConstMacro" + ["constructor"] = "TSConstructor", -hlmap["constructor"] = "TSConstructor" + ["debug"] = "TSDebug", + ["define"] = "TSDefine", -hlmap["debug"] = "TSDebug" -hlmap["define"] = "TSDefine" + ["error"] = "TSError", + ["exception"] = "TSException", -hlmap["error"] = "TSError" -hlmap["exception"] = "TSException" + ["field"] = "TSField", -hlmap["field"] = "TSField" + ["float"] = "TSFloat", -hlmap["float"] = "TSFloat" + ["function"] = "TSFunction", + ["function.call"] = "TSFunctionCall", + ["function.builtin"] = "TSFuncBuiltin", + ["function.macro"] = "TSFuncMacro", -hlmap["function"] = "TSFunction" -hlmap["function.call"] = "TSFunctionCall" -hlmap["function.builtin"] = "TSFuncBuiltin" -hlmap["function.macro"] = "TSFuncMacro" + ["include"] = "TSInclude", -hlmap["include"] = "TSInclude" + ["keyword"] = "TSKeyword", + ["keyword.function"] = "TSKeywordFunction", + ["keyword.operator"] = "TSKeywordOperator", + ["keyword.return"] = "TSKeywordReturn", -hlmap["keyword"] = "TSKeyword" -hlmap["keyword.function"] = "TSKeywordFunction" -hlmap["keyword.operator"] = "TSKeywordOperator" -hlmap["keyword.return"] = "TSKeywordReturn" + ["label"] = "TSLabel", -hlmap["label"] = "TSLabel" + ["method"] = "TSMethod", + ["method.call"] = "TSMethodCall", -hlmap["method"] = "TSMethod" -hlmap["method.call"] = "TSMethodCall" + ["namespace"] = "TSNamespace", -hlmap["namespace"] = "TSNamespace" + ["none"] = "TSNone", + ["number"] = "TSNumber", -hlmap["none"] = "TSNone" -hlmap["number"] = "TSNumber" + ["operator"] = "TSOperator", -hlmap["operator"] = "TSOperator" + ["parameter"] = "TSParameter", + ["parameter.reference"] = "TSParameterReference", -hlmap["parameter"] = "TSParameter" -hlmap["parameter.reference"] = "TSParameterReference" + ["preproc"] = "TSPreProc", -hlmap["preproc"] = "TSPreProc" + ["property"] = "TSProperty", -hlmap["property"] = "TSProperty" + ["punctuation.delimiter"] = "TSPunctDelimiter", + ["punctuation.bracket"] = "TSPunctBracket", + ["punctuation.special"] = "TSPunctSpecial", -hlmap["punctuation.delimiter"] = "TSPunctDelimiter" -hlmap["punctuation.bracket"] = "TSPunctBracket" -hlmap["punctuation.special"] = "TSPunctSpecial" + ["repeat"] = "TSRepeat", -hlmap["repeat"] = "TSRepeat" + ["storageclass"] = "TSStorageClass", -hlmap["storageclass"] = "TSStorageClass" + ["string"] = "TSString", + ["string.regex"] = "TSStringRegex", + ["string.escape"] = "TSStringEscape", + ["string.special"] = "TSStringSpecial", -hlmap["string"] = "TSString" -hlmap["string.regex"] = "TSStringRegex" -hlmap["string.escape"] = "TSStringEscape" -hlmap["string.special"] = "TSStringSpecial" + ["symbol"] = "TSSymbol", -hlmap["symbol"] = "TSSymbol" + ["tag"] = "TSTag", + ["tag.attribute"] = "TSTagAttribute", + ["tag.delimiter"] = "TSTagDelimiter", -hlmap["tag"] = "TSTag" -hlmap["tag.attribute"] = "TSTagAttribute" -hlmap["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", -hlmap["text"] = "TSText" -hlmap["text.strong"] = "TSStrong" -hlmap["text.emphasis"] = "TSEmphasis" -hlmap["text.underline"] = "TSUnderline" -hlmap["text.strike"] = "TSStrike" -hlmap["text.title"] = "TSTitle" -hlmap["text.literal"] = "TSLiteral" -hlmap["text.uri"] = "TSURI" -hlmap["text.math"] = "TSMath" -hlmap["text.reference"] = "TSTextReference" -hlmap["text.environment"] = "TSEnvironment" -hlmap["text.environment.name"] = "TSEnvironmentName" + ["text.note"] = "TSNote", + ["text.warning"] = "TSWarning", + ["text.danger"] = "TSDanger", -hlmap["text.note"] = "TSNote" -hlmap["text.warning"] = "TSWarning" -hlmap["text.danger"] = "TSDanger" + ["todo"] = "TSTodo", -hlmap["todo"] = "TSTodo" + ["type"] = "TSType", + ["type.builtin"] = "TSTypeBuiltin", + ["type.qualifier"] = "TSTypeQualifier", + ["type.definition"] = "TSTypeDefinition", -hlmap["type"] = "TSType" -hlmap["type.builtin"] = "TSTypeBuiltin" -hlmap["type.qualifier"] = "TSTypeQualifier" -hlmap["type.definition"] = "TSTypeDefinition" + ["variable"] = "TSVariable", + ["variable.builtin"] = "TSVariableBuiltin", +} -hlmap["variable"] = "TSVariable" -hlmap["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, hlgroup, { link = "@" .. capture }) + end +end + +for capture, hlgroup in pairs(default_map) do + link_captures(capture, hlgroup) +end local function should_enable_vim_regex(config, lang) local additional_hl = config.additional_vim_regex_highlighting @@ -152,9 +169,10 @@ 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 k, v in pairs(captures) do - hlmap[k] = v + for capture, hlgroup in pairs(captures) do + link_captures(capture, hlgroup) end end |
