nvim-lua / kickstart.nvim

A launch point for your personal nvim configuration
MIT License
18.86k stars 21.57k forks source link

Debug Test For Go Not Working #940

Closed AnthonyMBonafide closed 2 months ago

AnthonyMBonafide commented 4 months ago

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

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.

dam9000 commented 4 months ago

@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)

AnthonyMBonafide commented 4 months ago

@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?

dam9000 commented 4 months ago

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

AnthonyMBonafide commented 4 months ago

@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?

dam9000 commented 4 months ago

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' })
AnthonyMBonafide commented 4 months ago

@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.

VlaDexa commented 3 months ago

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

feoh commented 2 months ago

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