refactor(ts): split runtime install path off ow.TS.Repo
This commit is contained in:
+27
-20
@@ -15,6 +15,9 @@ local M = {}
|
|||||||
---@class ow.TS.Repo : ow.TS.RepoBase
|
---@class ow.TS.Repo : ow.TS.RepoBase
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field parsers ow.TS.Parser[]
|
---@field parsers ow.TS.Parser[]
|
||||||
|
|
||||||
|
---@class RepoState
|
||||||
|
---@field repo ow.TS.Repo
|
||||||
---@field path? string
|
---@field path? string
|
||||||
|
|
||||||
---@class ow.TS.SingleRepoOpts : ow.TS.RepoBase
|
---@class ow.TS.SingleRepoOpts : ow.TS.RepoBase
|
||||||
@@ -61,10 +64,10 @@ local function activate_open_buffers(lang)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param repo ow.TS.Repo
|
---@param state RepoState
|
||||||
---@param parser ow.TS.Parser
|
---@param parser ow.TS.Parser
|
||||||
local function build(repo, parser)
|
local function build(state, parser)
|
||||||
local path = assert(repo.path, "repo not installed: " .. repo.name)
|
local path = assert(state.path, "repo not installed: " .. state.repo.name)
|
||||||
local cwd = parser.location and vim.fs.joinpath(path, parser.location)
|
local cwd = parser.location and vim.fs.joinpath(path, parser.location)
|
||||||
or path
|
or path
|
||||||
local out = parser_so(path, parser.lang)
|
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 }
|
return { src = p[1], name = p.name, version = p.version }
|
||||||
end, repos)
|
end, repos)
|
||||||
|
|
||||||
---@type table<string, ow.TS.Repo>
|
---@type RepoState[]
|
||||||
|
local states = {}
|
||||||
|
---@type table<string, RepoState>
|
||||||
local by_src = {}
|
local by_src = {}
|
||||||
for _, p in ipairs(repos) do
|
for _, repo in ipairs(repos) do
|
||||||
by_src[p[1]] = p
|
local state = { repo = repo }
|
||||||
|
table.insert(states, state)
|
||||||
|
by_src[repo[1]] = state
|
||||||
end
|
end
|
||||||
|
|
||||||
local pack = require("pack")
|
local pack = require("pack")
|
||||||
local changed = pack.install(pack_specs, function(data)
|
local changed = pack.install(pack_specs, function(data)
|
||||||
local repo = by_src[data.spec.src]
|
local state = by_src[data.spec.src]
|
||||||
if repo then
|
if state then
|
||||||
repo.path = data.path
|
state.path = data.path
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
for _, repo in ipairs(repos) do
|
for _, state in ipairs(states) do
|
||||||
pack.register_hook(repo.name, function(ev)
|
pack.register_hook(state.repo.name, function(ev)
|
||||||
repo.path = ev.path
|
state.path = ev.path
|
||||||
for _, parser in ipairs(repo.parsers) do
|
for _, parser in ipairs(state.repo.parsers) do
|
||||||
build(repo, parser)
|
build(state, parser)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if not repo.path then
|
if not state.path then
|
||||||
log.error("Repo not installed: %s", repo.name)
|
log.error("Repo not installed: %s", state.repo.name)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
for _, parser in ipairs(repo.parsers) do
|
for _, parser in ipairs(state.repo.parsers) do
|
||||||
local so = parser_so(repo.path, parser.lang)
|
local so = parser_so(state.path, parser.lang)
|
||||||
if changed[repo.name] or not vim.uv.fs_stat(so) then
|
if changed[state.repo.name] or not vim.uv.fs_stat(so) then
|
||||||
build(repo, parser)
|
build(state, parser)
|
||||||
else
|
else
|
||||||
vim.treesitter.language.add(parser.lang, { path = so })
|
vim.treesitter.language.add(parser.lang, { path = so })
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user