diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 15 | ||||
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 11 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index a7bbcb97d..7a41aae90 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -299,8 +299,8 @@ end -- @param bufnr the bufnr -- @param lang the language of the buffer function M.attach_module(mod_name, bufnr, lang) - local bufnr = bufnr or api.nvim_get_current_buf() - local lang = lang or parsers.get_buf_lang(bufnr) + bufnr = bufnr or api.nvim_get_current_buf() + lang = lang or parsers.get_buf_lang(bufnr) local resolved_mod = resolve_module(mod_name) if resolved_mod @@ -311,7 +311,16 @@ function M.attach_module(mod_name, bufnr, lang) end end -M.attach_module_async = utils.async(M.attach_module) +-- must have custom async function or bufnr will be wrong +function M.attach_module_async(mod_name, bufnr) + bufnr = bufnr or api.nvim_get_current_buf() -- get bufnr before doing async, or bufnr will be wrong + + local handle + handle = vim.loop.new_async(vim.schedule_wrap(function(...) + M.attach_module(...) + end)) + handle:send(mod_name, bufnr, nil) +end -- Detaches a module to a buffer -- @param mod_name the module name diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 00ba4b943..de579bd6d 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -141,15 +141,4 @@ function M.index_of(tbl, obj) end end -function M.async(f) - return function(...) - local handle - handle = vim.loop.new_async(vim.schedule_wrap(function(...) - f(...) - handle:close() - end)) - handle:send(...) - end -end - return M |
