Skip to content

Commit

Permalink
Use vim.ui.input for launch.json promptString
Browse files Browse the repository at this point in the history
Closes #1040
  • Loading branch information
mfussenegger committed Nov 1, 2023
1 parent 4cba91e commit 5f68498
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
16 changes: 15 additions & 1 deletion lua/dap/ext/vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ local function create_input(type_, input)
if not vim.endswith(description, ': ') then
description = description .. ': '
end
return vim.fn.input(description, input.default or '')
if vim.ui.input then
local co = coroutine.running()
local opts = {
prompt = description,
default = input.default or '',
}
vim.ui.input(opts, function(result)
vim.schedule(function()
coroutine.resume(co, result)
end)
end)
return coroutine.yield()
else
return vim.fn.input(description, input.default or '')
end
end
elseif type_ == "pickString" then
return function()
Expand Down
28 changes: 17 additions & 11 deletions tests/ext_vscode_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---@diagnostic disable: duplicate-set-field
local ui_input = vim.ui.input
local vscode = require('dap.ext.vscode')
describe('dap.ext.vscode', function()
after_each(function()
vim.ui.input = ui_input
end)

it('can load launch.json file and map adapter type to filetypes', function()
local dap = require('dap')
vscode.load_launchjs('tests/launch.json', { bar = { 'c', 'cpp' } })
Expand All @@ -12,10 +18,10 @@ describe('dap.ext.vscode', function()
it('supports promptString input', function()
local prompt
local default
vim.fn.input = function(prompt_, default_, _)
prompt = prompt_
default = default_
return 'Fake input'
vim.ui.input = function(opts, on_input)
prompt = opts.prompt
default = opts.default
on_input('Fake input')
end
local jsonstr = [[
{
Expand Down Expand Up @@ -96,8 +102,8 @@ describe('dap.ext.vscode', function()
end)

it('inputs can be used in arrays or dicts', function()
vim.fn.input = function(_, default_value, _)
return default_value
vim.fn.input = function(opts)
return opts.default
end
local jsonstr = [[
{
Expand Down Expand Up @@ -133,8 +139,8 @@ describe('dap.ext.vscode', function()
assert.are.same("the default value", result)
end)
it('can use two inputs within one property', function()
vim.fn.input = function(_, default_value, _)
return default_value
vim.fn.input = function(opts)
return opts.default
end
local jsonstr = [[
{
Expand Down Expand Up @@ -196,9 +202,9 @@ describe('dap.ext.vscode', function()
it('supports promptString without default value', function()
local prompt
local default
vim.fn.input = function(prompt_, default_, _)
prompt = prompt_
default = default_
vim.fn.input = function(opts)
prompt = opts.prompt
default = opts.default
return 'Fake input'
end
local jsonstr = [[
Expand Down

0 comments on commit 5f68498

Please sign in to comment.