feat(snipe): add snipe select backend#186
feat(snipe): add snipe select backend#186muratoffalex wants to merge 3 commits intostevearc:masterfrom muratoffalex:feat/snipe-select-backend
Conversation
| @@ -0,0 +1,56 @@ | |||
| local M = {} | |||
|
|
|||
| local snipe = require("snipe") | |||
There was a problem hiding this comment.
No top-level requires here. This module needs to be able to be required even if snipe is not installed (because we need to check the is_supported method below)
| return pcall(require, "snipe") | ||
| end | ||
|
|
||
| M._init_snipe_menu = function(config, on_choice) |
There was a problem hiding this comment.
Is there any reason this needs to be on the module? If not, this could just be a local function.
| if config.add_new_buffer_callback then | ||
| snipe_menu:add_new_buffer_callback(function(m) | ||
| config.add_new_buffer_callback(m, on_choice) | ||
| end) | ||
| end |
There was a problem hiding this comment.
This seems odd. Why are we passing on_choice here? That's the callback for the vim.ui.select call, but this is only going to be called once on startup?
| -- Set cursor to the first item | ||
| vim.api.nvim_win_set_cursor(snipe.ui_select_menu.win, { 1, 0 }) |
There was a problem hiding this comment.
What is the default behavior without these lines?
|
|
||
| vim.api.nvim_create_autocmd("BufLeave", { | ||
| desc = "Cancel vim.ui.select", | ||
| once = true, |
There was a problem hiding this comment.
Can we also pass buffer = 0? We want to make sure this is only called when leaving the snipe buffer
| on_choice(nil, nil) | ||
| snipe.ui_select_menu:close() |
There was a problem hiding this comment.
Is it possible for on_choice to get double-called here? Naively I would expect that if you use snipe to select an item it will call on_choice, then close the buffer, which will trigger BufLeave and call on_choice again.
| on_choice(nil, nil) | ||
| snipe.ui_select_menu:close() | ||
| -- Reset the title to avoid the title being set for the next menu | ||
| snipe.ui_select_menu.config.open_win_override.title = nil |
There was a problem hiding this comment.
Very odd...the snipe vim.ui.select wrapper stores the window title and re-uses it?
add snipe select backend
Description
Snipe can be used as vim.ui.select, an example is given in the snipe documentation