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

How to improve tab-completion for userland classes? #435

Closed
Wojciechem opened this issue Nov 10, 2017 · 6 comments
Closed

How to improve tab-completion for userland classes? #435

Wojciechem opened this issue Nov 10, 2017 · 6 comments

Comments

@Wojciechem
Copy link

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 :)

@bobthecow
Copy link
Owner

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.

@Wojciechem
Copy link
Author

Wojciechem commented Nov 12, 2017

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:

  1. It does autocomplete nicely ie. DateTime
    $d = new Da[tab]Ti[tab]
  2. doesn't complete methods on newly instantiated object of DateTime
    $d->[tab] #does nothing
  3. 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.

@bobthecow
Copy link
Owner

I'd be curious to know whether 1f9bc08 fixes this for you.

@Wojciechem
Copy link
Author

Thanks for notifying, sadly it seems not to.
My steps:

  1. check out to develop
  2. make build
  3. run build/psysh/bin/psysh (is this correct?)
  4. 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 :)

@tgr
Copy link
Contributor

tgr commented Mar 9, 2019

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?

@Wojciechem
Copy link
Author

Closing as the title is not very "accurate". The (apparently rare) tab-completion issue is discussed in #561

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

No branches or pull requests

3 participants