-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(snipe): add snipe select backend #186
base: master
Are you sure you want to change the base?
feat(snipe): add snipe select backend #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits and Qs
@@ -0,0 +1,56 @@ | |||
local M = {} | |||
|
|||
local snipe = require("snipe") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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