aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-03-10 13:35:07 +0000
committerGitHub <noreply@github.com>2023-03-10 13:35:07 +0000
commit845efb8e12cb014b385deac62fb83622a99024ec (patch)
tree3686fc9ffbdd4bd2afeb4419ff649ef6e0f34c55 /runtime/lua/vim/treesitter.lua
parent75537768ef0b8cc35ef9c6aa906237e449640b46 (diff)
parent46b73bf22cb951151de9bf0712d42e194000b677 (diff)
downloadrneovim-845efb8e12cb014b385deac62fb83622a99024ec.tar.gz
rneovim-845efb8e12cb014b385deac62fb83622a99024ec.tar.bz2
rneovim-845efb8e12cb014b385deac62fb83622a99024ec.zip
Merge pull request #22594 from lewis6991/perf/treefold
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r--runtime/lua/vim/treesitter.lua25
1 files changed, 20 insertions, 5 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index ab9f8968c8..5723cce563 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -99,13 +99,28 @@ function M.get_parser(bufnr, lang, opts)
if bufnr == nil or bufnr == 0 then
bufnr = a.nvim_get_current_buf()
end
+
if lang == nil then
local ft = vim.bo[bufnr].filetype
- lang = language.get_lang(ft) or ft
- -- TODO(lewis6991): we should error here and not default to ft
- -- if not lang then
- -- error(string.format('filetype %s of buffer %d is not associated with any lang', ft, bufnr))
- -- end
+ if ft ~= '' then
+ lang = language.get_lang(ft) or ft
+ -- TODO(lewis6991): we should error here and not default to ft
+ -- if not lang then
+ -- error(string.format('filetype %s of buffer %d is not associated with any lang', ft, bufnr))
+ -- end
+ else
+ if parsers[bufnr] then
+ return parsers[bufnr]
+ end
+ error(
+ string.format(
+ 'There is no parser available for buffer %d and one could not be'
+ .. ' created because lang could not be determined. Either pass lang'
+ .. ' or set the buffer filetype',
+ bufnr
+ )
+ )
+ end
end
if parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then