mfussenegger / nvim-dap

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

Python `print()` statements in the REPL are duplicated #1255

Closed carschandler closed 3 weeks ago

carschandler commented 3 weeks ago

Debug adapter definition and debug configuration

Installed via Lazy. Minimal plugin config:

return {
  'mfussenegger/nvim-dap',

  config = function()
    local dap = require('dap')

    dap.adapters.python = {
      type = 'executable',
      command = 'python',
      args = { '-m', 'debugpy.adapter' };
    }

    dap.configurations.python = {
      {
        name = 'Launch file',
        type = 'python',
        request = 'launch',
        program = '${file}',
        pythonPath = 'python',
      },
    }
  end
}

Debug adapter version

debugpy v1.8.1

Steps to Reproduce

In any project, start DAP, open the REPL, and print("anything").

Expected Result

The object is printed once

Actual Result

The object is printed twice

mfussenegger commented 3 weeks ago

Although confusing this is actually expected. debugpy returns 10 as result of the expression, but also prints 10 as side-effect to stdout/reports it as output event.

If you use the integrated terminal you'll only see it once in the REPL, and once in the terminal.

Not much to do about that on the client side because different debug adapters behave different in this regard, and the client doesn't know that the output event is related in that way to the expression result.

You could override on_output and customized it if you wanted to (see dap.defaults)

(Or just evaluate expressions directly without wrapping them in print)

carschandler commented 3 weeks ago

I figured this wasn't actually a bug, but had been irking me since I started using DAP a few months back and I couldn't find anything on it in other issues/discussions so I figured at the least it would be good to have it out there for others in the future. Thank you for the tip on the integrated terminal!