Skip to content

Commit

Permalink
feat(actions): only show update/upgrade all crates when available
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Aug 2, 2024
1 parent 70e657b commit 82c7a93
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lua/crates/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function M.get_actions()
local actions = {}

local buf = util.current_buf()
local buf_cache = state.buf_cache[buf]
local line, col = util.cursor_pos()
local key, crate = util.get_crate_on_line(buf, line)

Expand Down Expand Up @@ -276,7 +277,7 @@ function M.get_actions()
end

if key and crate then
local info = util.get_crate_info(buf, key)
local info = buf_cache.info[key]
if info then
if info.vers_update then
table.insert(actions, {
Expand Down Expand Up @@ -327,14 +328,24 @@ function M.get_actions()
})
end

table.insert(actions, {
name = "update all crates",
action = M.update_all_crates,
})
table.insert(actions, {
name = "upgrade all crates",
action = M.upgrade_all_crates,
})
local has_update = false
local has_upgrade = false
for _, info in pairs(buf_cache.info) do
has_update = has_update or (info.vers_update ~= nil)
has_upgrade = has_upgrade or (info.vers_upgrade ~= nil)
end
if has_update then
table.insert(actions, {
name = "update all crates",
action = M.update_all_crates,
})
end
if has_upgrade then
table.insert(actions, {
name = "upgrade all crates",
action = M.upgrade_all_crates,
})
end

return actions
end
Expand Down

0 comments on commit 82c7a93

Please sign in to comment.