How to improve tab-completion for userland classes?
Wojciechem opened this issue · 6 comments
Hi, I'm having strange issue with tabcompletion. It only works "the second time" - see:
$c = new Psy\Configuration
=> Psy\Configuration {#293}
>>> $c->getRe # [tab][tab] tried many times, does nothing
# pressed [enter]
PHP Notice: Undefined property: Psy\Configuration::$getRe on line 1
>>> $c->getReadline(); #this time [tab] completed to getReadline[space]
=> Psy\Readline\Libedit {#259}
I don't think it's supposed to work like this.
I currently use psysh under luxifer/symfony-repl, but it was the same case with bare psysh or psysh-bundle. I've tried googling around, read existing Issues, checked my config etc. No one seems to have the same problem as I do.
Some time ago I used artisan:tinker for a Laravel project and tabcompletion worked flawlessly for any class I needed - and I understand it uses psysh underneath. This is exactly what I'd like to achieve.
More info:
>>> \Psy\Info()
=> [
"PsySH version" => "v0.8.14",
"PHP version" => "7.0.25-1+ubuntu16.04.1+deb.sury.org+1",
"default includes" => [],
"require semicolons" => false,
"error logging level" => 32767,
"config file" => [
"default config file" => null,
"local config file" => null,
"PSYSH_CONFIG env" => false,
],
"updates" => [
"update available" => false,
"latest release version" => "v0.8.14",
"update check interval" => "weekly",
"update cache file" => "~/.config/psysh/update_check.json",
],
"pcntl" => [
"pcntl available" => true,
"posix available" => true,
],
"readline" => [
"readline available" => true,
"readline enabled" => true,
"readline service" => "Psy\Readline\Libedit",
"readline library" => "EditLine wrapper",
],
"history" => [
"history file" => "~/.config/psysh/psysh_history",
"history size" => null,
"erase duplicates" => null,
],
"docs" => [
"manual db file" => null,
"sqlite available" => true,
],
"autocomplete" => [
"tab completion enabled" => true,
"custom matchers" => [],
"bracketed paste" => false,
],
]
If i press [tab] in empty prompt, I get:
Display all 3544 possibilities? (y or n)
I care about this because I use psysh daily for rapid prototyping - it's a great tool.
If this is a wrong place to ask - apologies in advance :)
I'm unable to reproduce this, with almost identical configuration. I can't think of a reason why it would inconsistently autocomplete, except for code that's auto-loaded. For example, I wouldn't expect it to autocomplete a class name that hasn't loaded yet... but methods on existing objects? There should be no problem here.
Thank You for replying. So as I understand it should work consistently for all instantiated classes?
I've just tried it on a different Ubuntu machine and get the same results.
sudo apt-get install php7-0
wget https://git.io/psysh
chmod +x psysh
./psysh
Example run:
- It does autocomplete nicely ie. DateTime
$d = new Da[tab]Ti[tab]
- doesn't complete methods on newly instantiated object of DateTime
$d->[tab] #does nothing
- if I successfully run ie. $d->format("Ymd"), in the next line completion works:
$d->[tab] #displays list of methods now
add getLastErrors modify setTimestamp
createFromFormat getOffset setDate setTimezone
diff getTimestamp setISODate sub
format getTimezone setTime
I'm puzzled. The strange thing is that it works sometimes, and I can't predict when will it. It's not just that I have to call anything on the object first (could live with that), but very well it can work once and then again do nothing.
Thanks for notifying, sadly it seems not to.
My steps:
- check out to develop
- make build
- run build/psysh/bin/psysh (is this correct?)
- try my "test case" with DateTime:
Psy Shell v0.9.3 (PHP 7.1.16-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> $d = new \DateTime();
=> DateTime {#1750
+"date": "2018-05-09 15:12:49.250162",
+"timezone_type": 3,
+"timezone": "Europe/Berlin",
}
>>> $d-> #[tab][tab] produces empty line
>>> $d->format(\DateTime::W3C); #type "by hand"
=> "2018-05-09T15:12:49+02:00"
>>> $d-> #[tab][tab] - works as charm this time
add getLastErrors modify setTimestamp
createFromFormat getOffset setDate setTimezone
diff getTimestamp setISODate sub
format getTimezone setTime
>>> $d->
There is still this weird inconsistency (does / does not complete) depending on previous line. I'm thinking of creating a docker env to test it for my sanity :)
My experience is the same, sometimes tab expansion fails and there doesn't seem to be any pattern to when, and it is usually not repeatable.
Maybe worth having some kind of debug logging of tab completion attempts?
Closing as the title is not very "accurate". The (apparently rare) tab-completion issue is discussed in #561