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

Class autocompletion doesn't work without 'use' keyword #59

Open
golaod opened this issue Sep 8, 2016 · 40 comments
Open

Class autocompletion doesn't work without 'use' keyword #59

golaod opened this issue Sep 8, 2016 · 40 comments

Comments

@golaod
Copy link

golaod commented Sep 8, 2016

That's something what is missing I think. When I have class like App\Entities\Order and I just type Order, I don't get anything unless I type 'use' keyword before. It wouldn't be a problem if I could do 'find use' and it would automatically add it to other use lines and leave 'Order' in current line. Is there a chance to enable that autocompletion without use keyword at least?

@mkusher
Copy link
Member

mkusher commented Sep 8, 2016

@golaod can you provide more examples?

@golaod
Copy link
Author

golaod commented Sep 8, 2016

Sure.

Let's say I have App\Entities\ConnectorFailedJob

and then somewhere in the code I type

namespace App\Console\Commands;

class MyCommand
{
    public function run()
    {
        ConnectorF // I expect to get hint with App\Entities\ConnectorFailedJob, but I don't get it

        // although I can get it when typing
        use ConnectorF // here it works, but of course it's pointless

        // because I will get
        use App\Entities\ConnectorFailedJob;
    }
}

Of course again it wouldn't be a problem if, for istance, 'find use' command would automatically change that line to:

namespace App\Console\Commands;

use App\Entities\ConnectorFailedJob;

class MyCommand
{
    public function run()
    {
        ConnectorFailedJob
        // or even better, that I don't have to type 'use' in the middle of the code
        // because would be great to have autocompletion of classes and FQCN anywhere
    }
}

@mkusher
Copy link
Member

mkusher commented Sep 8, 2016

@golaod are you using master version?

@mkusher
Copy link
Member

mkusher commented Sep 8, 2016

so, understood.
The fix could be quite easy: we just need to add classes to this map https://github.com/mkusher/padawan.php/blob/master/src/Padawan/Domain/Completer/GlobalFunctionsCompleter.p
Fix is really simple: this context should be added to class name completer canHandle

@golaod
Copy link
Author

golaod commented Sep 8, 2016

Thanks for the info, but I can't use master version.

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: react/http[dev-master, v0.4.1].
    - Can only install one of: react/http[v0.4.1, dev-master].
    - Can only install one of: react/http[dev-master, v0.4.1].
    - don't install react/http dev-master|don't install react/react v0.4.1
    - mkusher/padawan dev-master requires react/http dev-master -> satisfiable by react/http[dev-master].
    - Installation request for mkusher/padawan master -> satisfiable by mkusher/padawan[dev-master].
    - Installation request for react/http (locked at v0.4.1) -> satisfiable by react/http[v0.4.1], react/react[v0.4.1].

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Any suggestions?

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod why do you need global react/http v0.4.1?

@golaod
Copy link
Author

golaod commented Sep 9, 2016

I don't need it. I just install your package with composer global require mkusher/padawan:master

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod can you remove it completely and then install again?
$ composer global require mkusher/padawan:dev-master

@golaod
Copy link
Author

golaod commented Sep 9, 2016

~/.composer$ composer global require mkusher/padawan:dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: react/http[dev-master, v0.4.1].
    - Can only install one of: react/http[v0.4.1, dev-master].
    - Can only install one of: react/http[dev-master, v0.4.1].
    - mkusher/padawan dev-master requires react/http dev-master -> satisfiable by react/http[dev-master].
    - Installation request for mkusher/padawan dev-master -> satisfiable by mkusher/padawan[dev-master].
    - Installation request for react/http (locked at v0.4.1) -> satisfiable by react/http[v0.4.1].


Installation failed, reverting ./composer.json to its original content.

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod can you show your global composer.json?

@golaod
Copy link
Author

golaod commented Sep 9, 2016

cat composer.json 
{
    "require": {
        "mkusher/padawan-di": "^0.1.1",
        "pbogut/padawan-magento": "dev-master"
    },
    "minimum-stability": "dev"
}

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod please, try following:

$ composer global remove react/react
$ composer global require mkusher/padawan:dev-master

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Thank you very much, that one helped. Now let me check, whether namespaces work in the middle of code.

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Nope, still doesn't autocomplete.

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod now only global functions will work, in order to complete fqcn we need to add this fix to the completer

@golaod
Copy link
Author

golaod commented Sep 9, 2016

I added it manually to your code, but right now with dev-master even use statement at the top of the file doesn't populate popup with classes

@golaod
Copy link
Author

golaod commented Sep 9, 2016

And if you wanna ask whether padawan-server is working. It does, because doing $this-> inside a method populates the popup.

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Hm...during further tests I found out that $this-> is not populated by your module, but by sublime. In that case padawan stopped working at all :(

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod run padawan generate from the root dir of your project.
I've also sent #64

@golaod
Copy link
Author

golaod commented Sep 9, 2016

I run padawan generate, I did the same in sublime, but it still doesn't autocomplete classes at the top of the file when writing along with 'use' keyword, doesn't autocomplete inherited methods on $this->, and #64 has a bug

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod yeah, I see the bug. So, I should spend more time on it :(
Have you restarted padawan server after you ran generate?

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Yes I did and same thing as with padawan generate. Doesn't matter if I run it from the console or sublime.

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

ooh, that's strange. Can you debug it with nc(show me request/response)?

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Any suggestion on how to debug it?

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Nvm, I figured out to catch the request first and then send it over

@golaod
Copy link
Author

golaod commented Sep 9, 2016

Request sent by sublime

POST /complete?path=%2Fhome%2Fgolaod%2Fwww%2Fproject&column=16&line=36&filepath=%2Fmodules%2FOrder%2FEntities%2FOrderItem.php HTTP/1.1
Accept-Encoding: identity
Host: 127.0.0.1:15155
Content-Length: 971
Content-Type: application/x-www-form-urlencoded
User-Agent: Python-urllib/3.3
Connection: close

<?php
namespace Modules\Order\Entities;

use App\Connectors\Traits\ConnectorModelColumns;
use App\Entities\Product;
use App\Traits\ModelHelpers;
use Illuminate\Database\Eloquent\Model;

class OrderItem extends Model
{
    use ModelHelpers, ConnectorModelColumns;

    protected $fillable = [
        'order_id', 'product_sku', 'qty', 'connector_id', 'external_id', 'external_data',
    ];

    protected $casts = [
        'order_id'   => 'int',
        'qty'        => 'int',
        'connector_id'  => 'int',
        'external_data' => 'array',
    ];

    public function __toString()
    {
        return $this->name;
    }

    public function order()
    {
        return $this->hasOne(Order::class, 'id', 'order_id');
    }

    public function product()
    {
        $this->
        return $this->hasOne(Product::class, 'sku', 'product_sku');
    }

    public function getNameAttribute()
    {
        return $this->product ? $this->product->name : '';
    }
}

As I couldn't use it to send it over to padawan-server through nc, so I built curl request

curl -XPOST -d '<?php
namespace Modules\Order\Entities;

use App\Connectors\Traits\ConnectorModelColumns;
use App\Entities\Product;
use App\Traits\ModelHelpers;
use Illuminate\Database\Eloquent\Model;

class OrderItem extends Model
{
    use ModelHelpers, ConnectorModelColumns;

    protected $fillable = [
        'order_id', 'product_sku', 'qty', 'connector_id', 'external_id', 'external_data',
    ];

    protected $casts = [
        'order_id'   => 'int',
        'qty'        => 'int',
        'connector_id'  => 'int',
        'external_data' => 'array',
    ];

    public function __toString()
    {
        return $this->name;
    }

    public function order()
    {
        return $this->hasOne(Order::class, 'id', 'order_id');
    }

    public function product()
    {
        $this->
        return $this->hasOne(Product::class, 'sku', 'product_sku');
    }

    public function getNameAttribute()
    {
        return $this->product ? $this->product->name : '';
    }
}' '127.0.0.1:15155/complete?path=%2Fhome%2Fgolaod%2Fwww%2Fproject&column=16&line=36&filepath=%2Fmodules%2FOrder%2FEntities%2FOrderItem.php'

It gets me response

{"completion":[],"context":[]}

And padawan server throws an error

[2016-09-09 14:34:19] completer.ERROR: exception 'PhpParser\Error' with message 'Syntax error, unexpected ',', expecting '(' on line 21'

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod thx, will try to debug it later

@mkusher
Copy link
Member

mkusher commented Sep 9, 2016

@golaod yeah, I've found the problem - wrong content-type header. I've already fixed it in padawan-php/padawan.sublime@46152ec
so can you update your padawan plugin for sublime(maybe I have to make new tag\release?)?

@golaod
Copy link
Author

golaod commented Sep 10, 2016

Thanks for fixing the header as I was able to use nc to send request.

nc 127.0.0.1 15155 < request.log 
HTTP/1.1 200 OK
X-Powered-By: React/alpha
Content-Type: application/json
Transfer-Encoding: chunked

1e
{"completion":[],"context":[]}
0

Now what I found:

  • Generate index stopped working. I removed index completely and tried to generate it. Progress bar just goes very fast and nothing happens. When I call padawan generate from console then it works ok. After generation when I try again in sublime, progress bar is still lightning fast.
  • Autocompletion of anything still doesn't work.

Sorry to tell, but previous version, even though with missing features, was more stable :(

@golaod
Copy link
Author

golaod commented Sep 10, 2016

Please don't get me wrong with my last sentence, I was just referring to it, because I wanted to help with few missing features, but now if package doesn't work at all, it's just harder than I thought. I really appreciate your help and didn't want to judge your volunteer work

@mkusher
Copy link
Member

mkusher commented Sep 10, 2016

Sorry to tell, but previous version, even though with missing features, was more stable

yeah, that's why I haven't created new tag. 0.2 branch is quite stable and dev-master is development. Even with auto tests there are a lot of untested cases.
I tried completion in your file without an index and got completion for current file context(using dev-master both for sublime plugin and padawan). Not sure how to reproduce your situation :(

@golaod
Copy link
Author

golaod commented Sep 10, 2016

I also get completion for current file, but I think it should return more, like for instance inherited methods. Plus it still doesn't return completion for fqcns

@mkusher
Copy link
Member

mkusher commented Sep 10, 2016

@golaod so does it return completions or it returns nothing?

@golaod
Copy link
Author

golaod commented Sep 10, 2016

it doesn't return completions from padawan. In case

class A
{
    public function test() {}
}

class B extends A
{
    public function __construct()
    {
        $this->
    }

    public function debug() {}
}

I see only 'debug' whereas should also see 'test' method

@mkusher
Copy link
Member

mkusher commented Sep 10, 2016

@golaod just created new file and tried your case and it works. So something wrong with padawan install. Maybe you're using some virtualization or something? I mean maybe padawan couldn't find files or something like?
And can you start padawan-server from your terminal and copy it's output here for this case?

@golaod
Copy link
Author

golaod commented Sep 10, 2016

Exactly, because you pasted both classes into the same file. I gave you a simple case, but of course I was referring to a regular day scenario, where your classes extend other classes (from other files).

@mkusher
Copy link
Member

mkusher commented Sep 10, 2016

@golaod oh, I just need to understand what's wrong.

<?php
class A
{
    public function test() {}
    protected function test2() {}
    private function test3() {}
}

class B extends A
{
    public function __construct()
    {
        $this->
    }

    public function debug() {}
}

in this case you should get test, test2 and debug. So that will show whether padawan works at all or not

@golaod
Copy link
Author

golaod commented Sep 10, 2016

But as I wrote in my last comment: Everything depends on where you put those classes. If you have them both in the same class, then actually I don't need padawan to see test, test2 and debug, because sublime can handle it. Problem is when you put class A to file a.php and class B to file b.php, because padawan doesn't return methods from class A even though B extends A

@mkusher
Copy link
Member

mkusher commented Sep 11, 2016

@golaod sublime couldn't understand private\protected and etc. And I need to understand what's wrong

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

No branches or pull requests

2 participants