mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.46k stars 194 forks source link

Seeing one too many `dap>` REPL prompts on each evaluation #1117

Closed Olical closed 9 months ago

Olical commented 9 months ago

Debug adapter definition and debug configuration

AstroNvim (comes with DAP already) and then my own custom Fennel. You'll have to squint through it, but the main thing is that you can see my debug adaptor configuration in there somewhere. It's all pretty basic, I don't think the issue is related to my configuration. It'll probably be related to the messages my debug adaptor is sending but they look correct to me.

 (uu.tx
   :jay-babu/mason-nvim-dap.nvim
   {:opts (fn [_ opts]
            (set opts.ensure_installed (utils.list_insert_unique opts.ensure_installed []))

            (let [dap (require :dap)]
              (dap.set_log_level "TRACE")
              (set dap.adapters.clojure
                   (fn [cb config]
                     (if
                       (= :attach config.request)
                       (cb
                         {:type :executable
                          :command "/home/olical/repos/Olical/clojure-dap/script/run"
                          :args []
                          :options {:source_filetype :clojure
                                    :initialize_timeout_sec 20}})

                       (= :launch config.request)
                       (error "Launching the debuggee through clojure-dap is not supported, use attach instead.")

                       (error (.. "Unknown request" (or config.request "nil"))))))

              (set dap.configurations.clojure
                   [{:type :clojure
                     :request :attach
                     :name "Start Clojure DAP and attach to a running nREPL"}]))

            opts)})]

Compiled Lua output:

local function _5_(_, opts)
  opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, {})
  do
    local dap = require("dap")
    dap.set_log_level("TRACE")
    local function _6_(cb, config)
      if ("attach" == config.request) then
        return cb({type = "executable", command = "/home/olical/repos/Olical/clojure-dap/script/run", args = {}, options = {source_filetype = "clojure", initialize_timeout_sec = 20}})
      elseif ("launch" == config.request) then
        return error("Launching the debuggee through clojure-dap is not supported, use attach instead.")
      else
        return error(("Unknown request" .. (config.request or "nil")))
      end
    end
    dap.adapters.clojure = _6_
    dap.configurations.clojure = {{type = "clojure", request = "attach", name = "Start Clojure DAP and attach to a running nREPL"}}
  end
  return opts
end

The debug adaptor is clojure-dap, something I'm writing. It only supports eval at the moment which works fine.

Debug adapter version

0.7.0 (latest, just updated)

Steps to Reproduce

  1. Connect Neovim to a debug adaptor. I'm doing so with nvim-dap-ui and AstroNvim's mappings. Which is <space>dc.
  2. Wait for the adaptor to come up and reply to the initial messages.
  3. Type some code into the REPL prompt and run it.
  4. Observe the output (with a stray prompt).

Expected Result

Only one REPL prompt should be printed. You should see the first prompt, your input, then the result and finally a new prompt to type into.

Actual Result

I'm seeing a new prompt appear as soon as I run the code, then the result and then ANOTHER prompt.

image

Here are the logs from my debug adaptor at the time. I can't spot anything awry.

[ DEBUG ] 2023-11-28T18:14:12Z+0000 ] ...ical/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1580 ]    "request"   {
  arguments = {
    context = "repl",
    expression = "20"
  },
  command = "evaluate",
  seq = 18,
  type = "request"
}
[ ERROR ] 2023-11-28T18:14:12Z+0000 ] ...ical/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1334 ]    "stderr"    {
  args = {},
  command = "/home/olical/repos/Olical/clojure-dap/script/run",
  options = {
    initialize_timeout_sec = 20,
    source_filetype = "clojure"
  },
  type = "executable"
}   '2023-11-28T18:14:12.167Z - TRACE [clojure-dap.server:105] - RECV {:arguments {:expression "20", :context "repl"}, :command "evaluate", :type "request", :seq 18}\n'
[ ERROR ] 2023-11-28T18:14:12Z+0000 ] ...ical/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1334 ]    "stderr"    {
  args = {},
  command = "/home/olical/repos/Olical/clojure-dap/script/run",
  options = {
    initialize_timeout_sec = 20,
    source_filetype = "clojure"
  },
  type = "executable"
}   '2023-11-28T18:14:12.177Z - TRACE [clojure-dap.server:88] - SEND {:type "response", :command "evaluate", :seq 20, :request_seq 18, :success true, :body {:variablesReference 0, :result "20"}}\n'
[ DEBUG ] 2023-11-28T18:14:12Z+0000 ] ...ical/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:935 ] 2   {
  body = {
    result = "20",
    variablesReference = 0
  },
  command = "evaluate",
  request_seq = 18,
  seq = 20,
  success = true,
  type = "response"
}

I also raise an issue with nvim-dap-ui (https://github.com/rcarriga/nvim-dap-ui/issues/308) but they say they don't handle the contents of the REPL, just the opening of the window.

Any advice or pointers will be much appreciated. Can you reproduce this with other adaptors? I don't have any set up to test it with right now. I can try and set one up if you want though, just thought the maintainers would have some easy ways to repro this.

If it ONLY happens with my adaptor then I guess there should be a clue in the DAP logs, I just don't see it.

mfussenegger commented 9 months ago

As far as I'm aware having any intermediate dap> prompts was fixed with https://github.com/mfussenegger/nvim-dap/pull/1063. I can't reproduce it with debugpy or java-debug and if you want me to look into anything, you'd need to provide a minimal reproduction - something that can be used with nvim --clean -u minimal.lua. A fennel configuration and AstroNvim is far from that.

Olical commented 9 months ago

Ah okay, that helps, I'll make sure everything is definitely up to date and nothing had been pinned back a few versions. If I'm definitely on the latest version and still seeing it I'll come back with a minimal reproduction if I can create one. Thanks!

Olical commented 8 months ago

It was a version thing! Sorry for the noise, I was using a distribution that had pinned the version behind so I needed to wait for the distro to update. I would like to move off of the distro and roll my own again but, y'know, time and life and stuff.

It's working well now. Will continue with clojure-dap 😃