-
Notifications
You must be signed in to change notification settings - Fork 115
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
Comments
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. |
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. |
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). |
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!). |
@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 |
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. |
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. |
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 🐱 |
The link is broken @filp |
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!
The text was updated successfully, but these errors were encountered: