leoluz / nvim-dap-go

An extension for nvim-dap providing configurations for launching go debugger (delve) and debugging individual tests
MIT License
475 stars 77 forks source link

Flashing screen and `Error on launch: Failed to launch` #100

Closed mclacore closed 3 hours ago

mclacore commented 4 hours ago

Trying to run debugging for a go package. I've gotten it to work before when opening the Debug test (go.mod) test in the configuration. However, now that screen is just flashing open/close. That got me to dig in and try to figure out why I can't run any of the other configurations. I do have dlv installed:

❯ dlv version
Delve Debugger
Version: 1.23.1
Build: $Id: 2eba762d75437d380e48fc42213853f13aa2904d $

So i tried to find out what I could/could not do and record it:

CleanShot 2024-09-24 at 09 43 57

DAP UI is flashing on/off in this gif for Debug test and Debug test (go.mod), but it doesn't show it in the gif.

Captured log:

[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1182 ]    "Starting debug adapter server executable"  {
  args = { "dap", "-l", "127.0.0.1:51368" },
  command = "dlv",
  detached = true
}
[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1315 ]    "Debug adapter server executable started, listening on 51368"
[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1319 ]    "Connecting to debug adapter"   {
  executable = {
    args = { "dap", "-l", "127.0.0.1:51368" },
    command = "dlv",
    detached = true
  },
  options = {
    initialize_timeout_sec = 20
  },
  port = 51368,
  type = "server"
}
[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "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 = 1,
  type = "request"
}
[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  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 = 1,
  seq = 0,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-24T10:32:34Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    buildFlags = "",
    mode = "test",
    name = "Debug test (go.mod)",
    program = "./.",
    request = "launch",
    type = "go"
  },
  command = "launch",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  event = "initialized",
  seq = 0,
  type = "event"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    breakpoints = { {
        line = 48
      } },
    lines = { 48 },
    source = {
      name = "tofutoschema.go",
      path = "/Users/mclacore/massdriver/airlock/pkg/opentofu/tofutoschema.go"
    },
    sourceModified = false
  },
  command = "setBreakpoints",
  seq = 3,
  type = "request"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  command = "launch",
  request_seq = 2,
  seq = 0,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  body = {
    breakpoints = { {
        id = 1,
        line = 48,
        source = {
          name = "tofutoschema.go",
          path = "/Users/mclacore/massdriver/airlock/pkg/opentofu/tofutoschema.go"
        },
        verified = true
      } }
  },
  command = "setBreakpoints",
  request_seq = 3,
  seq = 0,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  command = "configurationDone",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  body = {
    category = "console",
    output = "Type 'dlv help' for list of commands.\n"
  },
  event = "output",
  seq = 0,
  type = "event"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  command = "configurationDone",
  request_seq = 4,
  seq = 0,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-24T10:32:36Z-0700 ] ...core/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 2   {
  body = vim.empty_dict(),
  event = "terminated",
  seq = 0,
  type = "event"
}

Here's my dap config (started w/ Kickstart.nvim):

return {
  'mfussenegger/nvim-dap',
  dependencies = {
    'rcarriga/nvim-dap-ui',
    'nvim-neotest/nvim-nio',
    'williamboman/mason.nvim',
    'jay-babu/mason-nvim-dap.nvim',
    'leoluz/nvim-dap-go',
  },
  config = function()
    local dap = require 'dap'
    local dapui = require 'dapui'

    require('mason-nvim-dap').setup {
      automatic_installation = true,
      handlers = {},

      ensure_installed = {
        'delve',
      },
    }

    vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''})
    vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''})

    -- Basic debugging keymaps, feel free to change to your liking!
    vim.keymap.set('n', '<Leader>dc', dap.continue, { desc = 'Debug: Start/Continue' })
    vim.keymap.set('n', '<Leader>di', dap.step_into, { desc = 'Debug: Step Into' })
    vim.keymap.set('n', '<Leader>dr', dap.step_over, { desc = 'Debug: Step Over' })
    vim.keymap.set('n', '<Leader>dt', dap.step_out, { desc = 'Debug: Step Out' })
    vim.keymap.set('n', '<Leader>db', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
    vim.keymap.set('n', '<Leader>dl', function() dap.repl.open() end, { desc = 'Debug: Open REPL' })
    vim.keymap.set('n', '<Leader>ds', function() dap.run_last() end, { desc = 'Debug: Run Last' })

    -- For more information, see |:help nvim-dap-ui|
    dapui.setup {
      icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
      controls = {
        element = "repl",
        enabled = true,
        icons = {
          pause = '⏸',
          play = '▶',
          step_into = '⏩',
          step_over = '⏭',
          step_out = '⏎',
          step_back = '⏪',
          run_last = '⏮',
          terminate = '⏹',
          disconnect = '⏏',
        },
      },
      element_mappings = {},
      expand_lines = true,
      floating = {
        border = "single",
        mappings = {
          close = { "q", "<Esc>" },
        }
      },
      force_buffers = true,
      mappings = {
        edit = "e",
        expand = { "<CR>", "<2-LeftMouse>" },
        open = "o",
        remove = "d",
        repl = "r",
        toggle = "t",
      },
      render = {
        indent = 1,
        max_value_lines = 100,
      },
      layouts = { {
          elements = { {
              id = "scopes",
              size = 0.25,
            }, {
              id = "breakpoints",
              size = 0.25,
            }, {
              id = "stacks",
              size = 0.25,
            }, {
              id = "watches",
              size = 0.25,
            } },
          position = "left",
          size = 40
          }, {
          elements = { {
              id = "repl",
              size = 0.5,
            }, {
              id = "console",
              size = 0.5,
            } },
          position = "bottom",
          size = 10
        } },
    }

    vim.keymap.set('n', '<Leader>dn', dapui.toggle, { desc = 'Debug: See last session result.' })
    vim.keymap.set('n', '<Leader>do', function() dapui.open() end, { desc = 'Debug: Open Debug UI' })
    vim.keymap.set('n', '<Leader>de', function() dapui.close() end, { desc = 'Debug: Close Debug UI' })

    dap.listeners.after.event_initialized['dapui_config'] = dapui.open
    dap.listeners.before.event_terminated['dapui_config'] = dapui.close
    dap.listeners.before.event_exited['dapui_config'] = dapui.close

    -- Install golang specific config
    require('dap-go').setup {
      dap_configurations = {
        {
          type = 'go',
          name = 'Attach remote',
          mode = 'remote',
          request = 'attach',
        },
      },
      delve = {
        path = "dlv",
      },
    }
  end,
}

I've been using nvim for only 5 months at this point, so I'm still very new, if someone could help me figure out why I suddenly can't load the debugger for go, when I have been able to before.

EDIT:

Tried manually opening DAP-UI and finding the stderr messages there, and I found these when trying to start a debug session:

[debug-adapter stderr] could not remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin3971516382: remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin3971516382: no such file or directory

[debug-adapter stderr] could not remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin2516458328: remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin2516458328: no such file or directory

Build Error: go build -o /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin1187058319 -gcflags all=-N -l /Users/mclacore/massdriver/airlock/pkg/opentofu/tofutoschema_test.go

[debug-adapter stderr] could not remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin2989260157: remove /Users/mclacore/massdriver/airlock/pkg/opentofu/__debug_bin2989260157: no such file or directory
mclacore commented 3 hours ago

Issue is not nvim-dap-go but rather my oversight with my test file.