coc.nvim
coc.nvim copied to clipboard
Debug Adapter Protocol Support
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:
- Vebugger: https://github.com/idanarye/vim-vebugger/issues/66
- Vimspector: https://github.com/puremourning/vimspector/issues/3 I found out later, that vimspector doesn't plan to support neovim
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.
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.
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.
@chemzqm How can we write these kind of extensions? I can help you.
@tbo just an update - there is an WIP PR to add support of Neovim in Vimspector by @romgrk.
@XVilka I checked it out, but the last few comments do not look promising.
Better ref https://github.com/puremourning/vimspector/issues/29
@puremourning Thanks for reference. That actually looks quite promising.
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?
@chemzqm I'm interested in help too.
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.
Vimspector neovim support is now fully functional and just needs testing.
@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 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.
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.
@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.
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?
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>
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.
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
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.
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:
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.
Currently Vimspector won't do this for you
correction : can't.
@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
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.
@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.
what about https://github.com/mfussenegger/nvim-dap and https://github.com/rcarriga/nvim-dap-ui ?
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?
It would be awesome if coc could support dap like it does lsp...
@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?