Nette Documentation Preview

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

.[perex]
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":https://github.com/nette/tracy/tree/master/tools/open-in-editor/windows to disk.

2. Edit `open-editor.js` and uncomment or edit the path to your editor in `settings`:

```js
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`:

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


Linux
=====

1. Download the appropriate files "from the Tracy repository":https://github.com/nette/tracy/tree/master/tools/open-in-editor/linux to directory `~/bin`.

2. Edit `open-editor.sh` and uncomment or edit the path to your editor in the variable `editor`:

```shell
#!/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:

```shell
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. .[note]


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:

```php
// 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:

<iframe width="560" height="315" src="https://www.youtube.com/embed/3ITT4mC0Eq4?rel=0&amp;showinfo=0" frameborder="0" allow="encrypted-media" allowfullscreen></iframe>

Creating a new file:

<iframe width="560" height="315" src="https://www.youtube.com/embed/AJ_FUivAGZQ?rel=0&amp;showinfo=0" frameborder="0" allow="encrypted-media" allowfullscreen></iframe>


Troubleshooting
===============

- In Firefox you may need to [allow |http://kb.mozillazine.org/Register_protocol#Firefox_3.5_and_above] 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 |https://www.winhelponline.com/blog/error-there-is-no-script-engine-for-file-extension-when-running-js-files/]
 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 |https://forum.nette.org].

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.