From 9be9ebda0ad5d5ffb880829ad3315ab7c55a2acc Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 5 Jul 2021 12:36:55 -0500 Subject: Re-attach module when the file type is changed Requires https://github.com/neovim/neovim/pull/14995 Closes https://github.com/nvim-treesitter/nvim-treesitter/issues/1249 --- lua/nvim-treesitter/configs.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index cb02e7032..ff1f8078f 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -85,7 +85,7 @@ local function enable_mod_conf_autocmd(mod) return end - local cmd = string.format("lua require'nvim-treesitter.configs'.attach_module('%s')", mod) + local cmd = string.format("lua require'nvim-treesitter.configs'.reattach_module('%s')", mod) api.nvim_command(string.format("autocmd NvimTreesitter FileType * %s", cmd)) config_mod.loaded = true @@ -442,6 +442,15 @@ function M.detach_module(mod_name, bufnr) end end +-- Same as attach_module, but if the module is already attached, detach it first. +-- @param mod_name the module name +-- @param bufnr the bufnr +-- @param lang the language of the buffer +function M.reattach_module(mod_name, bufnr, lang) + M.detach_module(mod_name, bufnr) + M.attach_module(mod_name, bufnr, lang) +end + -- Gets available modules -- @param root root table to find modules function M.available_modules(root) -- cgit v1.2.3-70-g09d2