neovim setup for golang 6 months in

neovim setup for golang 6 months in

So far

I have been using my nvim golang setup for around more than 6months now and I am still learning something new everyday while I use it.

coc.vim works really well so far for me. Linting, autocomplete, jumping to definitions back and forth, code folding, checking for references for where a function/method is used, it works out for me well so far.

What I am trying to fix on my setup so far

The debugging experience for sure can be improved, I have tried using nvim-dap-go.

It does work for tests where you would not have a lot of nesting, for example works great for simple t.Run() calls which are not overly nested (at least from my usage so far) but I have had trouble using it with some ginkgo style tests where it’s not able to parse for the parent test when trying to add a debug point, internally it ends up using treesitter to parse the whole file.

Have an open issue here which I added more context in this issue https://github.com/leoluz/nvim-dap-go/issues/9#issuecomment-1521496733.

My setup for the same is very simple and mostly untouched from the usual config which is out there in the docs

lua <<EOF
local dap = require('dap')
local dapui = require("dapui")

dapui.setup()

require('dap-go').setup {
  -- delve configurations
  delve = {
      -- time to wait for delve to initialize the debug session.
      -- default to 20 seconds
      initialize_timeout_sec = 20,
      -- a string that defines the port to start delve debugger.
      -- default to string "${port}" which instructs nvim-dap
      -- to start the process in a random available port
      port = "${port}"
  },
  dap_configurations = {
    {
      type = "go",
      name = "Attach remote",
      mode = "remote",
      request = "attach",
    },
  },
}

-- You can use nvim-dap events to open and close the windows automatically
-- from: https://github.com/rcarriga/nvim-dap-ui
dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close()
end

EOF

Workflow

The flow of usage is pretty out of the box

Key maps being used

I am as of now using the following keymaps

nmap <silent> <leader>tb :lua require'dap'.toggle_breakpoint()<CR>
nmap <silent> <leader>tc :lua require'dap'.continue()<CR>
nmap <silent> <leader>tt :lua require'dap'.terminate()<CR>
nmap <silent> <leader>td :lua require('dap-go').debug_test()<CR>