Skip to content

workspaceFolder variable substitution in launch.json or tasks.json should use URI for virtual filesystems #197377

@zobo

Description

@zobo

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.84.0 (user setup)
  • OS Version: Windows_NT x64 10.0.22621

Steps to Reproduce:

  1. Install a remote virtual filesystem extension like Kelvin.vscode-sshfs or liximomo.remotefs
  2. When connected to a remote FS, create a remote launch.json and use ${workspaceFolder} somewhere where it will be replaced - the same can be seen with a remote tasks.json
  3. The variable is replaced not with it's URI form but with its fsPath form.

Here is an example tasks.json than can quickly reproduce the issue. Note the options.cwd.

{
	"version": "2.0.0",
	"tasks": [
	  {
		"label": "echo 2",
		"type": "shell",
		"options": {
			"cwd": "c:\\temp"
		},
		"command": "echo ${workspaceFolder}"
	  }
	]
  }

And a xdebug.php-debug specific launch.json.

{ "version": "0.2.0", "configurations": [ 
	{ 
		"name": "Listen for Sail Xdebug", 
		"debugServer": 4711,
		"type": "php", 
		"request": "launch", 
		"port": 9003, 
		"pathMappings": { "/var/www/html": "${workspaceFolder}" }, 
		// "pathMappings": { "/var/www/html": "ssh://docker.local/users/zobo/laravel-test" }, 
	}
]}

Additional info.

In the specific case of debugging a remote PHP script - mounted over SSHFS virtual filesystem, this is needed so that the php-debug adapter can convert a /var/www/html/index.php path to a VFS uri of ssh://users/zobo/laravel-test/index.php.

I have added the virtualWorkspaces capability, but that did not help. I believe this is the offending code:

case 'workspaceRoot':
case 'workspaceFolder':
return normalizeDriveLetter(this.fsPath(getFolderUri(VariableKind.WorkspaceFolder)));

Related php-debug issue: xdebug/vscode-php-debug#873
Related docs https://code.visualstudio.com/api/extension-guides/virtual-workspaces

Example XXX.code-workspace config for sshfs and remotefs

{
	"folders": [
		{
			"name": "example-app — (Remote)",
			"uri": "sftp://dockerrfs/"
		},
		{
			"path": ".."
		},
		{
			"name": "SSH FS - docker",
			"uri": "ssh://users/zobo/laravel-test"
		}
	],
	"settings": {
		"sshfs.configs": [
			{
				"name": "docker",
				"host": "192.168.56.101",
				"username": "root",
				"root": "/users/zobo/laravel-test",
				"agent": "pageant"
			}
		],
		"remotefs.remote": {
			"dockerRFS": {
				"scheme": "sftp",
				"host": "192.168.56.101",
				"username": "root",
				"rootPath": "/users/zobo/laravel-test",
				"agent": "pageant"
			}
		}
	}
}

I could solve the problem by implementing this in the php-debug resolveDebugConfiguration

                if (folder && folder.uri.scheme !== 'file') {
                    // replace 
                    if (debugConfiguration.pathMappings) {
                        for (const key in debugConfiguration.pathMappings) {
                            debugConfiguration.pathMappings[key] = debugConfiguration.pathMappings[key].replace('${workspaceFolder}', folder.uri.toString())
                        }
                    }
                }

(This just replaces the variable in one specific key, should be everywhere...)

Label: debug

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugvariable-resolving

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions