Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Add links on exception-page to open error-line in IDE

1
by Xitara, last modified on March 19th, 2023

Change the following lines in file modules/system/views/exception.php:

Line 21 old:

<p><?=$exception->getFile()?> <span>line</span> <?=$exception->getLine()?></p>

new:

<p>
    <a href="subl://open?url=file://<?=$exception->getFile()?>&line=<?=$exception->getLine()?>">
        <?=$exception->getFile()?> <span>line</span> <?=$exception->getLine()?>
    </a>
</p>

Line 59 old:

<td><?=$stackItem->file?></td>

new:

<td>
    <?php
        $file = (dirname(dirname(dirname(dirname(__FILE__)))));
        $file = str_replace('~', $file, $stackItem->file);
    ?>
    <a href="subl://open?url=file://<?=$file;?>&line=<?=$stackItem->line;?>">
        <b><?=$stackItem->file?></b>
    </a>
</td>

This link is for sublime text but can changed for phpstorm, vcode and other easily. Now you have to register a custom protocol handler.

On linux create a file "subl-url-handler" in a destination of your choice

#!/usr/bin/env bash
arg=${1}

if [[ $arg == *"column"* ]]; then
    pattern=".*file(:\/\/|\=)(.*)&line=(.*)&column=(.*)"
else
    pattern=".*file(:\/\/|\=)(.*)&line=(.*)"
fi

file=$(echo "${arg}" | sed -r "s/${pattern}/\2/")
line=$(echo "${arg}" | sed -r "s/${pattern}/\3/")
column=$(echo "${arg}" | sed -r "s/${pattern}/\4/")

if [ $column == "" ]; then
    DISPLAY=:0.0 /opt/sublime_text/sublime_text $file:$line
else
    DISPLAY=:0.0 /opt/sublime_text/sublime_text $file:$line:$column
fi

then create a file /usr/share/applications/subl-url-handler.desktop

[Desktop Entry]
Version=1.0
Type=Application
Name=subl URL Handler
Comment=Handle URL Scheme subl://open?url=@file&line=@line
Icon=subl
NoDisplay=true
Categories=TextEditor;Utility;
Exec=/path/to/subl-url-handler %u
Terminal=false
MimeType=x-scheme-handler/subl;
X-Desktop-File-Install-Version=0.22

and now run "sudo update-desktop-database" or "update-desktop-database" if you are root

Mac-user can take a look at https://github.com/asuth/subl-handler

Windows-user can find tipps at https://github.com/Octarine-Phaneron/custom_protocol

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?