aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/ui_spec.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2021-09-27 21:57:28 +0200
committerGitHub <noreply@github.com>2021-09-27 21:57:28 +0200
commit63fde086d9e7936b21c51e145253ec69820b2112 (patch)
treefe42e09315181b66e32b5787508f6bd81e719c67 /test/functional/lua/ui_spec.lua
parent6736ee8be5ae9a3b004bd9033d7efffad74a03be (diff)
downloadrneovim-63fde086d9e7936b21c51e145253ec69820b2112.tar.gz
rneovim-63fde086d9e7936b21c51e145253ec69820b2112.tar.bz2
rneovim-63fde086d9e7936b21c51e145253ec69820b2112.zip
feat(ui): add vim.ui.select and use in code actions (#15771)
Continuation of https://github.com/neovim/neovim/pull/15202 A plugin like telescope could override it with a fancy implementation and then users would get the telescope-ui within each plugin that utilizes the vim.ui.select function. There are some plugins which override the `textDocument/codeAction` handler solely to provide a different UI. With custom client commands and soon codeAction resolve support, it becomes more difficult to implement the handler right - so having a dedicated way to override the picking function will be useful.
Diffstat (limited to 'test/functional/lua/ui_spec.lua')
-rw-r--r--test/functional/lua/ui_spec.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua
new file mode 100644
index 0000000000..25a208b70b
--- /dev/null
+++ b/test/functional/lua/ui_spec.lua
@@ -0,0 +1,46 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local clear = helpers.clear
+
+describe('vim.ui', function()
+ before_each(function()
+ clear()
+ end)
+
+
+ describe('select', function()
+ it('can select an item', function()
+ local result = exec_lua[[
+ local items = {
+ { name = 'Item 1' },
+ { name = 'Item 2' },
+ }
+ local opts = {
+ format_entry = function(entry)
+ return entry.name
+ end
+ }
+ local selected
+ local cb = function(item)
+ selected = item
+ end
+ -- inputlist would require input and block the test;
+ local choices
+ vim.fn.inputlist = function(x)
+ choices = x
+ return 1
+ end
+ vim.ui.select(items, opts, cb)
+ vim.wait(100, function() return selected ~= nil end)
+ return {selected, choices}
+ ]]
+ eq({ name = 'Item 1' }, result[1])
+ eq({
+ 'Select one of:',
+ '1: Item 1',
+ '2: Item 2',
+ }, result[2])
+ end)
+ end)
+end)