Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go (using delve directly) no output #232

Closed
y1rn opened this issue Jul 9, 2021 · 5 comments
Closed

Go (using delve directly) no output #232

y1rn opened this issue Jul 9, 2021 · 5 comments

Comments

@y1rn
Copy link
Contributor

y1rn commented Jul 9, 2021

as subject, i m using nvim-dap-ui,but no every log output in repl panel.

@mfussenegger
Copy link
Owner

I'll need a more detailed problem description to investigate or help

@y1rn
Copy link
Contributor Author

y1rn commented Jul 9, 2021

image
should be print something here, right?

@mfussenegger
Copy link
Owner

mfussenegger commented Jul 10, 2021

Looks like dlv dap currently logs the output to its own stdout instead of routing it via the debug adapter protocol.

recording.mp4

Ideally they'd support the runInTerminal request, so you could have it launch your application in a dedicated terminal. Looks like that's not yet supported: golang/vscode-go#124 - but there is active work in that direction going on: go-delve/delve#2566

There isn't anything that can be done within nvim-dap about it :(

@mfussenegger
Copy link
Owner

Actually there is something you can do, you could redirect the output of dlv to the repl:

dap.adapters.dlv_spawn = function(cb)
  local stdout = vim.loop.new_pipe(false)
  local handle
  local pid_or_err
  local port = 38697
  local opts = {
    stdio = {nil, stdout},
    args = {"dap", "-l", "127.0.0.1:" .. port},
    detached = true
  }
  handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code)
    stdout:close()
    handle:close()
    if code ~= 0 then
      print('dlv exited with code', code)
    end
  end)
  assert(handle, 'Error running dlv: ' .. tostring(pid_or_err))
  stdout:read_start(function(err, chunk)
    assert(not err, err)
    if chunk then
      vim.schedule(function()
        --- You could adapt this and send `chunk` to somewhere else
        require('dap.repl').append(chunk)
      end)
    end
  end)
  -- Wait for delve to start
  vim.defer_fn(
    function()
      cb({type = "server", host = "127.0.0.1", port = port})
    end,
    100)
end

You'll have to change the type in your configurations to dlv_spawn to use this new adapter definition. For example:

dap.configurations.go = {
  {
    type = 'dlv_spawn',
    name = 'Launch dlv & file',
    request = 'launch',
    program = "${file}";
  },
}

You also have to be aware that the prompt buffer in neovim behaves a bit odd, and output is only visible if you enter it.

@y1rn
Copy link
Contributor Author

y1rn commented Jul 11, 2021

thanks for you response, and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants