mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 04:28:33 +00:00
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.
This commit is contained in:
@@ -135,9 +135,7 @@ void ui_refresh(void)
|
||||
insert(test_text)
|
||||
|
||||
eq(
|
||||
'.../treesitter.lua:0: There is no parser available for buffer 1 and one'
|
||||
.. ' could not be created because lang could not be determined. Either'
|
||||
.. ' pass lang or set the buffer filetype',
|
||||
'.../treesitter.lua:0: Parser not found.',
|
||||
pcall_err(exec_lua, 'vim.treesitter.get_parser(0)')
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user