stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.73k stars 32 forks source link

Usage question #9

Closed idmitryd closed 2 years ago

idmitryd commented 2 years ago

Hello, I want to use vim.ui.input() to set path to executable for nvim-dap. I managed to do it with default vim.ui.input() (which simply calls vim.fn.input() as I understand) as follows:

dap.configurations.cpp = {
  {
    program = function()
        local path_to_program = '???'
        vim.ui.input({
            prompt = 'Path to executable: ',
            default = vim.fn.getcwd() .. '/',
            completion = 'file',
        },
        function(input)
            path_to_program = input
        end
        )
        return path_to_program
    end,
  },
}

But when I tried to use dressing.nvim implementation of vim.ui.input() in the same manner I faced two issues:

  1. After calling <cmd>lua require'dap'.continue()<cr> popup window that serves for setting path to executable opens as expected but then it immediately closes so I cannot write anything in there.
  2. on_confirm function changes path_to_program variable as expected inside its scope but in the end when the variable has to be returned it equals '???' as before the change. So change of the variable inside on_confirm does not take effect.

Could you please help me to figure out how to properly use vim.ui.input() in this case?

Edit: I use NVIM v0.6.0.

stevearc commented 2 years ago

The problem is that vim.ui.input is not a drop-in replacement for vim.fn.input. vim.fn.input is blocking and so your function won't return until you have given it input. vim.ui.input returns immediately (when your path_to_program variable is still '???') and calls the callback later. In order for this to work you'll need to either convince the author of nvim-dap to support async functions or callbacks in these config options, or you'll need to use vim.ui.input to get and set the program name before you activate nvim-dap.

idmitryd commented 2 years ago

I got it. Thank you for the reply.