-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Added ability to config the trace file and line number #162
Conversation
thiagotalma
commented
Nov 7, 2016
Q | A |
---|---|
Is bugfix? | no |
New feature? | no |
Breaks BC? | no |
Tests pass? | no |
this would be more consistent indeed. Can you add a link to this convention in this topic? |
It will be more universal. + closes #144 [
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
'editor' => ['phpstorm:https://open?file={file}&line={line}', '{file}:{line}']
],
],
] public function editorLink($trace)
{
if ($this->editor === null) {
return "{$trace['file']}:{$trace['line']}";
}
if (is_string($this->editor)) {
return strtr($this->editor, ['{file}' => $trace['file'], '{line}' => $trace['line']]);
}
return Html::a(strtr($this->editor[0], ['{file}' => $trace['file'], '{line}' => $trace['line']]), strtr($this->editor[1], ['{file}' => $trace['file'], '{line}' => $trace['line']]));
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a changelog.
@samdark,, I made the changes that colleagues asked. Please check again. |
/** | ||
* @param array $trace The log trace | ||
* | ||
* @return string the trace line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing @SInCE
if (is_callable($this->module->traceLink)) { | ||
return call_user_func($this->module->traceLink, $trace, $this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line may be removed.
@@ -91,6 +91,19 @@ class Module extends \yii\base\Module implements BootstrapInterface | |||
* You may want to enable the debug logs if you want to investigate how the debug module itself works. | |||
*/ | |||
public $enableDebugLogs = false; | |||
/** | |||
* @var mixed the string with placeholders to be be substituted or an anonymous function that returns the trace line string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its unclear how this string should look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, an example would be good.
@@ -114,4 +114,22 @@ public function getUrl($additionalParams = null) | |||
|
|||
return Url::toRoute($route); | |||
} | |||
|
|||
/** | |||
* @param array $trace The log trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing method description
What do you think? $links = [
'textmate' => 'txmt:https://open?url={file}&line={line}',
'macvim' => 'mvim:https://open?url={file}&line={line}',
'emacs' => 'emacs:https://open?url={file}&line={line}',
'sublime' => 'subl:https://open?url={file}&line={line}',
'phpstorm' => 'phpstorm:https://open?url={file}&line={line}',
]; [
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
'ide' =>'phpstorm'
],
],
] |
@@ -98,7 +98,7 @@ | |||
function debug_db_detail() { | |||
$('.db-explain a').on('click', function(e) { | |||
e.preventDefault(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these lines added accidentally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's automatic PhpStorm's removal of whitespace on blank lines. I agree that it should not be in this commit...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for including the traceLink functionality. Looking forward to have this integrated with PhpStorm.
@bashkarev this is interesting. Presets for common IDEs and editors could be very handy. Alternatively it could be put into readme. |
please add options public function traceLink($file, $line)
{
/**
* @var $debug \yii\debug\Module
*/
if (
$file !== null
&& $line !== null
&& ($debug = Yii::$app->getModule('debug')) !== null
) {
return $debug->traceLink([
'file' => $file,
'line' => $line,
'text' => 'open file' //!!!
]);
}
return null;
} |
adjustments done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done
'item' => function ($trace) { | ||
return "<li>{$trace['file']} ({$trace['line']})</li>"; | ||
'item' => function ($trace) use ($panel) { | ||
return '<li>' . $panel->traceLink($trace) . '</li>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if set 'traceLink' => 'phpstorm:https://open?url={file}&line={line}',
this not link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bashkarev really! my bad....
fixed in README
... | ||
]; | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest putting common IDE strings here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samdark In fact, there is no a list of possible settings per IDE.
The user is who sets the string when it does the setup in the operating system. There is a link that talks about this in the example I quoted: https://pla.nette.org/en/how-open-files-in-ide-from-debugger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, shortly described at #144 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example symfony
again for about option public function traceLink($options)
{
if (!isset($options['text'])) {
$options['text'] = "{$options['file']}:{$options['line']}";
}
if ($this->module->traceLink === null) {
return $options['text'];
}
if (is_callable($this->module->traceLink)) {
return call_user_func($this->module->traceLink, $options, $this);
}
if (is_string($this->module->traceLink)) {
return strtr($this->module->traceLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
}
return null;
} $debug->traceLink(['file'=>'...','line'=>1,'text'=>'<svg></svg>']) |
alright, are you sure everything is working correctly? Thats 'traceLink' method has reached a certain level of complexity that it deserves some unit tests. |
@bashkarev you can help with tests? |
alright. I've commited some fixes & tests. It also tried to integrate it with PhpStorm on a windows machine. That was quite some work and the good news is thats its working. You need several patches for that:
Took a few hours ;) but it works now. Unfortunately yet only with files. With the line numbers, I do not see any activity in the PhpStorm. Its very likely a bug on their side. |
They have an issue tracker: http:https://youtrack.jetbrains.net/issues/WI |
@dynasource I got it with a minimum of work. https://gist.github.com/thiagotalma/fa5a54e1e34133f78f4538eb96c87ae8 EDIT: |
my solution is a little different and smaller. Its uses a bat file so you only have to put it to the registry once (and change the bat file if PhpStorm upgrades):
Custom bat file 'phpstorm.bat' pointing that one of PhpStorm:
|
This was time consuming:
|
nice. You have to do --line before the file argument. Now it works fine! |
@thiagotalma, I tried your WScript. Its better because its headless and faster. Had to modify it to make it work ;) :
|
@@ -25,7 +25,7 @@ | |||
*/ | |||
class Module extends \yii\base\Module implements BootstrapInterface | |||
{ | |||
const TRACELINK_PHPSTORM_WINDOWS = '<a href="phpstorm:https:// {file} {line}">{file}:{line}</a>'; | |||
const TRACELINK_PHPSTORM = '<a href="phpstorm:https://open?url=file:https://{file}&line={line}">{file}:{line}</a>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const TRACELINK_PHPSTORM = '<a href="phpstorm:https://open?url=file:https://{file}&line={line}">{text}</a>';
@@ -25,6 +25,8 @@ | |||
*/ | |||
class Module extends \yii\base\Module implements BootstrapInterface | |||
{ | |||
const TRACELINK_PHPSTORM = '<a href="phpstorm:https://open?url=file:https://{file}&line={line}">{text}</a>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it called PHPSTORM if the link is the same for all IDEs?
} | ||
if ($this->module->traceLink === null) { | ||
return $options['text']; | ||
}else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting!
if ($this->module->traceLink === null) { | ||
return $options['text']; | ||
}else{ | ||
$options['file'] = str_replace('\\','/',$options['file']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting!
Wouldn't it be nice to be able to open files directly from the debug trace? | ||
|
||
Well, you can! | ||
With a few settings and you're ready to go! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for and
here.
@@ -8,8 +8,13 @@ | |||
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; | |||
$_SERVER['SCRIPT_FILENAME'] = __FILE__; | |||
|
|||
require_once(__DIR__ . '/../vendor/autoload.php'); | |||
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); | |||
if(is_dir(__DIR__ . '/../vendor/')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is such condition needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please read the next lines
- renamed to traceLine - set traceLine to the CONST as default - fixed a false setting showing a textual line
thanks to you all. Great work. |
What about instruction for unix systems? |
@ilgiz-badamshin just found this: http:https://www.tuicool.com/articles/ANBBVj looks like it could be used as a basis for writing linux instructions in the docs. Would you be willing to write a guide and send a pull request? |
created an issue for this: #172 |