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
This commit is contained in:
Santos Gallegos 2021-07-05 12:36:55 -05:00 committed by mergify[bot]
parent 74d1d58572
commit 9be9ebda0a

View file

@ -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)