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(update): set version of all installed rocks.toml entries #382

Merged
merged 2 commits into from
Jun 19, 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
27 changes: 15 additions & 12 deletions lua/rocks/operations/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ operations.update = function(on_complete)

local ct = 0
for name, rock in pairs(outdated_rocks) do
local rocks_key, user_rock = get_rock_and_key(user_rocks, rock.name)
local _, user_rock = get_rock_and_key(user_rocks, rock.name)
if not user_rock or user_rock.pin then
goto skip_update
end
Expand All @@ -408,18 +408,10 @@ operations.update = function(on_complete)
name = name,
version = rock.target_version,
})
local success, ret = pcall(future.wait)
local success = pcall(future.wait)
ct = ct + 1
nio.scheduler()
if success then
---@type rock_name
local rock_name = ret.name
if user_rock and user_rock.version then
-- Rock is configured as a table -> Update version.
user_rocks[rocks_key][rock_name].version = ret.version
elseif user_rock then -- Only insert the version if there's an entry in rocks.toml
user_rocks[rocks_key][rock_name] = ret.version
end
progress_handle:report({
message = rock.version == rock.target_version
and ("Updated rock %s: %s"):format(rock.name, rock.version)
Expand Down Expand Up @@ -449,9 +441,20 @@ operations.update = function(on_complete)

if vim.tbl_isempty(outdated_rocks) and vim.tbl_isempty(external_update_handlers) then
progress_handle:report({ message = "Nothing to update!", percentage = 100 })
else
fs.write_file_await(config.config_path, "w", tostring(user_rocks))
end
-- Update the version for all installed rocks in case rocks.toml is out of date [#380]
for _, installed_rock in pairs(state.installed_rocks()) do
---@type rock_name
local rock_name = installed_rock.name
local rocks_key, user_rock = get_rock_and_key(user_rocks, installed_rock.name)
if user_rock and user_rock.version then
-- Rock is configured as a table -> Update version.
user_rocks[rocks_key][rock_name].version = installed_rock.version
elseif user_rock then -- Only insert the version if there's an entry in rocks.toml
user_rocks[rocks_key][rock_name] = installed_rock.version
end
end
fs.write_file_await(config.config_path, "w", tostring(user_rocks))
nio.scheduler()
if not vim.tbl_isempty(error_handles) then
local message = "Update completed with errors! Run ':Rocks log' for details."
Expand Down
Loading