mortenscheel / editor-links
A lightweight PHP package that generates clickable links to open files directly in your preferred code editor.
Requires
- php: ^8.2.0
Requires (Dev)
- laravel/pint: ^1.18.3
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^9.9
- pestphp/pest: ^3.7.1
- pestphp/pest-plugin-type-coverage: ^3.2.3
- phpro/grumphp-shim: ^2.10
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- rector/rector: ^2.0.4
- symfony/var-dumper: ^7.2.0
This package is auto-updated.
Last update: 2025-03-15 19:27:06 UTC
README
EditorLinks
A lightweight PHP package that generates clickable links to open files directly in your preferred code editor.
Installation
You can install the package via composer:
composer require mortenscheel/editor-links
Usage
<?php use function Scheel\EditorLinks\editorLink; // Generate a link to open a file at a specific line in your editor $link = editorLink('/path/to/your/file.php', 42); // Output: phpstorm://open?file=/path/to/your/file.php&line=42 echo $link;
Supported Editors
EditorLinks supports the following editors out of the box:
phpstorm
(default)sublime
textmate
emacs
macvim
idea
vscode
vscode-insiders
vscode-remote
vscode-insiders-remote
vscodium
nova
xdebug
atom
espresso
netbeans
Configuration
Setting the editor
By default, EditorLinks uses PhpStorm as the target editor. You can change this by setting the EDITOR_LINK_EDITOR
environment variable:
# In your .env file or shell environment
EDITOR_LINK_EDITOR=vscode
Using a custom link format
Alternatively you can provide a custom link format with %file
and %line
placeholders:
EDITOR_LINK_FORMAT=custom-scheme://open?file=%file&line=%line
Path Mapping
If you're working in an environment where file paths need to be transformed (like Docker or WSL), you can set up path mapping using the EDITOR_LINK_MAPPING
environment variable:
# Format: localPath:remotePath
EDITOR_LINK_MAPPING=/var/www/html:/Users/username/Projects
This will replace /var/www/html
with /Users/username/Projects
in file paths.
Examples
HTML link to error location
$link = editorLink($exception->getFile(), $exception->getLine()); echo "<a href=\"$link\">Open in editor</a>";
Terminal link in console commands
// In Symfony Console command $output->writeln("<href=$link>Link label</>"); // In Laravel Artisan commands $this->output->writeln("<href=$link>Link label</>"); $this->info("<href=$link>Link label</>");
Contributing
Contributions are welcome! If you'd like to add support for another editor or improve the package, please feel free to submit a pull request.
License
The MIT License (MIT). Please see License File for more information.