summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/highlight.lua
diff options
context:
space:
mode:
authorkiyan <yazdani.kiyan@protonmail.com>2022-02-06 15:15:42 +0100
committerStephan Seitz <stephan.seitz@fau.de>2022-02-19 18:26:51 +0100
commit560e8fb4500ac481601d2511b40f730b4515820e (patch)
tree88e745b744e36041fd8a2cfab9f7b271ecdd4a2e /lua/nvim-treesitter/highlight.lua
parentaf71c25edce0861589a51c630525bd0b06ba6a41 (diff)
refacto: expose a function to set custom capture for the higlighter
BREAKING: deprecate custom_captures from highlight config. This allows plugin authors to extend the map. It also avoids settings user configuration specific values during the highlighter initialization (SOC). Not sure how much value this brings, and might potentially break a lot of people configurations. This is questionable.
Diffstat (limited to 'lua/nvim-treesitter/highlight.lua')
-rw-r--r--lua/nvim-treesitter/highlight.lua19
1 files changed, 8 insertions, 11 deletions
diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua
index ce7cf811..b71a64ee 100644
--- a/lua/nvim-treesitter/highlight.lua
+++ b/lua/nvim-treesitter/highlight.lua
@@ -114,10 +114,6 @@ local function enable_syntax(bufnr)
api.nvim_buf_set_option(bufnr, "syntax", "ON")
end
-function M.get_config()
- return configs.get_module "highlight"
-end
-
function M.stop(bufnr)
if ts.highlighter.active[bufnr] then
ts.highlighter.active[bufnr]:destroy()
@@ -126,18 +122,13 @@ end
function M.start(bufnr, lang)
local parser = parsers.get_parser(bufnr, lang)
- local config = M.get_config()
-
- for k, v in pairs(config.custom_captures) do
- hlmap[k] = v
- end
-
ts.highlighter.new(parser, {})
end
function M.attach(bufnr, lang)
+ local config = configs.get_module "highlight"
M.start(bufnr, lang)
- if should_enable_vim_regex(M.get_config(), lang) then
+ if should_enable_vim_regex(config, lang) then
enable_syntax(bufnr)
end
end
@@ -147,4 +138,10 @@ function M.detach(bufnr)
enable_syntax(bufnr)
end
+function M.set_custom_captures(captures)
+ for k, v in pairs(captures) do
+ hlmap[k] = v
+ end
+end
+
return M