-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I researched how to do this, but it is difficult to Google such common words like "line number". I tried many wordings for the search, and tried searching for various VSCode API calls people mentioned. I want to be able to jump to the line number in the Debug Console, but I cannot find the API call to manipulate this. My use case is that VSCode's pattern matching for the Debug Console does not detect the line number in PHP tracebacks. I can get it working if I paste the errors into a comment:
<?php
/*
[Sun May 19 19:46:26 2024] PHP Fatal error: Uncaught TypeError: mysqli_error(): Argument #1 ($mysql) must be of type mysqli, null given in /opt/git/mysql-shim/mysql-shim.php:491
Stack trace:
#0 /opt/git/mysql-shim/mysql-shim.php(491): mysqli_error()
#1 /home/owner/git/rpgdx/forums/db/mysql.php(325): mysql_error()
#2 /home/owner/git/rpgdx/forums/includes/functions.php(756): sql_db->sql_error()
#3 /home/owner/git/rpgdx/forums/includes/db.php(63): message_die()
#4 /home/owner/git/rpgdx/forums/common.php(194): include('...')
#5 /home/owner/git/rpgdx/includes/main.php(7): include('...')
#6 /home/owner/git/rpgdx/index.php(2): include('...')
#7 {main}
thrown in /opt/git/mysql-shim/mysql-shim.php on line 491
[Sun May 19 19:46:26 2024] [::1]:40882 [500]: GET / - Uncaught TypeError: mysqli_error(): Argument #1 ($mysql) must be of type mysqli, null given in /opt/git/mysql-shim/mysql-shim.php:491
Stack trace:
#0 /opt/git/mysql-shim/mysql-shim.php(491): mysqli_error()
#1 /home/owner/git/rpgdx/forums/db/mysql.php(325): mysql_error()
#2 /home/owner/git/rpgdx/forums/includes/functions.php(756): sql_db->sql_error()
#3 /home/owner/git/rpgdx/forums/includes/db.php(63): message_die()
#4 /home/owner/git/rpgdx/forums/common.php(194): include('...')
#5 /home/owner/git/rpgdx/includes/main.php(7): include('...')
#6 /home/owner/git/rpgdx/index.php(2): include('...')
#7 {main}
thrown in /opt/git/mysql-shim/mysql-shim.php on line 491
*/
?>
using this config:
"regexrobin.rules": [
// This requires the Regex Robin extension.
// The last matching rule takes precedence.
// This doesn't work in the DEBUG CONSOLE,
// so paste debug console output into
// a comment in a temporary PHP file
// to be able to jump to errors :(.
{
"regex": "#(\\d+)\\s+(\\S+)\\.php\\((\\d+)",
"editor": [{
"group": 2,
"link": "file://$2.php#$3",
"color": "#66EFD9",
"hoverMessage": "file://$2.php#$3"
}]
},
{
"regex": "thrown in\\s+(\\S+) on line (\\d+)",
"editor": [{
"group": 1,
"link": "file://$1#$2",
"color": "#66EFD9",
"hoverMessage": "file://$1#$2"
}]
},
{
"regex": "\\[.*\\].* in (.*)\\.php:(\\d+)",
"editor": [{
"group": 1,
"link": "file://$1.php#$2",
"color": "#66EFD9",
"hoverMessage": "file://$1.php#$2"
}]
}
]
- The regex explicitly looks for ".php" to avoid trying to look for ":" because on windows, there could be a drive letter then colon. Removing the "." from pattern instead of just looking for "php" 1 seemed like the neatest looking way to highlight the match (via the group setting), as this way the filename but not the .php is highlighted (it looked odd if the dot but not extension was highlighted, and no other regex code seemed like a good way to go).
There is an issue on VSCode where someone is trying to get pattern matching, but even the VSCode developers don't seem to understand this use case, because they linked to this
but that's already the register call that Regex Robin uses, and that doesn't help with the Debug Console and they closed the issue:
However, the issue doesn't actually say "where" the link would be, and doesn't specifically mention debug console. If it isn't an issue with that, can already use Regex Robin and closing the issue was legit.
@Natejoestev Please clarify whether Regex Robin can already solve your issue (It does if you are talking about links in loaded files).
Possibly related info:
There seems to be some way to get handlers working in the Debug Console, but I don't really understand fully if this applies here, since it seems to be a very specific use case related to changing the root directory for a package name to make it clickable that way: