Skip to content

Commit

Permalink
feat: support env vars for editorLink()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 11, 2024
1 parent afdef7e commit 43ed1de
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,23 @@ public function editLinks($options = null, $list = true, $size = 32)

public function editorLink($path)
{
$tracy = $this->wire->config->tracy;
if (is_array($tracy) and array_key_exists('localRootPath', $tracy))
$root = $tracy['localRootPath'];
else $root = $this->wire->config->paths->root;
$link = str_replace($this->wire->config->paths->root, $root, $path);
$rootPath = $this->wire->config->paths->root;
$editor = "vscode://file/%file";

if ($this->wire->modules->isInstalled("TracyDebugger")) {
$tracy = $this->wire->modules->get("TracyDebugger");
$rootPath = $tracy->localRootPath;
$editor = $tracy->editor;
}

$rootPath = getenv("TRACY_LOCALROOTPATH") ?: $rootPath;
$editor = getenv("TRACY_EDITOR") ?: $editor;

$rootPath = rtrim($rootPath, "/") . "/";
$link = str_replace($this->wire->config->paths->root, $rootPath, $path);
$link = Paths::normalizeSeparators($link);

$handler = $this->ideLinkHandler ?: "vscode://file/%file";
$handler = str_replace(":%line", "", $editor);
$link = str_replace("%file", ltrim($link, "/"), $handler);
return $link;
}
Expand Down

0 comments on commit 43ed1de

Please sign in to comment.