aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/_fold.lua
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-09-13 05:09:11 -0700
committerGitHub <noreply@github.com>2024-09-13 05:09:11 -0700
commitb9b408a56c7e607972beaa7214719ff1494e384c (patch)
tree92c415c133cd2d591000d314df0a026c49961e17 /runtime/lua/vim/treesitter/_fold.lua
parent8654a9700690a715e35baa600bb982f4ea608ead (diff)
downloadrneovim-b9b408a56c7e607972beaa7214719ff1494e384c.tar.gz
rneovim-b9b408a56c7e607972beaa7214719ff1494e384c.tar.bz2
rneovim-b9b408a56c7e607972beaa7214719ff1494e384c.zip
feat(treesitter): start moving get_parser to return nil #30313
**Problem:** `vim.treesitter.get_parser` will throw an error if no parser can be found. - This means the caller is responsible for wrapping it in a `pcall`, which is easy to forget - It also makes it slightly harder to potentially memoize `get_parser` in the future - It's a bit unintuitive since many other `get_*` style functions conventionally return `nil` if no object is found (e.g. `get_node`, `get_lang`, `query.get`, etc.) **Solution:** Return `nil` if no parser can be found or created - This requires a function signature change, and some new assertions in places where the parser will always (or should always) be found. - This commit starts by making this change internally, since it is breaking. Eventually it will be rolled out to the public API.
Diffstat (limited to 'runtime/lua/vim/treesitter/_fold.lua')
-rw-r--r--runtime/lua/vim/treesitter/_fold.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/_fold.lua b/runtime/lua/vim/treesitter/_fold.lua
index 7375beaf9d..49792c3891 100644
--- a/runtime/lua/vim/treesitter/_fold.lua
+++ b/runtime/lua/vim/treesitter/_fold.lua
@@ -114,7 +114,7 @@ local function compute_folds_levels(bufnr, info, srow, erow, parse_injections)
srow = srow or 0
erow = erow or api.nvim_buf_line_count(bufnr)
- local parser = ts.get_parser(bufnr)
+ local parser = assert(ts._get_parser(bufnr))
parser:parse(parse_injections and { srow, erow } or nil)
@@ -392,7 +392,7 @@ function M.foldexpr(lnum)
lnum = lnum or vim.v.lnum
local bufnr = api.nvim_get_current_buf()
- local parser = vim.F.npcall(ts.get_parser, bufnr)
+ local parser = ts._get_parser(bufnr)
if not parser then
return '0'
end