added attach async

This commit is contained in:
Brian Shu 2021-01-05 11:26:03 -05:00 committed by Thomas Vigouroux
parent b441f257a4
commit e0b49a9a18
2 changed files with 14 additions and 1 deletions

View file

@ -78,7 +78,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'.attach_module_async('%s')", mod)
api.nvim_command(string.format("autocmd NvimTreesitter FileType * %s", cmd))
config_mod.loaded = true
@ -311,6 +311,8 @@ function M.attach_module(mod_name, bufnr, lang)
end
end
M.attach_module_async = utils.async(M.attach_module)
-- Detaches a module to a buffer
-- @param mod_name the module name
-- @param bufnr the bufnr

View file

@ -141,4 +141,15 @@ 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