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

Tab completion and reflection methods? #3

Open
michaelwills opened this issue Jul 14, 2012 · 10 comments
Open

Tab completion and reflection methods? #3

michaelwills opened this issue Jul 14, 2012 · 10 comments
Labels

Comments

@michaelwills
Copy link

Just discovered Boris. Very nice! After using Ruby's Pry my first thought was on tab completion. As a simple test, dropping in the readline_completion_function from this php repl got immediate PHP completions which is quite helpful:

https://github.com/ErikDubbelboer/php-repl

The inline documentation like and other reflection methods are neat as well. Any thoughts on combining the best of the 3?

boris all around cool repl
php-repl tab completions
php_repl reflection methods

Thanks!

@d11wtq
Copy link
Contributor

d11wtq commented Jul 14, 2012

I'm also a ruby user who uses Pry. I have thought about building more features into Boris, but it hasn't been a priority, since the main thing I was aiming for was something that would not exit when I mistype something, or try something experimental that causes an error. Boris solves that, but I agree it's lacking in features that other REPLs provide. I often find myself hitting tab and getting caught out in boris. If you feel like picking through that readline competion code and bringing it to Boris (in a OO style), I'll gladly merge it ;)

With regards to the reflection/docblock parsing, I'm not as bothered about this, but that's probably just because I don't use those features in other REPLs. I prefer to poke around in the source.

@michaelwills
Copy link
Author

Understood. I'm just spoiled by popup documentation in my IDE (IntelliJ) or being able to jump to source there in the IDE. :)

Adding readline wasn't bad. Adding the reflection methods isn't bad but nothing like a full on repl of course. It's just hacked code at the moment. Thanks for sharing the tool.

[edit] I'll have to dig in more later and hopefully I can figure out scope and such. but it's quite a helpful tool as is.

@d11wtq
Copy link
Contributor

d11wtq commented Mar 2, 2013

Re-thinking this, I think what I'd like to do is have a separate project that does the tab completion in a smart way, then if that works well, the two can get merged together, or that project can grow wings of its own and provide it's own executable (that just loads boris internally). One thing I like about Boris' codebase is that it's really succinct. Adding tab completion "correctly" will bloat the codebase a considerable amount. I'd really like the tab completion to be context-aware (so it knows you're invoking a method, or completing a variable name, or extending a class etc).

@kleiram
Copy link

kleiram commented Mar 2, 2013

How about this function with a nice regex? Shouldn't be too hard to implement right (going to dig into the code now to see how it works!).

@d11wtq
Copy link
Contributor

d11wtq commented Mar 3, 2013

@kleiram yeah that's the easy part, but what about method name completion instead of function completion, and variable name completion? If I've just typed -> and hit tab, I don't want PHP functions to be auto-completed, I want methods on properties on the current object. That's where it starts to get tricky ;)

@kleiram
Copy link

kleiram commented Mar 3, 2013

I guess you're keeping track of the type of a certain object right? Then, when someone presses tab you can do the following (see ReflectionClass):

$reflection = new \ReflectionClass($type);
$methods    = $reflection->getMethods();
$properties = $reflection->getProperties();

But I'm guessing you already thought of something like that :)

Edit: The ReflectionMethod class has support for getting the doc comment too (but I think there's a better library for that actually).

Edit 2: Another thing that I think is possible is to hook into the autoloading mechanism and watch for classes that are being loaded and parse those only when needed.

@d11wtq
Copy link
Contributor

d11wtq commented Mar 3, 2013

I'm not keeping track of anything at the moment, so this is another place where it gets bloated ;) readline() provides the last "token" the user typed, so you'd have to grab that string, then ask the EvalWorker (who is the only component that knows what variables exist in the user's REPL session) to find that variable's methods, if it can. I also have a feeling readline only returns the string 'object' if you type '$object' and hit tab. Perhaps that's configurable though. I looked at all this briefly on the first day I wrote Boris, but haven't given any serious amount of time to explore in reality.

@filp
Copy link
Contributor

filp commented Jan 18, 2014

Sorry for the necro-bump, but someone looking into tackling this, and who can read ruby, may find some interest in pry's fairly simple completion module:

https://github.com/pry/pry/blob/master/lib/pry/completion.rb

I was recently looking at it for another project and it reminded me of this issue 🐱

@tejasmanohar
Copy link
Contributor

The link is broken @filp

@Bilge
Copy link

Bilge commented Mar 1, 2015

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

No branches or pull requests

6 participants