mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
fix(treesitter): don't throw an error for missing injected langs
This commit is contained in:
@ -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.
|
||||
|
Reference in New Issue
Block a user