Skip to content

Commit

Permalink
Merge pull request #15 from nvim-neorocks/luarocks-fallback
Browse files Browse the repository at this point in the history
fix(auto_install): fall back to luarocks.org query if cache is not populated
  • Loading branch information
mrcjkb authored Jun 17, 2024
2 parents 53a0913 + c9ab744 commit 99916f1
Showing 1 changed file with 22 additions and 15 deletions.
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])
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

0 comments on commit 99916f1

Please sign in to comment.