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(prune): delegate to extensions' handlers #400

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions lua/rocks/operations/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,16 @@ helpers.remove_recursive = nio.create(function(name, keep, progress_handle)
return success
end, 3)

---@async
---@param rock_name rock_name
---@return boolean
helpers.is_installed = nio.create(function(rock_name)
local future = nio.control.future()
---@param sc vim.SystemCompleted
luarocks.cli({ "show", rock_name }, function(sc)
future.set(sc.code == 0)
end)
return future.wait()
end, 1)

return helpers
22 changes: 18 additions & 4 deletions lua/rocks/operations/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,24 @@ operations.prune = function(rock_name)
if user_config.rocks then
user_config.rocks[rock_name] = nil
end
local user_rock_names =
---@diagnostic disable-next-line: invisible
nio.fn.keys(vim.tbl_deep_extend("force", user_config.rocks or {}, user_config.plugins or {}))
local success = helpers.remove_recursive(rock_name, user_rock_names, progress_handle)
local success = true -- initialised for handlers
if helpers.is_installed(rock_name) then
local user_rock_names =
---@diagnostic disable-next-line: invisible
nio.fn.keys(vim.tbl_deep_extend("force", user_config.rocks or {}, user_config.plugins or {}))
success = helpers.remove_recursive(rock_name, user_rock_names, progress_handle)
end
-- NOTE: We always delegate to handlers, even if the rock is installed,
-- so we can allow them to manage luarocks packages.
local function report_progress(message)
progress_handle:report({ message = message })
end
local function report_error(message)
progress_handle:report({ message = message, title = "Error" })
success = false
end
local user_rocks = config.get_user_rocks()
handlers.prune_user_rocks(user_rocks, report_progress, report_error)
fs.write_file_await(config.config_path, "w", tostring(user_config))
cache.populate_removable_rock_cache()
vim.schedule(function()
Expand Down
Loading