vscode-php-debug icon indicating copy to clipboard operation
vscode-php-debug copied to clipboard

Add `launchTask` option for debugging tasks

Open AlmightyTritan opened this issue 4 years ago • 5 comments

Consider adding the ability to launch a task after the debugger has started. As of right now I can start a task that runs a composer command, but by the time VSCode has detected that the task is at a point where the debugger can start, it finishes and is past my breakpoint.

If we had the option to have something like launchTask to go alongside preLaunchTask and postLaunchTask we would be golden.

Alternatively, the only reason I am using task instead of just having the debugger call composer directly, is that the env option for the debugger doesn't work.

AlmightyTritan avatar Sep 24 '21 14:09 AlmightyTritan

Hi. preLaunchTask and postDebugTask are handled by VSCode, not this extension. I think I can implement running tasks (https://code.visualstudio.com/api/references/vscode-api#tasks) but the downside would be that there is no way to interact with the executed process (stdio, killing the process).

That said, I'd rather first focus on the issues you are having with ENV. program is indeed exactly what you need. It seems to work here:

    {
      "name": "Launch currently open script",
      "type": "php",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}",
      "port": 0,
      "runtimeArgs": ["-dxdebug.start_with_request=yes"],
      "env": {
        "XDEBUG_MODE": "debug,develop",
        "XDEBUG_CONFIG": "client_port=${port}",
        "TESTENV": "testenv"
      },
      "xdebugSettings": {
        "max_depth": 5
      },
    },
<?php

var_dump($_SERVER['TESTENV']);
string(7) "testenv"

This is my setup:

Version: 1.60.1 (user setup) Commit: 83bd43bc519d15e50c4272c6cf5c1479df196a4d Date: 2021-09-10T17:07:10.714Z Electron: 13.1.8 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19043

PHP Version => 8.1.0RC1 Zend Engine v4.1.0RC1, Copyright (c) Zend Technologies with Xdebug v3.1.0beta1, Copyright (c) 2002-2021, by Derick Rethans

Let me know what's your setup like and I'll see if I can reproduce the problem with the missing env.

zobo avatar Sep 25 '21 07:09 zobo

Right okay that's a fair point with the no interactivity. I didn't think about that. I'll try and get some more information about the ENV issue I've been experiencing shortly.

AlmightyTritan avatar Sep 28 '21 11:09 AlmightyTritan

Okay so I have the following launch.json config used to run my projects tests:

{
  "name": "Test",
  "type": "php",
  "request": "launch",
  "port": 9005,
  "cwd": "${workspaceRoot}",
  "program": "/usr/local/bin/composer",
  "env": {
    "XDEBUG_MODE": "debug,develop", 
    "XDEBUG_CONFIG": "client_port=9005"
  },
  "args": [
    "test"
  ],
  "presentation": {
    "hidden": false,
    "group": "test",
    "order": 1
  }
},

How ever when I run it, it seems to throw the following error in the Debug Console:

Error: spawn php ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn php',
  path: 'php',
  spawnargs: [ '/usr/local/bin/composer', 'test' ]
}

As far as I can tell, this seems to be happening because it's completely replacing the environment variables with what is in the env option, rather then merging them with the systems environment variables. I came to this conclusion because if I was to add back in the PATH environment variable, it's able to resolve the binary for PHP and continues for a bit.

AlmightyTritan avatar Oct 01 '21 19:10 AlmightyTritan

Interesting. I have not yet encountered such a case. I'll try it here. Are you on Linux? Can you copy the information from VS Code / Help / About?

Also, try to set runtimeExecutable to your php full path. I suspect that composer is spawning a sub process an that's the reason behind the error.

What does you "test" composer target do?

zobo avatar Oct 01 '21 20:10 zobo

I'm using Dev Containers in VS Code so it is running under Linux, however the About information doesn't really represent that but here is the info in case it may still be useful.

Version: 1.60.2 (user setup)
Commit: 7f6ab5485bbc008386c4386d08766667e155244e
Date: 2021-09-22T12:00:31.514Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

I'll give setting the runtimeExecutable a shot here and see if that helps.

My test composer target runs the Kahlan CLI to start up my unit tests:

{
  "test": "kahlan"
}

AlmightyTritan avatar Oct 06 '21 13:10 AlmightyTritan