Created
February 9, 2022 02:43
-
-
Save wookayin/9c665e210e33ff58c25dbfd02b4c4e02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Make sure TS syntax tree is updated when needed by plugin (with some throttling) | |
-- even if the `highlight` module is not enabled. | |
-- See https://github.com/nvim-treesitter/nvim-treesitter/issues/2492 | |
_G.TreesitterParse = function() | |
local lang = ts_parsers.ft_to_lang(vim.bo.filetype) | |
local parser = ts_parsers.get_parser(vim.fn.bufnr(), lang) | |
if parser then | |
parser:parse() | |
return true | |
else | |
return false | |
end | |
end | |
local function throttle(fn, ms) | |
local timer = vim.loop.new_timer() | |
local running = false | |
return function(...) | |
if not running then | |
timer:start(ms, 0, function() running = false end) | |
running = true | |
pcall(vim.schedule_wrap(fn), select(1, ...)) | |
end | |
end | |
end | |
if not ts_configs.get_module('highlight').enable then | |
_G.TreesitterParseDebounce = throttle(_G.TreesitterParse, 100) -- 100 ms | |
vim.cmd [[ | |
augroup TreesitterUpdateParsing | |
autocmd! | |
autocmd TextChanged,TextChangedI * call v:lua.TreesitterParseDebounce() | |
augroup END | |
]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment