diff --git a/lua/ts.lua b/lua/ts.lua index 51c95d1..5f2fab3 100644 --- a/lua/ts.lua +++ b/lua/ts.lua @@ -133,11 +133,12 @@ local function build(repo, parser) end ---@param pack_name string ----@return string +---@return string? lang +---@return string? err local function lang_from_name(pack_name) local lang = pack_name:match("^tree%-sitter%-(.+)$") if not lang then - error("cannot derive lang from pack name: " .. pack_name) + return nil, "cannot derive lang from pack name: " .. pack_name end return lang end @@ -161,7 +162,7 @@ local function pick(child, parent) end ---@param entry string | ow.TS.RepoOpts ----@return ow.TS.Repo +---@return ow.TS.Repo? local function normalize(entry) ---@type ow.TS.RepoOpts local opts @@ -187,8 +188,17 @@ local function normalize(entry) end else ---@cast opts ow.TS.SingleRepoOpts + local lang = opts.lang + if not lang then + local derived, err = lang_from_name(name) + if not derived then + log.error("Skipping %s: %s", name, err) + return nil + end + lang = derived + end table.insert(parsers, { - lang = opts.lang or lang_from_name(name), + lang = lang, location = opts.location, generate = opts.generate, from_json = opts.from_json, @@ -206,7 +216,13 @@ end ---@param opts (string | ow.TS.RepoOpts)[] function M.setup(opts) ---@type ow.TS.Repo[] - local repos = vim.tbl_map(normalize, opts) + local repos = {} + for _, entry in ipairs(opts) do + local repo = normalize(entry) + if repo then + table.insert(repos, repo) + end + end ---@type vim.pack.Spec[] local pack_specs = vim.tbl_map(function(p)