diff options
| author | William Boman <william@redwill.se> | 2022-11-29 19:54:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-29 19:54:12 +0100 |
| commit | 23bb2dba52c5351f4c8f97712abee4d2d65a97cf (patch) | |
| tree | 20b5e2d7259d8e0ef6c126e16b3957ae225e7bb0 /lua | |
| parent | chore: use pwsh instead of powershell (#706) (diff) | |
| download | mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar.gz mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar.bz2 mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar.lz mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar.xz mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.tar.zst mason-23bb2dba52c5351f4c8f97712abee4d2d65a97cf.zip | |
feat(ui): add keybind on section headers for cancelling installation of the entire group (#707)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason/ui/components/main/package_list.lua | 9 | ||||
| -rw-r--r-- | lua/mason/ui/instance.lua | 36 |
2 files changed, 27 insertions, 18 deletions
diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua index 3a99558f..5b4600cf 100644 --- a/lua/mason/ui/components/main/package_list.lua +++ b/lua/mason/ui/components/main/package_list.lua @@ -197,6 +197,7 @@ local function Installing(state) heading = Ui.Node { Ui.HlTextNode(p.heading "Installing"), Ui.StickyCursor { id = "installing-section" }, + Ui.Keybind(settings.current.ui.keymaps.cancel_installation, "TERMINATE_PACKAGE_HANDLES", packages), }, hide_when_empty = true, packages = packages, @@ -231,7 +232,11 @@ local function Queued(state) local packages = state.packages.queued return PackageListContainer { state = state, - heading = Ui.HlTextNode(p.heading "Queued"), + heading = Ui.Node { + Ui.HlTextNode(p.heading "Queued"), + Ui.StickyCursor { id = "queued-section" }, + Ui.Keybind(settings.current.ui.keymaps.cancel_installation, "TERMINATE_PACKAGE_HANDLES", packages), + }, packages = packages, hide_when_empty = true, ---@param pkg Package @@ -241,7 +246,7 @@ local function Queued(state) { p.highlight(settings.current.ui.icons.package_pending), p.none(" " .. pkg.name) }, }, Ui.StickyCursor { id = ("%s-installing"):format(pkg.spec.name) }, - Ui.Keybind(settings.current.ui.keymaps.cancel_installation, "DEQUEUE_PACKAGE", pkg), + Ui.Keybind(settings.current.ui.keymaps.cancel_installation, "TERMINATE_PACKAGE_HANDLE", pkg), } end, } diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua index d338f8a2..4b2f43e4 100644 --- a/lua/mason/ui/instance.lua +++ b/lua/mason/ui/instance.lua @@ -351,15 +351,32 @@ end local function terminate_package_handle(event) ---@type Package local pkg = event.payload + vim.schedule_wrap(notify)(("Cancelling installation of %q."):format(pkg.name)) pkg:get_handle():if_present( ---@param handle InstallHandle function(handle) - vim.schedule_wrap(notify)(("Cancelling installation of %q."):format(pkg.name)) - handle:terminate() + if not handle:is_closed() then + handle:terminate() + end end ) end +local function terminate_all_package_handles(event) + ---@type Package[] + local pkgs = _.list_copy(event.payload) -- we copy because list is mutated while iterating it + for _, pkg in ipairs(pkgs) do + pkg:get_handle():if_present( + ---@param handle InstallHandle + function(handle) + if not handle:is_closed() then + handle:terminate() + end + end + ) + end +end + local function install_package(event) ---@type Package local pkg = event.payload @@ -373,19 +390,6 @@ local function uninstall_package(event) vim.schedule_wrap(notify)(("%q was successfully uninstalled."):format(pkg.name)) end -local function dequeue_package(event) - ---@type Package - local pkg = event.payload - pkg:get_handle():if_present( - ---@param handle InstallHandle - function(handle) - if not handle:is_closed() then - handle:terminate() - end - end - ) -end - local function toggle_expand_package(event) ---@type Package local pkg = event.payload @@ -544,10 +548,10 @@ local effects = { ["CHECK_NEW_VISIBLE_PACKAGE_VERSIONS"] = a.scope(check_new_visible_package_versions), ["CLEAR_LANGUAGE_FILTER"] = clear_filter, ["CLOSE_WINDOW"] = window.close, - ["DEQUEUE_PACKAGE"] = dequeue_package, ["INSTALL_PACKAGE"] = install_package, ["LANGUAGE_FILTER"] = filter, ["SET_VIEW"] = set_view, + ["TERMINATE_PACKAGE_HANDLES"] = terminate_all_package_handles, ["TERMINATE_PACKAGE_HANDLE"] = terminate_package_handle, ["TOGGLE_EXPAND_CURRENT_SETTINGS"] = toggle_expand_current_settings, ["TOGGLE_EXPAND_PACKAGE"] = toggle_expand_package, |
