aik099/PhpStormProtocol

How to manage it to work with projects on vagrant

Closed this issue · 6 comments

I'm using a vagrant box as my development environment. My host OS is windows 7 and the guest is a linux based machine. My code base is shared between host and guest so the path of the project is something like D:\vagrant\PROJECT_NAME\code and /var/www/html/NAME/on the host and guest machines respectively.

The generated link is something like pstorm://open/?url=file:///var/www/html/NAME/app/cache/dev/classes.php&line=2061 which has not a valid path on the windows. How can I mange it to work? Maybe adding two options to replace first part of the file path?

There are 2 options:

  • use relative vs absolute path (only keep file path part, that is common to both places) and PhpStorm might figure out which file that is in the opened project (because it's not cross-os solution I personally don't recommend this)
  • in your app do the replacement, so the links to PhpStorm are already using path on Windows, rather than Vagrant, where web server runs, which built them (I'm doing that with all my projects)

Can you explain more?
I forgot to mention that I'm using Symfony so, the pages that contain exception will be generated by Symfony itself.

Looking at #12 I can suggest tweaking symfony part, where the url is built so that url is already having paths on local machine.

I've found code responsible for file link building: https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php#L182-L197

I propose creating PR to symfony/FrameworkBundle that would work like this:

  • have 2 settings in config (right after place where you specify ide setting (see http://symfony.com/doc/current/reference/configuration/framework.html#ide):
    • local_path - base path on machine, where PhpStorm runs
    • remote_path - base path on machine, where Web Server runs (e.g. Vagrant)
  • pass values of both parameters to CodeHelper class by injecting config values in service container
  • in getFileLink method:
    • if both settings are missing don't do anything special
    • if both settings are present to replacement from path beginning of remote_path value to local_path value

see #14 to let the snippet replace the external absolute path with the network share you've mapped.

Closing due no obvious solution. Feel free to reopen if needed.