Skip to content

Add support for environment variables in pathMappings #1069

Closed

Description

@Tolsee

Description

Just like how vscode handle environment variables, can we enable pathMappings to support env variables as well?

Launch config would look something like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/${env:YOUR_ID}": "${workspaceFolder}/app"
      },
      "ignore": ["**/vendor/**/*.php"]
    }
  ]
}

Activity

  1. Tolsee commented on Nov 13, 2025

    @Tolsee
    Author
  2. zobo commented on Nov 13, 2025

    @zobo
    Contributor

    Will look at this asap

  3. Tolsee commented on Nov 13, 2025

    @Tolsee
    Author

    Thanks @zobo!

  4. zobo commented on Nov 13, 2025

    @zobo
    Contributor

    The real question here is, why is this not already working? https://code.visualstudio.com/docs/reference/variables-reference#_environment-variables

  5. Tolsee commented on Nov 13, 2025

    @Tolsee
    Author

    I think the substitution works for values, not the keys as shown in the example

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Listen for Xdebug",
          "type": "php",
          "request": "launch",
          "port": 9003,
          "pathMappings": {
            "/var/www/${env:YOUR_ID}": "${workspaceFolder}/app"
          },
          "ignore": ["**/vendor/**/*.php"]
        }
      ]
    }
    

    It may have worked if we have pathMappings to be of type {local:string;remote:string}[]?

  6. zobo commented on Nov 15, 2025

    @zobo
    Contributor

    I remembered something about this. I already reported this and provided a patch but not sure what happened to this.
    microsoft/vscode#245798 microsoft/vscode#245989

    I looks like it got merged, but I can't find the code in main.... strange. I need to check this before I merge this patch.

  7. zobo commented on Nov 16, 2025

    @zobo
    Contributor

    I went back and tested this without your patch. And as it looks to me, things work as they should. This was my launch,json

        {
          "debugServer": 4711, // Uncomment for debugging the adapter
          "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}"
          },
          "ignoreExceptions": ["IgnoreException"],
          "pathMappings": {
            "/var/www/${env:YOUR_ID}": "${workspaceFolder}/app"
          },
          "log": false
        },

    And when I debugged what I get from VSC to the adapter on launch request it shows that the ${env:YOUR_ID} was substituted.

    Image

    So, can you look at what the situation is on your end? This is my VSC version

    Version: 1.105.1 (user setup)
    Commit: 7d842fb85a0275a4a8e4d7e040d2625abbf7f084
    Date: 2025-10-14T22:33:36.618Z
    Electron: 37.6.0
    ElectronBuildId: 12502201
    Chromium: 138.0.7204.251
    Node.js: 22.19.0
    V8: 13.8.258.32-electron.0
    OS: Windows_NT x64 10.0.26100
    
  8. Tolsee commented on Nov 20, 2025

    @Tolsee
    Author

    I got this issue in originally in Cursor. Today, I checked it in VS Code and it is working well like you described. Maybe the fix you didn't landed on Cursor? What do you think about keeping this for any other VS Code clones which might not have latest VS Code?

  9. zobo commented on Nov 20, 2025

    @zobo
    Contributor

    I'm reluctant to merge this, as this should be fixed by the IDEs... Perhaps try to open an issue with Cursor - they probably do a periodic sync with the main code-base. If ti doesn't work out with them, I'll reconsider merging.

  10. zobo commented on Dec 22, 2025

    @zobo
    Contributor

    I will close this as it should be fixed in the IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions