diff --git a/lua/ts.lua b/lua/ts.lua index 5f2fab3..9b4610a 100644 --- a/lua/ts.lua +++ b/lua/ts.lua @@ -15,6 +15,9 @@ local M = {} ---@class ow.TS.Repo : ow.TS.RepoBase ---@field name string ---@field parsers ow.TS.Parser[] + +---@class RepoState +---@field repo ow.TS.Repo ---@field path? string ---@class ow.TS.SingleRepoOpts : ow.TS.RepoBase @@ -61,10 +64,10 @@ local function activate_open_buffers(lang) end end ----@param repo ow.TS.Repo +---@param state RepoState ---@param parser ow.TS.Parser -local function build(repo, parser) - local path = assert(repo.path, "repo not installed: " .. repo.name) +local function build(state, parser) + local path = assert(state.path, "repo not installed: " .. state.repo.name) local cwd = parser.location and vim.fs.joinpath(path, parser.location) or path local out = parser_so(path, parser.lang) @@ -229,35 +232,39 @@ function M.setup(opts) return { src = p[1], name = p.name, version = p.version } end, repos) - ---@type table + ---@type RepoState[] + local states = {} + ---@type table local by_src = {} - for _, p in ipairs(repos) do - by_src[p[1]] = p + for _, repo in ipairs(repos) do + local state = { repo = repo } + table.insert(states, state) + by_src[repo[1]] = state end local pack = require("pack") local changed = pack.install(pack_specs, function(data) - local repo = by_src[data.spec.src] - if repo then - repo.path = data.path + local state = by_src[data.spec.src] + if state then + state.path = data.path end end) - for _, repo in ipairs(repos) do - pack.register_hook(repo.name, function(ev) - repo.path = ev.path - for _, parser in ipairs(repo.parsers) do - build(repo, parser) + for _, state in ipairs(states) do + pack.register_hook(state.repo.name, function(ev) + state.path = ev.path + for _, parser in ipairs(state.repo.parsers) do + build(state, parser) end end) - if not repo.path then - log.error("Repo not installed: %s", repo.name) + if not state.path then + log.error("Repo not installed: %s", state.repo.name) goto continue end - for _, parser in ipairs(repo.parsers) do - local so = parser_so(repo.path, parser.lang) - if changed[repo.name] or not vim.uv.fs_stat(so) then - build(repo, parser) + for _, parser in ipairs(state.repo.parsers) do + local so = parser_so(state.path, parser.lang) + if changed[state.repo.name] or not vim.uv.fs_stat(so) then + build(state, parser) else vim.treesitter.language.add(parser.lang, { path = so }) end