mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-21 23:37:18 +00:00
feat(command): use vim.ui.select
If Gitsigns is run without a subcommand, then vim.ui.select is called. Resolves #594
This commit is contained in:
parent
ef8a79b2cb
commit
ce636faddd
11
lua/gitsigns.lua
generated
11
lua/gitsigns.lua
generated
@ -355,10 +355,15 @@ local function parse_to_lua(a)
|
||||
return a
|
||||
end
|
||||
|
||||
local function run_cmd_func(params)
|
||||
local run_cmd_func = void(function(params)
|
||||
local pos_args_raw, named_args_raw = require('gitsigns.argparse').parse_args(params.args)
|
||||
|
||||
local func = pos_args_raw[1]
|
||||
|
||||
if not func then
|
||||
func = async.wrap(vim.ui.select, 3)(complete('', 'Gitsigns '), {})
|
||||
end
|
||||
|
||||
local pos_args = vim.tbl_map(parse_to_lua, vim.list_slice(pos_args_raw, 2))
|
||||
local named_args = vim.tbl_map(parse_to_lua, named_args_raw)
|
||||
|
||||
@ -385,11 +390,11 @@ local function run_cmd_func(params)
|
||||
end
|
||||
|
||||
error(string.format('%s is not a valid function or action', func))
|
||||
end
|
||||
end)
|
||||
|
||||
local function setup_command()
|
||||
nvim.command('Gitsigns', run_cmd_func,
|
||||
{ force = true, nargs = '+', range = true, complete = complete })
|
||||
{ force = true, nargs = '*', range = true, complete = complete })
|
||||
end
|
||||
|
||||
local function wrap_func(fn, ...)
|
||||
|
@ -355,10 +355,15 @@ local function parse_to_lua(a: string): any
|
||||
return a
|
||||
end
|
||||
|
||||
local function run_cmd_func(params: api.UserCmdParams)
|
||||
local run_cmd_func = void(function(params: api.UserCmdParams)
|
||||
local pos_args_raw, named_args_raw = require('gitsigns.argparse').parse_args(params.args)
|
||||
|
||||
local func = pos_args_raw[1]
|
||||
|
||||
if not func then
|
||||
func = async.wrap(vim.ui.select, 3)(complete('', 'Gitsigns '), {})
|
||||
end
|
||||
|
||||
local pos_args = vim.tbl_map(parse_to_lua, vim.list_slice(pos_args_raw, 2)) as {any}
|
||||
local named_args = vim.tbl_map(parse_to_lua, named_args_raw) as {string:any}
|
||||
|
||||
@ -385,11 +390,11 @@ local function run_cmd_func(params: api.UserCmdParams)
|
||||
end
|
||||
|
||||
error(string.format('%s is not a valid function or action', func))
|
||||
end
|
||||
end)
|
||||
|
||||
local function setup_command()
|
||||
nvim.command('Gitsigns', run_cmd_func,
|
||||
{ force = true, nargs = '+', range = true, complete = complete })
|
||||
{ force = true, nargs = '*', range = true, complete = complete })
|
||||
end
|
||||
|
||||
local function wrap_func(fn: function, ...: any): function()
|
||||
|
@ -578,6 +578,12 @@ global record vim
|
||||
|
||||
record ui
|
||||
input: function({string:any}, function(string))
|
||||
record SelectOpts<T>
|
||||
prompt: string
|
||||
format_item: function(T): string
|
||||
kind: string
|
||||
end
|
||||
select: function<T>({T}, SelectOpts<T>, on_choice: function(T, idx: integer))
|
||||
end
|
||||
|
||||
record VersionDetails
|
||||
|
Loading…
Reference in New Issue
Block a user