rcarriga / nvim-dap-ui

A UI for nvim-dap
MIT License
2.69k stars 101 forks source link

nvim-dap error running a target when cursor is on repl #255

Open Spasitjel opened 1 year ago

Spasitjel commented 1 year ago

I have this issue which reproduces if I actively put myself in a certain setup with nvim-dap and nvim-dap-ui, or it always happens if I'm using also cmake-tools (https://github.com/Civitasv/cmake-tools.nvim) to start debugging.

I decided to open an issue here because the issue appears only when nvim-dap-ui is used (although the other behavior is questionable).

I'm using nvim 0.8.3, nvim-dap 0.5.0 (but I've also tried the very latest) nvim-dap-ui v3.8.0 cmake-tools.nvim 1c2ad8e4ce63413cb3594d7e10239904f6b0bdcf

Setup with nvim-dap alone

  1. Open a file of the project
  2. Place a breakpoint on any line
  3. Open the repl with :lua require'dap'.repl.open()
  4. Move the cursor in the opened repl
  5. Run the target with :lua require'dap'.run({ name = "cpp", program = "<path to program>", cwd = vim.loop.cwd(), type = "lldb", request = "launch" })

Then a copy of the buffer/source code is opened in the repl window. Not really desirable, but at least there's no error when I step

Setup with nvim-dap + nvim-dap-ui

Do all the previous steps, then this time the repl doesn't become a copy of the buffer I had opened with the source code, it stays a repl, the buttons to control the program appear, but all buttons a part from the play and the restart are greyed out. Furthermore, the issue, is that if I step with :lua require'dap'.step_over() or into, doesn't matter, nvim-dap complains that "Debug adapter reported a frame at line column , but: Cursor position outside buffer. Ensure executable is up2date and if using a source mapping ensure it is correct" (https://github.com/mfussenegger/nvim-dap/blob/7389e85233e3483b31b6a1c4ba69cda77336b7a8/lua/dap/session.lua#L383) If then I move the cursor back to the split with the source code, then everything goes back to normal, and the buttons in the repl split are not greyed out anymore.

nvim-dap + nvim-dap-ui + cmake-tools (what I actually use)

I use this function to start debugging:

function start_debug()
  require'dapui'.open()
  require'cmake-tools'.debug({ nargs = "*", desc = "CMake debug" })
end

(and here the cmake-tools debug implementation: https://github.com/Civitasv/cmake-tools.nvim/blob/1c2ad8e4ce63413cb3594d7e10239904f6b0bdcf/lua/cmake-tools/init.lua#L320) It's the same if I use the provided CMakeDebug command via vim.cmd('CMakeDebug').

Something I noticed here is that even though I'm asking to open the UI before requesting to debug, things happens in this order:

  1. I always first get the cmake-tools prompt in the cmdline to choose a build type
  2. then a preset
  3. then dap ui opens, with cursor still on the cmdline because there's another prompt
  4. cmake-tools has opened an additional split where it shows CMake has re-configured the project, and in the cmdline is asking me to select which target to launch.
  5. Selecting the target finally executes it, and the cursor is on the repl, with the issue described previously.

Sorry for the long explanation here but I'm not exactly sure who should be responsible to setup everything correctly. Thank you very much for your time! Let me know if I can do anything else to help.

Ariamis613 commented 4 months ago

Hey, did you manage to fix that I'm having the same problem and I have no idea how to fix it

Spasitjel commented 4 months ago

Hey, did you manage to fix that I'm having the same problem and I have no idea how to fix it

Unfortunately not, I have stopped using nvim/vim altogether ^^'.