-
Notifications
You must be signed in to change notification settings - Fork 918
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
feat(lang): add debug adapter plugin for go #1115
Conversation
I thought mason-nvim-dap should have added a Go DAP adapter and configurations automatically without the need for this plugin. Is that not working or are the adapters/configs not working correctly? |
@jyuan0 Hm, not sure. You can see the error I get when I just enable the go extras here:#1107 I haven't looked into whether mason-nvim-dap is supposed set both a DAP adapter and a configuration up. Here's the go extras implementation in case you want to take a look: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/go.lua |
|
neotest-go does not provide a DAP strategy, and thus you cannot invoke the debugger with require('neotest').run.run({strategy=dap}). There have been efforts to implement this in nvim-neotest/neotest-go#12 but this seems to have stalled. You can find the background to this change discussed here: #1107
Or are you talking about |
From my understanding of mason-nvim-dap, it should automatically setup a DAP adapter and configs without specifying anything in I'm not saying this solves the issue with |
|
So, from my testing, if I just add the Go extra, delve is automatically installed and mason-nvim-dap adds an DAP adapter and configurations without needing to specify anything in On another note, the null-ls sources ( |
@jyuan0 Thanks for letting us know. I hadn't experimented myself since I don't use Go. |
@@ -15,6 +15,10 @@ return { | |||
opts = { | |||
servers = { | |||
gopls = { | |||
keys = { | |||
-- Workaround for the lack of a DAP strategy in neotest-go: https://github.com/nvim-neotest/neotest-go/issues/12 | |||
{ "<leader>td", "<cmd>lua require('dap-go').debug_test()<CR>", desc = "Debug Nearest (Go)" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this will always overwrite the neotest configuration?
I would suspect that it does not, if you load the go lang extra before the neotest extra?
Also, this will unconditionally bind <leader>td
even if we do not have the neotest or dap extras.
I think this keybind probably has to be done under an optional neotest dependency, probably under the nvim-dap
dependency too 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kind of new to Neovim/LazyVim and can't say I know for sure what's the best way to do this, or what caveats/side-effects there may be. Would be great to have @folke pitch in here (but I see he's on vacation so it'll of course have to wait until he's back).
But since I think you had an interesting observation, I just now tried to load the go extras before the neotest/dap extras, just to see if the keymap would still be overridden for go tests. I initially did this:
-- lazy.lua
...
require("lazy").setup({
spec = {
-- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
-- import any extras modules here
{ import = "lazyvim.plugins.extras.lang.go" },
{ import = "lazyvim.plugins.extras.test.core" },
{ import = "lazyvim.plugins.extras.dap.core" },
{ import = "plugins" },
},
...
I also tried switching them around, and in all cases, I were able to debug a go test with <leader>td
- which means the keymap seems like it's always overridden regardless of this order.
However, I haven't dug into the LazyVim implementation and I'm not fully understood with how the Lazy.nvim dependencies =
declarative works, and perhaps my local config somehow triggers loading of plugins in some order that doesn't show by this rudimental switcharoo test of mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, should be fine
Thanks! |
neotest-go does not provide a DAP strategy, and thus you cannot invoke the debugger with require('neotest').run.run({strategy=dap}). There have been efforts to implement this in nvim-neotest/neotest-go#12 but this seems to have stalled. You can find the background to this change discussed here: LazyVim#1107
Why this change?
I'm getting an error with
<leader>td
, when I want to debug a go test. See #1107 for details.It seems there is no debug adapter defined in the Go extras. I can work around this locally like so:
...but I figured it might be better to extend the go extras with this capability, hence this PR.
What was changed?
nvim-dap-go
plugin.<leader>td
in gopls lspconfig.I can now successfully debug go tests with
<leader>td
.Concerns, side-effects, notes etc
Even with the addition of
nvim-dap-go
, you cannot use<leader>td
orrequire("neotest").run.run({strategy = "dap"})
to debug a test, as neotest-go apparently does not implement a DAP strategy. Instead you have to invokerequire('dap-go').debug_test()
. It might be good to mention this in the extras docs. Or can we reliably override the command executed by<leader>td
but only for go buffers, perhaps?