JosephLenton / PHP-Error

Better error reporting for PHP, and prettier too!
1.35k stars 151 forks source link

A method to generate file links, akin to xdebug.file_link_format? #50

Closed demonkoryu closed 2 years ago

demonkoryu commented 11 years ago

With xdebug, I can define a format for links to the filename/line number of the call stack, for example:

xdebug.file_link_format="javascript:var d=document,r=d.createElement(\"script\");r.src=\"http://localhost:8091?message=%f:%l\";d.body.appendChild(r);void(null)"

Here, the generated links allow me to click to open the file in question directly in IntelliJ IDEA. Is it possible to preserve the link format, or maybe use the xdebug.file_link_format ini setting to format it that way by yourself?

markhalliwell commented 11 years ago

I greatly second this feature and miss this the greatest! For TextMate I use xdebug.file_link_format = "txmt://open?url=file://%f&line=%l"

JosephLenton commented 11 years ago

I fully agree this idea should be in, however I do not agree with the approach. Here is my thinking.

by default, detect the editor to use

If I am using IntelliJ, then it should open in IntelliJ, automatically! No urls, no having to build this prefix, it should just work, out of the box. Same if I am using Textmate, Sublime, gVim, Eclipse, PHPStorm, NetBeans, Visual Studio, etc. They should all be supported, automatically, with no setup required.

That will work if the editor is currently open, by looking at the currently running processes.

also allow specifying the editor

What if an editor is not open, or I want to specify it? Then you can use 'file_link_format' to override, and set it manually. First we'll support urls, such as those you two have provided.

However I do not want to have to do:

file_link_format = txmt://open?url=file:// ... etc

However I find that too much, and I certainly couldn't remember that. So shortcuts will also be provided, allowing you to just do:

editor = textmate
editor = sublime
editor = "visual studio"
editor = intellij
editor = gvim

You then get a way to open the file, given to you automatically. If an editor is not supported, it should raise an error.

If both of those fail, it will just use a 'file://c:/my_website/file.php' type url.

demonkoryu commented 11 years ago

I'm all for that. I have a question, though: How would my web server know which IDE I'm currently running? In my case, the web server runs on another box.

markhalliwell commented 11 years ago

I kind of have to agree here, how would my browser know what program I use? Even if you were to use just the file:///, the browser may just display it instead of sending to another program. I mean yeah, you could have a daemon that handles sending files to an editor and namespace links to something like phperror://. When the browser encounters it, you simply tell it to use the daemon, but that seem like more work and is certainly not [initially] automatic as you'd have to let the browser know where the daemon is.

JosephLenton commented 11 years ago

If it's on another box, then you would set file_link_format.

However a lot of devs use XAMPP, or something similar for development, and that is why I'd prefer a solution that "just works", for those occasions, and does nothing, where that will not work. This will do both.

We can know what editor you are using, by using exec to get a list of running processes. If Sublime/Textmate/whatever is in the list, then it must be running on the same machine it's being developed on, and that will be editor. If it doesn't, then it doesn't do that.

A generic 'file://' is also only given, as a generic default, when all others fail.

It might be worth calling the 'editor' option 'local_editor', to point out that it would only be designed to work locally.

Finally to clarify, the order of things to use when generating the link would be: