feat(ui): add vim.ui.input and use in lsp rename (#15959)

* vim.ui.input is an overridable function that prompts for user input
* take an opts table and the `on_confirm` callback, see `:help vim.ui.input` for more details
* defaults to a wrapper around vim.fn.input(opts)
* switches the built-in client's rename handler to use vim.ui.input by default
This commit is contained in:
Sebastian Lyng Johansen
2021-11-07 16:13:53 +01:00
committed by GitHub
parent b74916cfd2
commit 16d4af6d2f
6 changed files with 106 additions and 13 deletions

View File

@@ -43,4 +43,29 @@ describe('vim.ui', function()
}, result[2])
end)
end)
describe('input', function()
it('can input text', function()
local result = exec_lua[[
local opts = {
prompt = 'Input: ',
}
local input
local cb = function(item)
input = item
end
-- input would require input and block the test;
local prompt
vim.fn.input = function(opts)
prompt = opts.prompt
return "Inputted text"
end
vim.ui.input(opts, cb)
vim.wait(100, function() return input ~= nil end)
return {input, prompt}
]]
eq('Inputted text', result[1])
eq('Input: ', result[2])
end)
end)
end)