Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auto_install): fall back to luarocks.org query if cache is not populated #15

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions lua/rocks_treesitter/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ local function is_installed(lang)
end

---@param lang string
---@return Rock[]
local function find_parser_rock(lang)
---@param callback fun(rock: Rock[])
local function find_parser_rock(lang, callback)
local rock_name = "tree-sitter-" .. lang
local rocks = api.try_get_cached_rocks()
return rocks[rock_name] or {}
if rocks and rocks[rock_name] then
callback(rocks[rock_name])
mrcjkb marked this conversation as resolved.
Show resolved Hide resolved
end
-- Cache may not have been populated. Query luarocks.
api.query_luarocks_rocks(function(luarocks_rocks)
callback(luarocks_rocks[rock_name] or {})
end)
end

---@param rock Rock
Expand Down Expand Up @@ -97,18 +103,19 @@ local function do_highlight(lang)
vim.treesitter.start()
return
end
local rocks = find_parser_rock(lang)
if vim.tbl_isempty(rocks) then
return
end
if config.auto_install == "prompt" then
vim.schedule(function()
prompt_auto_install(rocks)
end)
elseif config.auto_install then
-- TODO: replace "dev" with nil once we have tagged releases
api.install(rocks[1].name, "dev", try_start_highlight)
end
find_parser_rock(lang, function(rocks)
if vim.tbl_isempty(rocks) then
return
end
if config.auto_install == "prompt" then
vim.schedule(function()
prompt_auto_install(rocks)
end)
elseif config.auto_install then
-- TODO: replace "dev" with nil once we have tagged releases
api.install(rocks[1].name, "dev", try_start_highlight)
end
end)
end

function highlight.create_autocmd()
Expand Down
Loading