kint-php / kint

Kint - Advanced PHP dumper
https://kint-php.github.io/kint/
MIT License
2.77k stars 291 forks source link

Can Kint show source code of a function? #97

Closed adityamenon closed 10 years ago

adityamenon commented 10 years ago

When I'm in the Available Methods view, I'd like to see the source code of a function when I expand it. Is this possible?

raveren commented 10 years ago

It is possible for userland functions, but not inbuilt ones.

However improper functions might contain thousands of lines of code, and I don't feel like outputting all that hardly useful stuff to the browser, Kint's output is humongous as it is. You can, however, set up Kint's source links to open your editor[*] at the proper place, and IIRC there are links to each function declaration.

[*] definitely possible for php storm, and most other modern ones.

raveren commented 10 years ago

I'm closing this issue, as I'm afraid it's impractical to implement, but if you have questions, I receive notifications to subsequent replies and will reply asap...

adityamenon commented 10 years ago

Hi @raveren, thanks for the reply.

Yes, I meant userland functions, definitely not inbuilt ones.

I understand the concern with improperly written functions, personally I mostly use Kint to check out the internals of framework objects in Laravel. The functions are usually pleasure to read :) But these implementation details sometimes (sadly) become important, and I thought it would be cool to be able to check them right then and there instead of having to head over to the API. To allay concerns about too-long functions, we could have the source collapsed by default. But I can understand if you feel strongly about this overall.

The "open links directly in editor" bit sounded really interesting, do you have any more info on how to set that up? I mean to ask, is there something special Kint itself can do about this? I see nothing in the docs about that. After every method, there is this helpful output in Kint:

Inherited from Laravel\Database\Eloquent\Model
Defined in /home/adityamenon/code/my-app/laravel/database/eloquent/model.php line 589

But I imagine it wouldn't be trivial to set this up to open links directly in Sublime Text (my current editor).

raveren commented 10 years ago

open links directly in Sublime Text

Here you can see work by a contributor to help you in that: https://github.com/raveren/kint/tree/master/scripts Open the files up and it's commented beautifully.

However, I use PHPstorm with the Remote Call plugin which does all the setup for me, so I did not investigate this much personally. But don't be discouraged, this is the best thing ever, you'll be able to click through every kint output - and I've even set up my projects to display links to current controller/action + template for developers. Saves hours every month, even though not directly related to Kint.

too-long functions, we could have the source collapsed by default well the thing is, traces and similar heavy output is already reaching into 100s of kb in size and when it starts to lag the browser down, it will be too late for cutting features off as it will leave many users mad.

I suppose an optional, config-enabled functionality that's off by default is possible, but it's going to take a while, I already have issue #91 open about this and could hardly devote any time to Kint in the recent months and I can't see that changing for a month or two more :(

adityamenon commented 10 years ago

Ah... a vbs script. Entertaining diversion to convert that into Python for Sublime, will look into that, thanks! :)

Sure, thanks for taking time to consider feedback :)

raveren commented 10 years ago

Yeah, that would be awesome, but I'm afraid registry modification might be necessary to register a new url:// protocol, what PHPstorm on the other hand does, is it's running a local port-listener for 'http://localhost:8091/?message=%f:%l.

Looking forward to any updates if you manage to entertain this task :)

aljinovic commented 10 years ago

Other approach would be to make a (cross)browser extension that handles custom protocol in which you could select IDE and its configuration?

raveren commented 10 years ago

If the extension can have permissions to launch external OS commands, then yes, I know Firefox allows that (open source in external editor via Firebug) and really really doubt that Chrome does, it's restrictiveness on extensions is the main reason I much prefer Firefox - both personally and as a development tool.

aljinovic commented 10 years ago

Here's the approach Nette framework is suggesting with the examples for multiple OS:

http://pla.nette.org/en/how-open-files-in-ide-from-debugger

raveren commented 10 years ago

I love the nette guys, I'm pretty sure I stole some code from the framework for my various projects and my own personal framework :) Their debugger/error page was one of the inspirations to Kint too!

So still, registry editing is required..

aljinovic commented 10 years ago

Yep, seems so, browser plugin is a tricky one, I've been looking at some examples, but it's a security issue for the browsers so it's going to be removed from firefox also, sooner or later.