coc.nvim icon indicating copy to clipboard operation
coc.nvim copied to clipboard

Debug Adapter Protocol Support

Open tbo opened this issue 6 years ago • 35 comments
trafficstars

Is your feature request related to a problem? Please describe.

I would like to have additional debugging support in coc.nvim. There are no debug extensions for neovim, that provide proper auto-completion, because this would require additional IDE level language support.

Describe the solution you'd like

VS Code integrates a multitude of debuggers via its Debug Adapter Protocol. They offer a node based sdk as a separate NPM Package. Additional info can be found here. coc.nvim would need to:

  • expose the DAP commands
  • react to DAP events
  • provide a terminal window with auto-completion

Describe alternatives you've considered

I checked two existing debugger extensions:

Additional context

All debug adapters known to me only exist as a vscode extension and in the case of Java Debug even require its LSP counterpart. I realize, that debugging is not coc.nvim's main focus, but if this can be implemented for neovim, then likely only on top of coc.nvim. I don't know any other plugin, that integrates the vscode ecosystem so well and also provides LSP-support.

tbo avatar Jan 05 '19 21:01 tbo

Is possbile to execute command and send request to a running language server started by coc, so it's possible to make a coc extension for it.

chemzqm avatar Jan 09 '19 01:01 chemzqm

I would consider vimspector support for neovim, but only after I have made vimspector fully tested and stable (e.g. a "v1 version") on vim, as that's the platform I use. Contributions are of course welcome.

puremourning avatar Jan 22 '19 19:01 puremourning

@chemzqm How can we write these kind of extensions? I can help you.

LinArcX avatar Feb 18 '19 13:02 LinArcX

@tbo just an update - there is an WIP PR to add support of Neovim in Vimspector by @romgrk.

XVilka avatar Jul 03 '19 04:07 XVilka

@XVilka I checked it out, but the last few comments do not look promising.

tbo avatar Jul 24 '19 21:07 tbo

Better ref https://github.com/puremourning/vimspector/issues/29

puremourning avatar Jul 24 '19 21:07 puremourning

@puremourning Thanks for reference. That actually looks quite promising.

tbo avatar Jul 24 '19 21:07 tbo

Is possbile to execute command and send request to a running language server started by coc, so it's possible to make a coc extension for it.

@chemzqm Could you please help us how to create this kind of extension?

LinArcX avatar Dec 09 '19 11:12 LinArcX

@chemzqm I'm interested in help too.

adelarsq avatar Dec 20 '19 14:12 adelarsq

Better ref neovim/neovim#11732. That way, it isn't bound to Coc and can be packaged with a stable release of Neovim one day.

hariamoor-zz avatar Jan 18 '20 21:01 hariamoor-zz

Vimspector neovim support is now fully functional and just needs testing.

puremourning avatar Jan 18 '20 21:01 puremourning

@chemzqm @LinArcX Would you two consider doing it in Lua and shipping it with Neovim? Like I said, I'd rather have it as a Lua plugin shipped with the editor than a Coc plugin, because that way, the functionality isn't bound to Coc.

hariamoor-zz avatar Jan 18 '20 23:01 hariamoor-zz

@hariamoor What should this plugin provide, that isn't already provided by Vimspector? AFAIK auto-completion is the only thing missing and also the original reason I created this feature request here. I just saw, that @puremourning mentioned, that DAP has support for this as well (https://github.com/puremourning/vimspector/issues/52#issuecomment-537460921). So Coc might not be necessary for this after all. @puremourning please correct me, if I'm wrong.

tbo avatar Jan 19 '20 10:01 tbo

You’re right. Now that vimspector has neovim support (nearly).

Vimspector has cmdline completion (sort of) for evaluate and watch. And for the console prompt buffer, it’s possible manually/planned generally to make an omnifunc which would work with standard completion and/or YCM etc.

I suppose one thing that would help is coc could expose an equivalent to the command to that YCM does to allow starting the java debug adapter (which is a plugin to jdt.ls). In YCM user runs :YcmCompleter ExecuteCommand vscode.java.startDebugSession That’s an LSP command within the java server and a mechanism by which the plugin is discovered and loaded.

But other than that it seems out of scope for coc.

puremourning avatar Jan 19 '20 12:01 puremourning

@hariamoor this is coc issue tracker, for a possible coc debugging extension. It doesn't make sense to request coc author to write a standalone debugging interface, for NeoVim only, in Lua.

oblitum avatar Jan 21 '20 01:01 oblitum

So based on @puremourning's comment... currently is there a way to start debug session on java language server from within coc (vscode.java.startDebugSession)? Or a workaround?

rockneverdies55 avatar Feb 02 '20 09:02 rockneverdies55

Here's an example:

function! JavaStartDebugCallback(err, port)
  execute "cexpr! 'Java debug started on port: " . a:port . "'"
  call vimspector#LaunchWithSettings({ "configuration": "Java Attach", "AdapterPort": a:port })
endfunction

function! JavaStartDebug()
  call CocActionAsync('runCommand', 'vscode.java.startDebugSession', function('JavaStartDebugCallback'))
endfunction

nmap <F1> :call JavaStartDebug()<CR>

dansomething avatar Feb 02 '20 14:02 dansomething

Thank you @dansomething. Here how it goes when I press F1 to invoke your function:

(1 of 1): Java debug started on port: null

Press ENTER or type command to continue<CR>

Enter value for debugPort: 8000<CR>

Here it opens complete empty vimspector window with asking for the port at the bottom again:

Enter port to connect to: 8000<CR> Request for initialize aborted: Closing down

Debugging works flawlessly in vscode but can't get it to work in nvim. Not sure if it's caused by vimspector itself or coc is somehow preventing vscode-debugger and vimspector to talk to each other.

rockneverdies55 avatar Feb 02 '20 15:02 rockneverdies55

Yeah, you'll need to get the Java Debug extension loaded into jdt.ls. Currently Vimspector won't do this for you. The vscode-java-debug plugin does it like this. See the jdt.ls extension docs for more info.

I've hacked to together an extension for coc.nvim to do this same thing. You're welcome to try it, but I can't make any guarantees for your setup. Being experimental, its currently not available as an npm package.

To install the coc-java-debug extension:

 CocInstall https://github.com/dansomething/coc-java-debug

To uninstall it

CocUninstall coc-java-debug

dansomething avatar Feb 02 '20 15:02 dansomething

Oh, here's the .vimspector.json I'm using with this setup to attached to an existing Java process that's waiting for a debug connection.

{
  "adapters": {
    "java-debug-server": {
      "name": "vscode-java",
      "port": "${AdapterPort}"
    }
  },
  "configurations": {
    "Java Attach": {
      "adapter": "java-debug-server",
      "configuration": {
        "request": "attach",
        "host": "127.0.0.1",
        "port": "5005"
      },
      "breakpoints": {
        "exception": {
          "caught": "N",
          "uncaught": "N"
        }
      }
    }
  }
}

See the Vimspector config for more info on this setup.

dansomething avatar Feb 02 '20 15:02 dansomething

Great. Thanks for the guidance. After hours of struggling... finally once your plugin was installed, it started to work like a charm.

Oh man this is plain awesome :slightly_smiling_face: With coc and vimspector, I don't ever need to touch my ide anymore. :+1:

rockneverdies55 avatar Feb 02 '20 16:02 rockneverdies55

With coc and vimspector, I don't ever need to touch my ide anymore.

this!

Let's hope the process keeps on getting better and smoother thanks to all the hard work of these project maintainers.

dansomething avatar Feb 02 '20 16:02 dansomething

Currently Vimspector won't do this for you

correction : can't.

puremourning avatar Feb 02 '20 16:02 puremourning

@dansomething - if you're feeling generous, would you mind writing this up on the vimspector wiki? I really appreciate the work you put in to make that smooth and to help others to get it working too

puremourning avatar Feb 02 '20 16:02 puremourning

Sure, I'll give it a shot. And thanks for the clarification above. Its the responsibility of the code that starts jdt.ls to provide the config to enable the java-debug server extension.

dansomething avatar Feb 02 '20 16:02 dansomething

@puremourning I had some progress started on the readme for coc-java-debug so I just pushed that up. Feel free to copy/tweak or link to that for the vimspector wiki.

dansomething avatar Feb 02 '20 19:02 dansomething

what about https://github.com/mfussenegger/nvim-dap and https://github.com/rcarriga/nvim-dap-ui ?

luisdavim avatar Aug 11 '21 23:08 luisdavim

coc.nvim is the easier alternative to mason.nvim. I love it so much, but unfortunately, coc.nvim won't support nvim-dap unlike mason.nvim, leaving with no debugger. I was looking for any other DAP manager that can complement coc.nvim in that regard, preferably with nvim-dap integration, but I found none that is maintained. (dap-buddy would be it, if it was maintained.)

To install mason along coc.nvim feels redundant. Can anybody suggest a maintained alternative to dap-buddy?

martin-braun avatar Dec 08 '22 01:12 martin-braun

It would be awesome if coc could support dap like it does lsp...

luisdavim avatar Dec 25 '22 19:12 luisdavim

@luisdavim what do you mean by "support dap like it does lsp"? LSP is a protocol, and DAP is another, so, how does former supports the latter?

oblitum avatar Dec 26 '22 18:12 oblitum