mirror of
https://github.com/neovim/neovim.git
synced 2026-01-06 11:27:26 +10:00
feat(treesitter): async parsing
**Problem:** Parsing can be slow for large files, and it is a blocking operation which can be disruptive and annoying. **Solution:** Provide a function for asynchronous parsing, which accepts a callback to be run after parsing completes. Co-authored-by: Lewis Russell <lewis6991@gmail.com> Co-authored-by: Luuk van Baal <luukvbaal@gmail.com> Co-authored-by: VanaIgr <vanaigranov@gmail.com>
This commit is contained in:
@@ -61,7 +61,7 @@ function M._create_parser(bufnr, lang, opts)
|
||||
{ on_bytes = bytes_cb, on_detach = detach_cb, on_reload = reload_cb, preview = true }
|
||||
)
|
||||
|
||||
self:parse()
|
||||
self:parse(nil, function() end)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -397,6 +397,8 @@ end
|
||||
--- Note: By default, disables regex syntax highlighting, which may be required for some plugins.
|
||||
--- In this case, add `vim.bo.syntax = 'on'` after the call to `start`.
|
||||
---
|
||||
--- Note: By default, the highlighter parses code asynchronously, using a segment time of 3ms.
|
||||
---
|
||||
--- Example:
|
||||
---
|
||||
--- ```lua
|
||||
@@ -408,8 +410,8 @@ end
|
||||
--- })
|
||||
--- ```
|
||||
---
|
||||
---@param bufnr (integer|nil) Buffer to be highlighted (default: current buffer)
|
||||
---@param lang (string|nil) Language of the parser (default: from buffer filetype)
|
||||
---@param bufnr integer? Buffer to be highlighted (default: current buffer)
|
||||
---@param lang string? Language of the parser (default: from buffer filetype)
|
||||
function M.start(bufnr, lang)
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
local parser = assert(M.get_parser(bufnr, lang, { error = false }))
|
||||
|
||||
Reference in New Issue
Block a user