Skip to content

Commit

Permalink
fix(sync): don't try to remove indirect dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 11, 2023
1 parent a08ee0d commit a1c0d2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 5 additions & 7 deletions lua/rocks/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,14 @@ operations.sync = function(user_rocks)
-- Determine dependencies of installed user rocks, so they can be excluded from rocks to prune
-- NOTE(mrcjkb): This has to be done after installation,
-- so that we don't prune dependencies of newly installed rocks.
-- TODO: This doesn't guarantee that all rocks that can be pruned will be pruned.
-- Typically, another sync will fix this. Maybe we should do some sort of repeat... until?
installed_rocks = state.installed_rocks()
local dependencies = vim.empty_dict()
---@cast dependencies {[string]: RockDependency}
for _, key in ipairs(key_list) do
if user_rocks[key] and installed_rocks[key] then
-- NOTE(vhyrro): It is not possible to use the vim.tbl_extend or vim.tbl_deep_extend
-- functions here within the async context. It simply refuses to work.
for k, v in pairs(state.rock_dependencies(installed_rocks[key])) do
dependencies[k] = v
end
for _, installed_rock in pairs(installed_rocks) do
for k, v in pairs(state.rock_dependencies(installed_rock)) do
dependencies[k] = v
end
end

Expand Down
5 changes: 2 additions & 3 deletions lua/rocks/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ state.rock_dependencies = nio.create(function(rock)

luarocks.cli({
"show",
"--deps",
"--porcelain",
rock_name,
}, function(obj)
Expand All @@ -114,7 +113,7 @@ state.rock_dependencies = nio.create(function(rock)
end

for line in string.gmatch(result, "%S*[^\n]+") do
local name, version = line:match("(%S+)%s%S+%s(%S+)")
local name, version = line:match("dependency%s+(%S+).*using%s+([^-%s]+)")
if not name then
name = line:match("(%S+)")
end
Expand All @@ -136,7 +135,7 @@ state.query_removable_rocks = nio.create(function()
---@cast dependent_rocks string[]
for _, rock in pairs(installed_rocks) do
for _, dep in pairs(state.rock_dependencies(rock)) do
dependent_rocks[#dependent_rocks + 1] = dep.name
table.insert(dependent_rocks, dep.name)
end
end
---@diagnostic disable-next-line: invisible
Expand Down

0 comments on commit a1c0d2f

Please sign in to comment.