From 823267cf3b77cf9a7ae28454926eabc18fec1ba0 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Wed, 15 May 2024 21:17:29 -0500 Subject: [PATCH] Fix bug where selecting a binary to download picks the wrong one behind the scenes --- lua/distant-core/installer.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lua/distant-core/installer.lua b/lua/distant-core/installer.lua index 72a1c72..d7a8fe3 100644 --- a/lua/distant-core/installer.lua +++ b/lua/distant-core/installer.lua @@ -387,19 +387,23 @@ local function download_binary(opts, cb) return end - local choices = vim.tbl_map( - function(entry) return entry.description end, - vim.tbl_filter(function(entry) - local version = parse_tag_into_version(entry.tag) - return not min_version or ((not not version) and version:compatible(min_version)) - end, entries) - ) + ---@type {choice:string, entry:ReleaseEntry}[] + local entry_choices = {} + for _, entry in ipairs(entries) do + local version = parse_tag_into_version(entry.tag) + if not min_version or ((not not version) and version:compatible(min_version)) then + table.insert(entry_choices, { choice = entry.description, entry = entry }) + end + end + local choice = prompt_choices({ prompt = 'Which version of the binary do you want?', - choices = choices, + choices = vim.tbl_map(function(ec) return ec.choice end, entry_choices), max_choices = MAX_DOWNLOAD_CHOICES, }) - local entry = entries[choice] + + -- Take the choice from the filtered set and figure out which entry + local entry = entry_choices[choice] and entry_choices[choice].entry if not entry then cb('Cancelled selecting binary version', nil) return