Repository navigation
Description
I was wondering if it's possible to map more than one path in vscode?
I'm working with Vagrant to develop a WordPress theme, and I'm using two shared folders on the guest.
I'm sharing one folder for the root of WordPress installation called www and the other one which is in the same path called main, shared on the guest within themes folder of WordPress installation.
Vagrantfile:
config.vm.synced_folder "./www/", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
config.vm.synced_folder "./main", "/var/www/wp-content/themes/main", :mount_options => ["dmode=777", "fmode=666"]
The problem is with the current launch.json file I'm not able to define two paths for my source codes, and when I'm debugging, VSCode doesn't hit the breakpoints anywhere in the main folder!
Take a look at the hierarchy below:
It's worth mentioning I'm currently achieving this using Sublime Text, but I'd like to work in VSCode instead.
Sublime Text project settings:
{
"settings": {
"xdebug": {
"path_mapping": {
"/var/www/wp-content/themes/main" : "/Users/[user]/Documents/[project]/main",
"/var/www" : "/Users/[user]/Documents/[project]/www",
},
"super_globals": true,
"close_on_stop": true
}
}
}
Extra info:
PHP version: 5.6.14-1
XDebug version: 2.3.3
Your launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"serverSourceRoot": "/var/www",
"localSourceRoot": "/Users/[user]/Documents/[project]/www"
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Thanks in advance.
Amin

Activity
felixfbecker commentedon Aug 16, 2016
That
path_mappingAPI looks nice. Feel free to do a PR 🙂aminpaks commentedon Aug 16, 2016
What's PR, what do you mean?
felixfbecker commentedon Aug 16, 2016
A Pull Request. I currently don't have much time to spend on this project and wouldn't use this feature myself. But you can fork the repository, add the feature and then open a Pull Request which I will merge in.
The source mapping is done here: https://github.com/felixfbecker/vscode-php-debug/blob/master/src/paths.ts
You could change the signature to accept a path map instead of
localSourceRootandserverSourceRoot. Then add the launch.json setting in package.json and theLaunchArgumentsinterface. When calling the functions, putlocalSourceRootandserverSourceRootinto the path mapping object for backwards compatibility.nacr commentedon Jan 3, 2017
+1
felixfbecker commentedon Jan 3, 2017
Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.

johnrom commentedon May 30, 2017
I have a feeling that it makes more sense to map $local_folder: $vm_source because there is a guarantee that a local folder cannot be mapped to multiple locations within the VM, whereas multiple local folders could potentially be mapped to a single location within the VM. Does that make sense?
... Not that I see the use case, but I see it being a possibility.
johnrom commentedon Jun 25, 2017
Added a PR for this issue, also in regards to my above comment, I went with the original suggested
server => localconfigurationgondwanasoft commentedon Jul 15, 2017
This feature would also help massively for concrete5 (https://www.concrete5.org/) CMS development. Concrete5 uses complex symfony2 routing, which makes stepping through code impossible with only a single URL:path mapping.
I note that VS Debugger for Firefox (https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-firefox-debug) supports an array of pathMappings.
felixfbecker commentedon Jul 15, 2017
I think you are confusing application/web routing with local/server path mapping
gondwanasoft commentedon Jul 16, 2017
You could well be right. Concrete5 claims to have routing, and the path used to render a page can vary (eg, to over-ride a default layout template or core class behaviour).
In a concrete5 project, I can use vscode-php-debug to debug some code (eg, stepping, breakpoints and exceptions), but not other code on the same locally-hosted site. This suggests that the localSourceRoot and serverSourceRoot are set correctly for some of the code, and that something else is going on.
I accept that this is a low priority and of no use to you, but here's some more info: https://documentation.concrete5.org/tutorials/override-almost-any-core-file-in-5-7
I can provide more links (but no knowledge).
ETA: Ignore me. For some reason, deleting both ...SourceRoot settings allows all debug features to work in all files; when I set those values, debugging would only work on SOME pages. Don't ask me why.
johnrom commentedon Jul 17, 2017
In case you are wondering what a valid use-case scenario for this is (at least for me), I am attempting to standardize a containerized workflow. If you are developing a PHP CLI project which is independent of and performs actions on a secondary PHP project (e.g., a website), but loads the entirety of both projects such that
/bin/cli-projectand/var/www/htmlboth need mappings in order to detect an error in either project, you quickly hit a wall with this extension. I think the lack of this functionality currently puts VS Code at a distinct disadvantage for developing applications likewp-cliandcomposer, when other editors support this functionality. Maybe containers will fizzle out, but it is my opinion that most projects will begin to standardize a contribution environment based on containers, as they provide an easy way to provision and modify an exact server environment. So for me, this issue is such a priority that I dove into typescript for the first time and contributed a PR :)bbak commentedon Aug 31, 2017
We have the same Problem here, but with a different Use Case: We're using PHP's "auto_prepend_file" to work around a nasty and longstanding bug in PHP related to Syslog Logging. The File is outside of the Web-Root, even outside the Project, but readable/accessible.
cardonator commentedon Nov 1, 2017
This would be handy in cases where using docker to run tests and the different docker environments have different root folders for the path mappings. Currently, you can only have one path mapping or you have to use a completely separate debug configuration, which can be annoying.
lbod commentedon Nov 14, 2017
I left a comment on the wrong issue, I don't mind having a look at this as I'd rather not use atom.
Same issue for me that I can't use Docker volume mappings to a php docker container to map themes and plugins from different local root paths.
However I'd like a bit of help from a dev to ask a few questions (gitter?) as it's a fairly large code base I've never seen before till now :)
I've had a look through and see a couple of areas that might need changed but really it's just a map of local to remote paths that need a getter to search and return.
felixfbecker commentedon Nov 14, 2017
Actually there is a PR open for this, #175. I never found the time to test it, but if you could check it out and tell me if it works for you, we could merge it in.
lbod commentedon Nov 14, 2017
@felixfbecker thanks, I should have found myself. I'll have a look how to test
clearfickle commentedon Nov 16, 2017
@felixfbecker I want to try it but I can't seem to package this extension. Forgive me if I missed something, as this is the first time I'm trying to build an extension.
felixfbecker commentedon Nov 16, 2017
Should work now on master.
clearfickle commentedon Nov 21, 2017
@felixfbecker His PR works ❤️❤️❤️
feat: path mappings (#175)