Skip to content

Commit

Permalink
Replace neotest-go adapter with neotest-golang
Browse files Browse the repository at this point in the history
Tried to setup DAP for go following nvim-dap documentation and using
delve directly, as described in https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go-using-delve-directly

However, I was struggling to get DAP working and was getting "Error on launch: Failed to launch" errors all the time,
when I discovered (via dap-ui) that the defaults of nvim-dap-go expects go.mod to be in the root of the project.

At the same time, the "native" neotest adapter for go seems to have the same behavior and
does not seem to support projects where go.mod is not in the root.

This was originally described here
leoluz/nvim-dap-go#80 (comment),
and there's an open issue for this in nvim-dap-go: leoluz/nvim-dap-go#85

There is, however, another adapter for go - fredrikaverpil/neotest-golang - which seems to be more flexible and does support projects
where go.mod is not in the root.

After replacing the adapter and adding configurations as per https://github.com/fredrikaverpil/neotest-golang/?tab=readme-ov-file#example-configuration-debugging,
I was finally able to get DAP working for go.
  • Loading branch information
serpro69 committed Sep 26, 2024
1 parent 6fcee74 commit e193718
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lua/plugins/neotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,35 @@ return {
end,
dependencies = {
"nvim-neotest/neotest-python",
"nvim-neotest/neotest-go",
-- "nvim-neotest/neotest-go", -- does not support monorepos where go.mod is not in root
-- "marilari88/neotest-vitest",
-- "nvim-neotest/neotest-jest",
-- "rouge8/neotest-rust",
-- "rcasia/neotest-java",
"nvim-treesitter/nvim-treesitter",
-- extra dependencies for golang debugging with suppport for monorepos
-- ref https://github.com/fredrikaverpil/neotest-golang/?tab=readme-ov-file#example-configuration-debugging
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
{
"fredrikaverpil/neotest-golang", -- Installation
dependencies = {
{
"leoluz/nvim-dap-go",
init = function()
require("dap-go").setup()
end,
},
},
},
},
config = function()
require("neotest").setup {
adapters = {
require "neotest-python" {
runner = "pytest",
},
require "neotest-go",
require "neotest-golang", -- Registration
},
}
end,
Expand Down

0 comments on commit e193718

Please sign in to comment.