diff options
Diffstat (limited to 'runtime/lua/vim/treesitter/language.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/language.lua | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua index a7e36a0b89..d60cd2d0c7 100644 --- a/runtime/lua/vim/treesitter/language.lua +++ b/runtime/lua/vim/treesitter/language.lua @@ -8,7 +8,8 @@ local M = {} -- -- @param lang The language the parser should parse -- @param path Optionnal path the parser is located at -function M.require_language(lang, path) +-- @param silent Don't throw an error if language not found +function M.require_language(lang, path, silent) if vim._ts_has_language(lang) then return true end @@ -16,12 +17,23 @@ function M.require_language(lang, path) local fname = 'parser/' .. lang .. '.*' local paths = a.nvim_get_runtime_file(fname, false) if #paths == 0 then + if silent then + return false + end + -- TODO(bfredl): help tag? error("no parser for '"..lang.."' language, see :help treesitter-parsers") end path = paths[1] end - vim._ts_add_language(path, lang) + + if silent then + return pcall(function() vim._ts_add_language(path, lang) end) + else + vim._ts_add_language(path, lang) + end + + return true end --- Inspects the provided language. |