How to Open a File in Editor from Tracy? (IDE Integration)

When the error page is displayed, you can click on file names and they will open in your editor with the cursor on the corresponding line. Files can also be created (action create file) or bug fixed in them (action fix it). In order to do this, you need to configure the browser and the system.

Tracy opens files via URLs of the form editor://open/?file=%file&line=%line, i.e. with the editor:// protocol. We will register our own handler for this one. This can be any executable file that process the parameters and starts our favorite editor.

You can change the URL in the Tracy\Debugger::$editor variable, or disable click-through by setting Tracy\Debugger::$editor = null.

Windows

  1. Download the appropriate files from the Tracy repository to disk.
  2. Edit open-editor.js and uncomment or edit the path to your editor in settings:
var settings = {

	// PhpStorm
	editor: '"C:\\Program Files\\JetBrains\\PhpStorm 2018.1.2\\bin\\phpstorm64.exe" --line %line% "%file%"',
	title: 'PhpStorm',

	// NetBeans
	// editor: '"C:\\Program Files\\NetBeans 8.1\\bin\\netbeans.exe" "%file%:%line%" --console suppress',

	// Sublime Text 2
	// editor: '"C:\\Program Files\\Sublime Text 2\\sublime_text.exe" "%file%:%line%"',

	...
}

...

Be careful and keep the double slashes in the paths.

3. Register the handler for editor:// protocol in the system.

This is done by running install.cmd. You need to run it as an Administrator. The open-editor.js script will now serve the editor:// protocol.

In order to open links generated on other servers, such as a production server or Docker, add a remote to local URL mapping to open-editor.js:

	mappings: {
		// remote path: local path
		'/var/www/nette.app': 'W:\\Nette.web\\_web',
	}

Linux

  1. Download the appropriate files from the Tracy repository to directory ~/bin.
  2. Edit open-editor.sh and uncomment or edit the path to your editor in the variable editor:
#!/bin/bash

# Emacs
#editor='emacs +$LINE "$FILE"'

# gVim
#editor='gvim +$LINE "$FILE"'

# gEdit
#editor='gedit +$LINE "$FILE"'

# Pluma
#editor='pluma +$LINE "$FILE"'

...

Make it executable:

chmod +x ~/bin/open-editor.sh

If the editor you are using is not installed from the package, the binary will probably not have a path in $PATH. This can be easily corrected. In the ~/bin directory, create a symlink on the editor binary.

3. Register the handler for editor:// protocol in the system.

This is done by running install.sh. The open-editor.js script will now serve the editor:// protocol.

macOS

Editors like PhpStorm, TextMate, etc. allow you to open files via a special URL, which you just need to set:

// PhpStorm
Tracy\Debugger::$editor = 'phpstorm://open?file=%file&line=%line';
// TextMate
Tracy\Debugger::$editor = 'txmt://open/?url=file://%file&line=%line';
// MacVim
Tracy\Debugger::$editor = 'mvim://open/?url=file://%file&line=%line';
// Visual Studio Code
Tracy\Debugger::$editor = 'vscode://file/%file:%line';

If you are using standalone Tracy, put the line before Tracy\Debugger::enable(), if Nette, before the $configurator->enableTracy() in Bootstrap.php.

Unfortunately, actions create file or fix it do not work on macOS.

Demos

Fixing bug:

Creating a new file:

Troubleshooting

  • In Firefox you may need to allow custom protocol execution in about:config by setting network.protocol-handler.expose.editor to false and network.protocol-handler.expose-all to true. It should be allowed by default, however.
  • If it's not all working immediately, don't panic. Try to refresh the page, restart browser or computer. That should help.
  • Here is the link

    to correct any errors: Input Error: There is no script engine for file extension ".js" or Maybe you associated ".js" file to another app, not JScript engine.

Starting from Google Chrome version 77 you will no longer see the checkbox “Always open these types of links in the associated app” when editor is opened through a link. Workaround for Windows: create file fix.reg:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\URLWhitelist]
"123"="editor://*"

Import it by double clicking and restart Chrome.

In case of more troubles or questions, ask on forum.