Jump to content

Tracy Debugger editor links / protocol handler for PHPStorm on Windows / WSL


dotnetic
 Share

Recommended Posts

Update August 2022:
There finally now is a native way of opening the correct file, if tracy throws an error.
You have to use Jetbrains Toolbox for this to work.

Go to tracy's 'Editor links' setting and in the input write this, and replace projectname with the PHPStorms project name:

jetbrains://php-storm/navigate/reference?project={projectname}&path=%file:%line

Also if you are using a folder structure, where the PW installation lies not in the root, then you want to modify the "Local root path" setting in Tracy.

Here is an example of my settings:

image.thumb.png.b2257c34a25c4036e18458e5db8acd52.png

 

Original post from 2019

Tracy Debugger offers an Editor protocol handler link so you can jump directly to a file from a Tracy Debugger dump message. Unfortunately this does not work on Windows, as the URI protocol handler isn't implemented in the Windows version (see link). However, all IDEA products (IntelliJ, PHPStorm, etc.) provide a REST API from which you can open files.

The syntax is http://localhost:63342/api/file//absolute/path/to/file.kt for absolute pathnames (please note the double backslash behind "file") and http://localhost:63342/api/file/relative/to/module/root/path/to/file.kt for relative filenames.

To use this, you have to set up Tracy with the following parameter: 

http://localhost:63342/api/file/%file:%line:0

If you click on a link now in Tracy, PHPStorm will focus and ask for permission to open the file.

image.png.a7cb160444f8d94d0ee3fe617553d186.png

ATTENTION: PHPStorm has to be opened and also your project has to be opened (so PHPStorm knows the root for relative path). This is a little bit cumbersome, but better than nothing.

Ping @adrian to bring this to your attention.

  • Thanks 1
Link to comment
Share on other sites

@adrian The solution you linked to could work (not tested), I found a similar script that I tried, that didn't work. But the script utilizes the Windows Scripting host and requires you to put the path in the .js file, which is a detour.

My solution provides a native way. Not saying, that this is the correct way, but one more way.

You could add the syntax with a comment "For Windows and PHPStorm use the following syntax" to Tracy's settings. I think, this could help some people.

Link to comment
Share on other sites

I also tried Nette's solution and it does work on Windows 10 (but with different paths, as I am Using Jetbrains Toolbox to install PHPStorm), there is an alert before opening the file.

image.png.08952434884d71b5b631556bf0d14c2d.png

After clicking ok, its working fine, but I have to focus PHPStorm manually, as the title of the window is always different, depending on which file you have opened.

Link to comment
Share on other sites

Yeah thought often about it, but PHPStorm offers me features that VScode does not have (yet) or are not that comfortable and that are important for me.

And I don't switch my editor/IDE just because of this small issue.

  • Like 1
Link to comment
Share on other sites

17 hours ago, Jens Martsch - dotnetic said:

You could add the syntax with a comment "For Windows and PHPStorm use the following syntax" to Tracy's settings. I think, this could help some people.

I think rather than using that custom syntax, it maybe makes more sense to install the protocol handler that @bernhard linked to. Actually, I just noticed that in the Tracy settings I was linking to a protocol handler for PHPStorm, but it was Linux only, so I have linked to the one bernhard mentioned instead.

Link to comment
Share on other sites

9 minutes ago, adrian said:

Do you still need to modify the js file if you install https://github.com/aik099/PhpStormProtocol ?

Yes. If you look into the file https://github.com/aik099/PhpStormProtocol/blob/master/PhpStorm Protocol (Win)/run_editor.js there are two variables you have to change and if you are using Jetbrain Toolbox to install and update your IDE, then even the paths in https://github.com/aik099/PhpStormProtocol/blob/master/PhpStorm Protocol (Win)/run_editor.js#L22 are completely different.

  • Like 1
Link to comment
Share on other sites

21 hours ago, adrian said:

I just want to ping a few other Windows users: @Robin S @bernhard @tpr to get their experience with this.

All good if another way is added to open files in PhpStorm, but I use the editor:// protocol with PhpStorm and never had any problem with it. It's been a long time since I set it up but I expect I followed the PhpStorm docs and I don't remember it being difficult.

  • Like 2
Link to comment
Share on other sites

@Jens Martsch - dotnetic, I had set it up some years ago under win7 with a (sort of) proxy batchfile. It is a single file, that I pointed the modules default protocol settings to. Don't know if this can be of help for you, as I hadn't read all the posts here. But here is the windows batchfile that I use(d):

@GOTO START
<?php
	$editor = "C:\\Program Files\\NuSphere\\PhpED\\phped.exe";
	if($argc > 1) $url = $argv[1];
	list($file, $line) = explode('&line=', str_replace(array('editor://open/?url=file://', ''), '', urldecode($url)));
	if(is_file($file)) {
		exec("\"$editor\" \"$file\" --line=$line");
	}
	exit(0);
?>
EXIT
:START
@ECHO OFF
SET PHP=C:\php\php.exe
%PHP% "%0" %*
EXIT
  •  
  •  

Short explanation:

  • the batch script (maybe named something like "tracyopener.bat", located somewhere in the system path) is called with the tracy default params for file & line.
  • the first line tells the win batch interpreter to skip the PHP section and start at the line where the php exe is defined
  • the next line calls the PHP interpreter, passes the own script to it "%0", followed by all other params "%*", what is an alias for %1 - %9
  • when the PHP interpreter processes the script, the first line is interpreted as HTML or text output and therefor ignored.
  • the next lines get and prepare the passed params for usage with my preferred editor NuSphere PhpEd, using the exec() function.

 

  • Like 1
Link to comment
Share on other sites

Hey @horst Your solution is very similar how scripts like https://github.com/aik099/PhpStormProtocol work. 

As mentioned before this is a workaround and a hacky way, and my solution provides a native alternative which works. 

I am not searching for another hacky solution, I just wanted to provide a native way of handling URI schemes in Tracy Debuger

Link to comment
Share on other sites

  • dotnetic changed the title to Tracy Debugger protocol handler for PHPStorm on Windows / WSL
  • dotnetic changed the title to Tracy Debugger editor links / protocol handler for PHPStorm on Windows / WSL
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...