fredrikaverpil / neotest-golang

Reliable Neotest adapter for running Go tests in Neovim.
MIT License
58 stars 6 forks source link

Not able to debug tests. #21

Closed kujtimiihoxha closed 1 month ago

kujtimiihoxha commented 1 month ago

I am using nvim-dap-go and neotest-golang ontop of astronvim. I think I am adding all the necessary configuration but for some reason it is not working I tried reading the dap logs but can't figure out what the issue is

[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1165 ]    "Starting debug adapter server executable"  {
  args = { "dap", "-l", "127.0.0.1:49309" },
  command = "dlv",
  detached = true
}
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1295 ]    "Debug adapter server executable started, listening on 49309"
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1299 ]    "Connecting to debug adapter"   {
  executable = {
    args = { "dap", "-l", "127.0.0.1:49309" },
    command = "dlv",
    detached = true
  },
  options = {
    initialize_timeout_sec = 20
  },
  port = 49309,
  type = "server"
}
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1676 ]    "request"   {
  arguments = {
    adapterID = "nvim-dap",
    clientId = "neovim",
    clientname = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_US.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 0,
  type = "request"
}
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:950 ] 4   {
  body = {
    supportsClipboardContext = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsDelayedStackTraceLoading = true,
    supportsDisassembleRequest = true,
    supportsEvaluateForHovers = true,
    supportsExceptionInfoRequest = true,
    supportsFunctionBreakpoints = true,
    supportsInstructionBreakpoints = true,
    supportsLogPoints = true,
    supportsSetVariable = true,
    supportsSteppingGranularity = true
  },
  command = "initialize",
  request_seq = 0,
  seq = 0,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1676 ]    "request"   {
  arguments = {
    args = { "-test.run", "^TestFileParser_FindGoFiles$" },
    cwd = "/Users/kujtimhoxha/go-services/gs/parser",
    mode = "test",
    name = "Neotest-golang",
    program = "/Users/kujtimhoxha/go-services/gs",
    request = "launch",
    type = "go"
  },
  command = "launch",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-05-25T13:32:20Z+0200 ] ...oxha/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:950 ] 4   {
  body = {
    error = {
      format = "Failed to launch: could not launch process: not an executable file",
      id = 3000,
      showUser = true
    }
  },
  command = "launch",
  message = "Failed to launch",
  request_seq = 1,
  seq = 0,
  success = false,
  type = "response"
}

nvim-dap config

return {

  "mfussenegger/nvim-dap",
  dependencies = {
    "mxsdev/nvim-dap-vscode-js",

    "leoluz/nvim-dap-go",
    -- build debugger from source
    {
      "microsoft/vscode-js-debug",
      version = "1.x",
      build = "npm i && npm run compile vsDebugServerBundle && mv dist out",
    },
  },
  config = function()
    require("dap-go").setup {}

    require("dap-vscode-js").setup {
      debugger_path = vim.fn.stdpath "data" .. "/lazy/vscode-js-debug",
      adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" },
    }

    for _, language in ipairs { "typescript", "javascript", "vue" } do
      require("dap").configurations[language] = {
        -- attach to a node process that has been started with
        -- `--inspect` for longrunning tasks or `--inspect-brk` for short tasks
        -- npm script -> `node --inspect-brk ./node_modules/.bin/vite dev`
        {
          -- use nvim-dap-vscode-js's pwa-node debug adapter
          type = "pwa-node",
          -- attach to an already running node process with --inspect flag
          -- default port: 9222
          request = "attach",
          -- allows us to pick the process using a picker
          processId = require("dap.utils").pick_process,
          -- name of the debug action you have to select for this config
          name = "Attach debugger to existing `node --inspect` process",
          -- for compiled languages like TypeScript or Svelte.js
          sourceMaps = true,
          -- resolve source maps in nested locations while ignoring node_modules
          resolveSourceMapLocations = {
            "${workspaceFolder}/**",
            "!**/node_modules/**",
          },
          -- path to src in vite based projects (and most other projects as well)
          cwd = "${workspaceFolder}/src",
          -- we don't want to debug code inside node_modules, so skip it!
          skipFiles = { "${workspaceFolder}/node_modules/**/*.js" },
        },
        {
          type = "pwa-chrome",
          name = "Launch Chrome to debug client",
          request = "launch",
          url = "http://localhost:5173",
          sourceMaps = true,
          protocol = "inspector",
          port = 9222,
          webRoot = "${workspaceFolder}/src",
          -- skip files from vite's hmr
          skipFiles = { "**/node_modules/**/*", "**/@vite/*", "**/src/client/*", "**/src/*" },
        },
        -- only if language is javascript, offer this debug action
        language == "javascript"
            and {
              -- use nvim-dap-vscode-js's pwa-node debug adapter
              type = "pwa-node",
              -- launch a new process to attach the debugger to
              request = "launch",
              -- name of the debug action you have to select for this config
              name = "Launch file in new node process",
              -- launch current file
              program = "${file}",
              cwd = "${workspaceFolder}",
            }
          or nil,
      }
    end
  end,
}

Neotest config

return {
  "nvim-neotest/neotest",
  dependencies = {
    "fredrikaverpil/neotest-golang", -- Installation
    "marilari88/neotest-vitest",
  },
  opts = function(_, opts)
    if not opts.adapters then opts.adapters = {} end
    local goConfig = { dap_go_enabled = true } -- Specify configuration
    table.insert(opts.adapters, require "neotest-vitest"(require("astrocore").plugin_opts "neotest-vitest"))
    table.insert(opts.adapters, require "neotest-golang"(goConfig))
  end,
}
fredrikaverpil commented 1 month ago

Is delve on your $PATH?

kujtimiihoxha commented 1 month ago

Yep, was wondering the same:

Screenshot 2024-05-26 at 02 16 29
fredrikaverpil commented 1 month ago

I'm sorry but I'm not sure how to help you out here, as it's a configuration problem on your end, it seems.

kujtimiihoxha commented 1 month ago

Yep you are probably right, was wondering if this is something you came across before, I will have to dig more :( . I will close this for now and report back with a fix if I find it.

fredrikaverpil commented 1 month ago

If you open ~/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua and go to line 950 or around there (which is where your log indicates the error is hit), you can try do some poor man's printing with print(vim.inspect(some_variable)).

When I go in that file onto line 950, it looks like we are likely on different versions of nvim-dap. But I see a Session:handle_body method, which is interesting, and in which you could e.g. print the body to perhaps gain some insight about what is going wrong.

fredrikaverpil commented 1 month ago

You can also try commenting out all the other DAP plugins you're using, to verify they are not conflicting with neotest-golang and/or nvim-dap-go.

kujtimiihoxha commented 1 month ago

Thanks a lot @fredrikaverpil this helps a ton, very new to neovim and lua so this is super helpful, I will report back 👍