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

Added ability to config the trace file and line number #162

Merged
merged 14 commits into from
Nov 10, 2016
Merged

Added ability to config the trace file and line number #162

merged 14 commits into from
Nov 10, 2016

Conversation

thiagotalma
Copy link
Contributor

Q A
Is bugfix? no
New feature? no
Breaks BC? no
Tests pass? no

@dynasource
Copy link
Member

this would be more consistent indeed. Can you add a link to this convention in this topic?

@cebe cebe added the type:enhancement Enhancement label Nov 7, 2016
@bashkarev
Copy link
Contributor

bashkarev commented Nov 7, 2016

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']]));
}

Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a changelog.

@thiagotalma thiagotalma added this to the 2.0.7 milestone Nov 7, 2016
@thiagotalma
Copy link
Contributor Author

@samdark,, I made the changes that colleagues asked. Please check again.

@thiagotalma thiagotalma changed the title Show line number using the colon convention Added ability to config the trace file and line number Nov 7, 2016
/**
* @param array $trace The log trace
*
* @return string the trace line
Copy link
Member

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);
}

Copy link
Member

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.
Copy link
Member

@dynasource dynasource Nov 7, 2016

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?

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing method description

@bashkarev
Copy link
Contributor

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();

Copy link
Member

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?

Copy link
Member

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...

Copy link
Member

@dynasource dynasource left a 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.

@samdark
Copy link
Member

samdark commented Nov 7, 2016

@bashkarev this is interesting. Presets for common IDEs and editors could be very handy. Alternatively it could be put into readme.

@bashkarev
Copy link
Contributor

bashkarev commented Nov 7, 2016

please add options text.
see example for \yii\web\ErrorHandler.php

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;
}

@thiagotalma
Copy link
Contributor Author

adjustments done!

dynasource
dynasource previously approved these changes Nov 7, 2016
Copy link
Member

@dynasource dynasource left a 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>';
Copy link
Contributor

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

Copy link
Contributor Author

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

...
];
```

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example symfony

@bashkarev
Copy link
Contributor

again for about option text

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>'])

@dynasource
Copy link
Member

alright, are you sure everything is working correctly? Thats 'traceLink' method has reached a certain level of complexity that it deserves some unit tests.

@thiagotalma
Copy link
Contributor Author

Thats 'traceLink' method has reached a certain level of complexity that it deserves some unit tests.

@bashkarev you can help with tests?

@yiisoft yiisoft locked and limited conversation to collaborators Nov 9, 2016
@dynasource dynasource dismissed their stale review November 9, 2016 19:18

not ready yet

@yiisoft yiisoft unlocked this conversation Nov 9, 2016
@dynasource
Copy link
Member

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:

  • install a url protocol to make the links work in the browser
  • create the correct links with files & line numbers
  • use a bat file to link to PhpStorm
  • without having any CMD windows left open

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.

@samdark
Copy link
Member

samdark commented Nov 9, 2016

They have an issue tracker: http:https://youtrack.jetbrains.net/issues/WI

@thiagotalma
Copy link
Contributor Author

thiagotalma commented Nov 9, 2016

@dynasource I got it with a minimum of work.
I've created a gist for you to try to use, just copy the files to the "C:\Program Files\PhpStorm Protocol (Win)" folder and run .reg

https://gist.github.com/thiagotalma/fa5a54e1e34133f78f4538eb96c87ae8

EDIT:
Change the .js file according to the configuration of your machine.
This solution was taken from the link I included in the README.

@dynasource
Copy link
Member

dynasource commented Nov 10, 2016

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):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\phpstorm]
@="\"URL:phpstorm Protocol\""
"URL Protocol"=""

[HKEY_CLASSES_ROOT\phpstorm\shell]

[HKEY_CLASSES_ROOT\phpstorm\shell\open]

[HKEY_CLASSES_ROOT\phpstorm\shell\open\command]
@="\"C:\\Program Files (x86)\\JetBrains\\phpstorm.bat\" %1"

Custom bat file 'phpstorm.bat' pointing that one of PhpStorm:

Start /b "" "C:\Program Files (x86)\JetBrains\PhpStorm 2016.2.1\bin\PhpStorm.bat" %2 --line %3

@dynasource
Copy link
Member

dynasource commented Nov 10, 2016

@dynasource I got it with a minimum of work.

This was time consuming:

  • trying to fix it with file:https:// and a chrome extension, but this seems to be restricted anno 2016
  • Fix the bat file to be headless
  • the line is not processed by PhpStorm 2016.2.2

@dynasource
Copy link
Member

nice. You have to do --line before the file argument. Now it works fine!

@dynasource
Copy link
Member

@thiagotalma, I tried your WScript. Its better because its headless and faster. Had to modify it to make it work ;) :

  • The x64 is reversed

@@ -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>';
Copy link
Contributor

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>';
Copy link
Member

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{
Copy link
Member

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']);
Copy link
Member

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!
Copy link
Member

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/')){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting!

Copy link
Member

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?

Copy link
Member

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
@dynasource dynasource merged commit ed07955 into yiisoft:master Nov 10, 2016
@dynasource
Copy link
Member

thanks to you all. Great work.

@ilgiz-badamshin
Copy link

Windows

What about instruction for unix systems?

@cebe
Copy link
Member

cebe commented Nov 29, 2016

@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?

@cebe
Copy link
Member

cebe commented Nov 29, 2016

created an issue for this: #172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants