kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

Debug Test For Go Not Working

Open AnthonyMBonafide opened this issue 1 year ago • 7 comments

Describe the bug

Using Kickstart with a couple of additional plugins unrelated to debugging. I am able to start debugging Go projects using the Debug , Debug (Arguments), Debug test (go.mod). However, when I try to use the Debug test option I get an error that states Error on launch: Failed to launch. I have set my cursor inside a test function and also tried putting it on the test function signature, but that did not change the results.

To Reproduce

  1. Open Go project in neovim at the root of the project
  2. Open a test file (*_test.go naming pattern)
  3. Navigate to a test
  4. Invoke the DAP continue function( By default this is F5)
  5. Select the Debug test option

Desktop

  • OS: MacOS Sonoma 14.4.1
  • Terminal: Kitty

Neovim Version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1713773202

Screenshot 2024-05-17 at 09 40 56

Note

I am still rather new to NeoVim and might be doing something silly and apologize in advance if this is a me problem.

AnthonyMBonafide avatar May 17 '24 13:05 AnthonyMBonafide

@AnthonyMBonafide maybe check out this vid if it provides any help: https://www.youtube.com/watch?v=lyNfnI-B640 simple neovim debugging setup (in 10 minutes)

dam9000 avatar May 17 '24 15:05 dam9000

@AnthonyMBonafide maybe check out this vid if it provides any help: https://www.youtube.com/watch?v=lyNfnI-B640 simple neovim debugging setup (in 10 minutes)

@dam9000 , Thank you. I saw this earlier and am still a little lost. Is there some more information on how to get the Debug test configuration working. He said in the video he wasn't going to go into setting up for that in particular :( . Can you point to some other resource that might help with setting up DAP in more depth?

AnthonyMBonafide avatar May 17 '24 22:05 AnthonyMBonafide

@AnthonyMBonafide sorry, I don't know. Maybe try asking here: https://github.com/leoluz/nvim-dap-go

dam9000 avatar May 18 '24 07:05 dam9000

@dam9000, I see it listed in the README on how to run them. Could you point me in the right direction of how you would suggest to add this as a key map for Go projects? My thinking at this point is to have a keymap to basically execute :lua require('dap-go').debug_test(). Maybe slightly better would be to have the Debug test option execute that command. Not really sure. Any suggestions?

AnthonyMBonafide avatar May 24 '24 01:05 AnthonyMBonafide

So you want to translate this vimscript to lua:

nmap <silent> <leader>td :lua require('dap-go').debug_test()<CR>

lua:

vim.keymap.set('n', '<leader>td', function()
  require('dap-go').debug_test()
end, { silent = true, desc = 'Debug Test' })

dam9000 avatar May 24 '24 07:05 dam9000

@dam9000 , yes thank you. Also, how to I configure this just for Go as other languages cannot leverage that? Should I set up that mapping on attach for dap-go ? IDK if that even makes sense or how to do that correctly. I'll look into the docs and if I figure it out I will create a PR.

AnthonyMBonafide avatar May 24 '24 16:05 AnthonyMBonafide

You can extract nvim-dap-go out of the dependency list of nvim-dap and set nvim-dap-go to load only on ft = 'go'. Then you can set your keymaps in the config function of nvim-dap-go, which will bind the keymap only on plugin load (when you open a file whose filetype is go).

if I figure it out I will create a PR.

I think that nvim-dap-go exists here only to be as an example of how to add language specific debuggers, so providing all of the keybindings may not be a goal

VlaDexa avatar Jun 11 '24 03:06 VlaDexa

Please seek further assistance at the specific dap adapter's repository.

feoh avatar Jul 22 '24 02:07 feoh