Skip to content

Commit a447ccc

Browse files
committed
feat(pick)!: set custom vim.ui.select implementation
Details: - This is a breaking change only if user didn't opt-in for `vim.ui.select` from 'mini.pick'. Either deliberately (which hopefully should be rare) or unknowingly (which this change should resolve). It can still be explicitly opted out by manually setting `vim.ui.select` *after* `require('mini.pick').setup()`.
1 parent ff05ba1 commit a447ccc

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ There are following change types:
1515

1616
This change is made to improve long term project stability. See more details [here](https://github.com/nvim-mini/mini.nvim/discussions/1970).
1717

18+
- Start setting custom Neovim method implementation during `setup()` (if module provides one). This is usually the expected behavior for majority of use cases and should improve "out of the box" experience. Modules should still export a function to manually adjust the implementation.
19+
20+
It is a breaking change only if the implementation was not explicitly used. Can still be done if set or restored *after* calling module's `setup()`.
21+
22+
Affected modules:
23+
24+
- 'mini.notify' sets `vim.notify`.
25+
- 'mini.pick' sets `vim.ui.select`.
26+
1827
### Refine
1928

2029
- Stop official support of Neovim 0.8.
@@ -115,14 +124,6 @@ There are following change types:
115124

116125
- Update `zoom()` to return whether current buffer is zoomed in. By @loichyan, PR #1954.
117126

118-
## mini.notify
119-
120-
### Evolve
121-
122-
- Update `setup()` to set `vim.notify` to a custom implementation, which is arguably the expected behavior for majority of use cases. This makes it unnecessary to manually `vim.notify = MiniNotify.make_notify()` after the `setup()`, but still can be done to adjust the behavior with custom options.
123-
124-
This is a breaking change for users who do not use 'mini.notify' for `vim.notify` implementation. To keep doing that, set `vim.notify` *after* executing `require('mini.notify').setup()`.
125-
126127
## mini.pick
127128

128129
### Expand

doc/mini-pick.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Features:
2525

2626
- |:Pick| command to work with extensible |MiniPick.registry|.
2727

28-
- |vim.ui.select()| wrapper (see |MiniPick.ui_select()|).
28+
- |vim.ui.select()| implementation. To adjust, use |MiniPick.ui_select()|
29+
or save-restore `vim.ui.select` manually after calling |MiniPick.setup()|.
2930

3031
- Rich and customizable built-in |MiniPick-actions| when picker is active:
3132
- Manually change currently focused item.
@@ -684,6 +685,10 @@ Example: >vim
684685
:Pick files tool='git'
685686
:Pick grep pattern='<cword>'
686687
<
688+
689+
It also sets custom |vim.ui.select()| implementation to use the module.
690+
See |MiniPick.ui_select()|.
691+
687692
Parameters ~
688693
{config} `(table|nil)` Module config table. See |MiniPick.config|.
689694

@@ -1056,6 +1061,7 @@ Select rewrite
10561061

10571062
Function which can be used to directly override |vim.ui.select()| to use
10581063
'mini.pick' for any "select" type of tasks.
1064+
Set automatically in |MiniPick.setup()|.
10591065

10601066
Implements required by `vim.ui.select()` signature, with some differencies:
10611067
- Allows `opts.preview_item` that returns an array of lines for item preview.
@@ -1066,14 +1072,18 @@ Notes:
10661072

10671073
Usage ~
10681074
>lua
1069-
vim.ui.select = MiniPick.ui_select
1070-
10711075
-- Customize with fourth argument inside a function wrapper
10721076
vim.ui.select = function(items, opts, on_choice)
10731077
local start_opts = { window = { config = { width = vim.o.columns } } }
10741078
return MiniPick.ui_select(items, opts, on_choice, start_opts)
10751079
end
10761080
<
1081+
To preserve original `vim.ui.select()`: >lua
1082+
1083+
local ui_select_orig = vim.ui.select
1084+
require('mini.pick').setup()
1085+
vim.ui.select = ui_select_orig
1086+
<
10771087
------------------------------------------------------------------------------
10781088
*MiniPick.builtin*
10791089
`MiniPick.builtin`

lua/mini/pick.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
---
2626
--- - |:Pick| command to work with extensible |MiniPick.registry|.
2727
---
28-
--- - |vim.ui.select()| wrapper (see |MiniPick.ui_select()|).
28+
--- - |vim.ui.select()| implementation. To adjust, use |MiniPick.ui_select()|
29+
--- or save-restore `vim.ui.select` manually after calling |MiniPick.setup()|.
2930
---
3031
--- - Rich and customizable built-in |MiniPick-actions| when picker is active:
3132
--- - Manually change currently focused item.
@@ -694,6 +695,10 @@ local H = {}
694695
--- :Pick files tool='git'
695696
--- :Pick grep pattern='<cword>'
696697
--- <
698+
---
699+
--- It also sets custom |vim.ui.select()| implementation to use the module.
700+
--- See |MiniPick.ui_select()|.
701+
---
697702
---@param config table|nil Module config table. See |MiniPick.config|.
698703
---
699704
---@usage >lua
@@ -726,6 +731,9 @@ MiniPick.setup = function(config)
726731
if not MiniPick.is_picker_active() then return paste_orig(...) end
727732
H.notify('Use `mappings.paste` (`<C-r>` by default) with "*" or "+" register.', 'HINT')
728733
end
734+
735+
-- Set custom implementation
736+
vim.ui.select = MiniPick.ui_select
729737
end
730738

731739
--stylua: ignore
@@ -1228,6 +1236,7 @@ end
12281236
---
12291237
--- Function which can be used to directly override |vim.ui.select()| to use
12301238
--- 'mini.pick' for any "select" type of tasks.
1239+
--- Set automatically in |MiniPick.setup()|.
12311240
---
12321241
--- Implements required by `vim.ui.select()` signature, with some differencies:
12331242
--- - Allows `opts.preview_item` that returns an array of lines for item preview.
@@ -1237,14 +1246,18 @@ end
12371246
--- - `on_choice` is called when target window is current.
12381247
---
12391248
---@usage >lua
1240-
--- vim.ui.select = MiniPick.ui_select
1241-
---
12421249
--- -- Customize with fourth argument inside a function wrapper
12431250
--- vim.ui.select = function(items, opts, on_choice)
12441251
--- local start_opts = { window = { config = { width = vim.o.columns } } }
12451252
--- return MiniPick.ui_select(items, opts, on_choice, start_opts)
12461253
--- end
12471254
--- <
1255+
--- To preserve original `vim.ui.select()`: >lua
1256+
---
1257+
--- local ui_select_orig = vim.ui.select
1258+
--- require('mini.pick').setup()
1259+
--- vim.ui.select = ui_select_orig
1260+
--- <
12481261
MiniPick.ui_select = function(items, opts, on_choice, start_opts)
12491262
local format_item = opts.format_item or H.item_to_string
12501263
local items_ext = {}

readmes/mini-pick.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ https://github.com/nvim-mini/mini.nvim/assets/24854248/65849d1e-3f96-4085-a4cf-f
4141

4242
- `:Pick` command to work with extensible `MiniPick.registry`.
4343

44-
- `vim.ui.select()` wrapper.
44+
- `vim.ui.select()` implementation. To adjust, use `MiniPick.ui_select()` or save-restore `vim.ui.select` manually after calling `MiniPick.setup()`.
4545

4646
- Rich and customizable built-in actions when picker is active:
4747
- Manually change currently focused item.

tests/test_pick.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ T['setup()']['creates side effects'] = function()
260260
validate_hl_group('MiniPickPrompt', 'links to DiagnosticFloatingInfo')
261261
validate_hl_group('MiniPickPromptCaret', 'links to MiniPickPrompt')
262262
validate_hl_group('MiniPickPromptPrefix', 'links to MiniPickPrompt')
263+
264+
-- `vim.ui.select` implementation
265+
child.lua_notify('vim.ui.select({ "a", "b" }, {}, function() end)')
266+
eq(child.lua_get('MiniPick.get_picker_items() ~= nil'), true)
263267
end
264268

265269
T['setup()']['creates `config` field'] = function()

0 commit comments

Comments
 (0)