mortenscheel/editor-links

A lightweight PHP package that generates clickable links to open files directly in your preferred code editor.

v0.2.0 2025-03-14 21:10 UTC

This package is auto-updated.

Last update: 2025-03-15 19:27:06 UTC


README

GitHub Workflow Status (master) Total Downloads Latest Version License

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.

Credits