Closed przepompownia closed 11 months ago
How do you debug currently with PHP and Neovim?
Hi @olimorris
I use nvim-dap for two years. I have no problem with running DAP adapter separately and run some test both from CLI and by neotest and then stop on a breakpoint.
By default I have disabled XDebug. If I need, I append -dzend_extension=xdebug.so
. To avoid complicating this PR, I assume here that XDebug is enabled permanently. Ultimately I would like to be able to use a separate phpunit_cmd
per strategy if possible.
It's only for convenience. If it would require a lot of work to complete, we may give up and work as before.
Do you need some standalone reproduction containing neotest with this change, nvim-dap, phpunit and simple test? I can prepare it if it would be helpful.
I haven't looked into this in any detail however I would have thought that we could take your existing config for running PHPUnit tests and triggering a debugger and use it in this adapter?
https://github.com/przepompownia/neotest-phpunit-example - please look at the demo. make start
should be enough to install dependencies and run, assuming that you have composer and php with xdebug.
Only five user mappings are defined here
vim.keymap.set('n', '<Esc>', vim.cmd.fclose)
vim.keymap.set({'n'}, ',dr', dap.continue, {})
vim.keymap.set({'n'}, ',dc', dap.close, {})
vim.keymap.set({'n'}, ',nr', require('neotest').run.run, {})
vim.keymap.set({'n'}, ',nd', function () require('neotest').run.run({strategy = 'dap'}) end, {})
and the only user command PhpUnitWithXdebug
to run the test manually.
Notice that on ,nd
(i.e. :lua require('neotest').run.run({strategy = 'dap'})
) no test is run.
@olimorris my English is still poor. I didn't fully understand the intent of your question. It was easier for me to create a demo :wink: It helped me use the adapter in a way I hadn't used before (program
, runtimeArgs
etc. - see https://github.com/xdebug/vscode-php-debug#supported-launchjson-settings).
This looks great. I'll try and look at this in the next couple of weeks; I'm rather time poor at the moment, unfortunately.
One of the disadvantages is that phpunit_cmd
cannot be table. The program
field in the adapter must be string if I know. At the moment I added validation for that.
Sorry I haven't got a round to looking at this.
I'm happy to merge this if you think it's finished?
I have tested it on https://github.com/phpactor/phpactor/pull/2476 without any problem. From my perspective it can be merged.
Thanks for your efforts on this!
Thanks for merging! I hope it will be useful to someone else.
hey @przepompownia do you have any example how to use this on lazyvim?
for example: https://github.com/eerison/lazyvim/blob/main/lua/plugins/php.lua#L34
it is related with: https://github.com/olimorris/neotest-phpunit/issues/25
I looked into https://github.com/nvim-neotest/neotest-python to see how
dap
strategy can be implemented and tried to apply something similar here in its simplest form to start with. Withand
:lua require("neotest").run.run({strategy = 'dap'})
I see (after setting some breakpoint) that the adapter starts as expected (with correct parameters) but it seems that the test does not run (at all or when the adapter is ready).Running then
:lua require("neotest").run.run({})
causes stopping the test at the breakpoint.Can anyone help me?