summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/highlight.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-10-31 10:52:52 +0000
committerChristian Clason <christian.clason@uni-due.de>2022-10-31 12:00:45 +0100
commit0948bf22745f1d80572e2b46ed547c7c8674cca9 (patch)
tree6bd8d49b094b36a61e9a38b1f1b2d04004330ca4 /lua/nvim-treesitter/highlight.lua
parent4392211d77a11f3f4806c963ff904506cb649a1f (diff)
feat(emmy): add emmylua annotations
Diffstat (limited to 'lua/nvim-treesitter/highlight.lua')
-rw-r--r--lua/nvim-treesitter/highlight.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua
index 502914fe..5f7dead6 100644
--- a/lua/nvim-treesitter/highlight.lua
+++ b/lua/nvim-treesitter/highlight.lua
@@ -6,6 +6,9 @@ local configs = require "nvim-treesitter.configs"
local M = {}
+---@param config table
+---@param lang string
+---@return boolean
local function should_enable_vim_regex(config, lang)
local additional_hl = config.additional_vim_regex_highlighting
local is_table = type(additional_hl) == "table"
@@ -13,29 +16,36 @@ local function should_enable_vim_regex(config, lang)
return additional_hl and (not is_table or vim.tbl_contains(additional_hl, lang))
end
+---@param bufnr integer
local function enable_syntax(bufnr)
api.nvim_buf_set_option(bufnr, "syntax", "ON")
end
+---@param bufnr integer
function M.stop(bufnr)
if ts.highlighter.active[bufnr] then
ts.highlighter.active[bufnr]:destroy()
end
end
+---@param bufnr integer
+---@param lang string
function M.start(bufnr, lang)
local parser = parsers.get_parser(bufnr, lang)
ts.highlighter.new(parser, {})
end
+---@param bufnr integer
+---@param lang string
function M.attach(bufnr, lang)
local config = configs.get_module "highlight"
M.start(bufnr, lang)
- if should_enable_vim_regex(config, lang) then
+ if config and should_enable_vim_regex(config, lang) then
enable_syntax(bufnr)
end
end
+---@param bufnr integer
function M.detach(bufnr)
M.stop(bufnr)
enable_syntax(bufnr)