Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ide links #283

Open
wants to merge 1 commit into
base: v7.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ private function renderEditor(Frame $frame): self

// getLine() might return null so cast to int to get 0 instead
$line = (int) $frame->getLine();
$this->render('at <fg=green>'.$file.'</>'.':<fg=green>'.$line.'</>');
$href = $this->getEditorLink($frame);
$this->render('at <fg=green;href='.$href.'>'.$file.'</>'.':<fg=green>'.$line.'</>');

$content = $this->highlighter->highlight((string) $frame->getFileContents(), (int) $frame->getLine());

Expand Down Expand Up @@ -308,8 +309,9 @@ private function renderTrace(array $frames): self
);
$vendorFrames = 0;
}
$href = $this->getEditorLink($frame);

$this->render("<fg=yellow>$pos</><fg=default;options=bold>$file</>:<fg=default;options=bold>$line</>", (bool) $class && $i > 0);
$this->render("<fg=yellow>$pos</><fg=default;options=bold;href=$href>$file</>:<fg=default;options=bold>$line</>", (bool) $class && $i > 0);
if ($class) {
$this->render("<fg=gray> $class$function($args)</>", false);
}
Expand Down Expand Up @@ -349,4 +351,17 @@ private function getFileRelativePath(string $filePath): string

return $filePath;
}

/**
* Returns a phpstorm protocol link that opens the file in PhpStorm on the selected line
* @param Frame $frame
* @return string
*/
private function getEditorLink(Frame $frame): string
{
return 'phpstorm://open?' . http_build_query([
'file' => (string) $frame->getFile(),
'line' => $frame->getLine(),
]);
}
}