diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-03-10 10:25:10 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-03-10 10:43:35 +0000 |
commit | c5b9643bf1b0f6d5166b4abf6a7c3f29532aefeb (patch) | |
tree | 2cf9bf93f8b78af94408239d73618df700509201 /runtime/lua/vim/treesitter.lua | |
parent | adfa9de8ebc4bce96d212280eccddc0306d1b013 (diff) | |
download | rneovim-c5b9643bf1b0f6d5166b4abf6a7c3f29532aefeb.tar.gz rneovim-c5b9643bf1b0f6d5166b4abf6a7c3f29532aefeb.tar.bz2 rneovim-c5b9643bf1b0f6d5166b4abf6a7c3f29532aefeb.zip |
fix(treesitter): better lang handling of get_parser()
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 25 |
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 |