Skip to content

Commit e1602c8

Browse files
authored
feat(ui): add setting to toggle help view (#1468)
Closes #1435.
1 parent 4a8deb6 commit e1602c8

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

lua/mason/settings.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,37 @@ local M = {}
44

55
---@class MasonSettings
66
local DEFAULT_SETTINGS = {
7+
---@since 1.0.0
78
-- The directory in which to install packages.
89
install_root_dir = path.concat { vim.fn.stdpath "data", "mason" },
910

11+
---@since 1.0.0
1012
-- Where Mason should put its bin location in your PATH. Can be one of:
1113
-- - "prepend" (default, Mason's bin location is put first in PATH)
1214
-- - "append" (Mason's bin location is put at the end of PATH)
1315
-- - "skip" (doesn't modify PATH)
1416
---@type '"prepend"' | '"append"' | '"skip"'
1517
PATH = "prepend",
1618

19+
---@since 1.0.0
1720
-- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
1821
-- debugging issues with package installations.
1922
log_level = vim.log.levels.INFO,
2023

24+
---@since 1.0.0
2125
-- Limit for the maximum amount of packages to be installed at the same time. Once this limit is reached, any further
2226
-- packages that are requested to be installed will be put in a queue.
2327
max_concurrent_installers = 4,
2428

29+
---@since 1.0.0
2530
-- [Advanced setting]
2631
-- The registries to source packages from. Accepts multiple entries. Should a package with the same name exist in
2732
-- multiple registries, the registry listed first will be used.
2833
registries = {
2934
"github:mason-org/mason-registry",
3035
},
3136

37+
---@since 1.0.0
3238
-- The provider implementations to use for resolving supplementary package metadata (e.g., all available versions).
3339
-- Accepts multiple entries, where later entries will be used as fallback should prior providers fail.
3440
-- Builtin providers are:
@@ -40,6 +46,7 @@ local DEFAULT_SETTINGS = {
4046
},
4147

4248
github = {
49+
---@since 1.0.0
4350
-- The template URL to use when downloading assets from GitHub.
4451
-- The placeholders are the following (in order):
4552
-- 1. The repository (e.g. "rust-lang/rust-analyzer")
@@ -49,9 +56,11 @@ local DEFAULT_SETTINGS = {
4956
},
5057

5158
pip = {
59+
---@since 1.0.0
5260
-- Whether to upgrade pip to the latest version in the virtual environment before installing packages.
5361
upgrade_pip = false,
5462

63+
---@since 1.0.0
5564
-- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior
5665
-- and is not recommended.
5766
--
@@ -60,52 +69,72 @@ local DEFAULT_SETTINGS = {
6069
},
6170

6271
ui = {
72+
---@since 1.0.0
6373
-- Whether to automatically check for new versions when opening the :Mason window.
6474
check_outdated_packages_on_open = true,
6575

76+
---@since 1.0.0
6677
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
6778
border = "none",
6879

80+
---@since 1.0.0
6981
-- Width of the window. Accepts:
7082
-- - Integer greater than 1 for fixed width.
7183
-- - Float in the range of 0-1 for a percentage of screen width.
7284
width = 0.8,
7385

86+
---@since 1.0.0
7487
-- Height of the window. Accepts:
7588
-- - Integer greater than 1 for fixed height.
7689
-- - Float in the range of 0-1 for a percentage of screen height.
7790
height = 0.9,
7891

7992
icons = {
93+
---@since 1.0.0
8094
-- The list icon to use for installed packages.
8195
package_installed = "",
96+
---@since 1.0.0
8297
-- The list icon to use for packages that are installing, or queued for installation.
8398
package_pending = "",
99+
---@since 1.0.0
84100
-- The list icon to use for packages that are not installed.
85101
package_uninstalled = "",
86102
},
87103

88104
keymaps = {
105+
---@since 1.0.0
89106
-- Keymap to expand a package
90107
toggle_package_expand = "<CR>",
108+
---@since 1.0.0
91109
-- Keymap to install the package under the current cursor position
92110
install_package = "i",
111+
---@since 1.0.0
93112
-- Keymap to reinstall/update the package under the current cursor position
94113
update_package = "u",
114+
---@since 1.0.0
95115
-- Keymap to check for new version for the package under the current cursor position
96116
check_package_version = "c",
117+
---@since 1.0.0
97118
-- Keymap to update all installed packages
98119
update_all_packages = "U",
120+
---@since 1.0.0
99121
-- Keymap to check which installed packages are outdated
100122
check_outdated_packages = "C",
123+
---@since 1.0.0
101124
-- Keymap to uninstall a package
102125
uninstall_package = "X",
126+
---@since 1.0.0
103127
-- Keymap to cancel a package installation
104128
cancel_installation = "<C-c>",
129+
---@since 1.0.0
105130
-- Keymap to apply language filter
106131
apply_language_filter = "<C-f>",
132+
---@since 1.1.0
107133
-- Keymap to toggle viewing package installation log
108134
toggle_package_install_log = "<CR>",
135+
---@since 1.8.0
136+
-- Keymap to toggle the help view
137+
toggle_help = "g?",
109138
},
110139
},
111140
}

lua/mason/ui/components/header.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ return function(state)
1717
p.header " mason.nvim ",
1818
state.view.is_searching and p.Comment " (search mode, press <Esc> to clear)" or p.none "",
1919
}),
20-
Ui.When(
21-
state.view.is_showing_help,
22-
{ p.none " press ", p.highlight_secondary "g?", p.none " for package list" },
23-
{ p.none "press ", p.highlight "g?", p.none " for help" }
24-
),
20+
Ui.When(state.view.is_showing_help, {
21+
p.none " press ",
22+
p.highlight_secondary(settings.current.ui.keymaps.toggle_help),
23+
p.none " for package list",
24+
}, {
25+
p.none "press ",
26+
p.highlight(settings.current.ui.keymaps.toggle_help),
27+
p.none " for help",
28+
}),
2529
{ p.Comment "https://github.com/williamboman/mason.nvim" },
2630
},
2731
}),

lua/mason/ui/components/help/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
---@param state InstallerUiState
4848
local function GenericHelp(state)
4949
local keymap_tuples = {
50-
{ "Toggle help", "g?" },
50+
{ "Toggle help", settings.current.ui.keymaps.toggle_help },
5151
{ "Toggle package info", settings.current.ui.keymaps.toggle_package_expand },
5252
{ "Toggle package installation log", settings.current.ui.keymaps.toggle_package_install_log },
5353
{ "Apply language filter", settings.current.ui.keymaps.apply_language_filter },

lua/mason/ui/instance.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require "mason.ui.colors"
2121
---@param state InstallerUiState
2222
local function GlobalKeybinds(state)
2323
return Ui.Node {
24-
Ui.Keybind("g?", "TOGGLE_HELP", nil, true),
24+
Ui.Keybind(settings.current.ui.keymaps.toggle_help, "TOGGLE_HELP", nil, true),
2525
Ui.Keybind("q", "CLOSE_WINDOW", nil, true),
2626
Ui.When(not state.view.language_filter, Ui.Keybind("<Esc>", "CLOSE_WINDOW", nil, true)),
2727
Ui.When(state.view.language_filter, Ui.Keybind("<Esc>", "CLEAR_LANGUAGE_FILTER", nil, true)),

0 commit comments

Comments
 (0)