Skip to content

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

Open

Description

@golaod

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?

Activity

  1. mkusher commented on Sep 8, 2016

    @mkusher
    Member

    @golaod can you provide more examples?

  2. golaod commented on Sep 8, 2016

    @golaod
    Author

    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
        }
    }
    
  3. mkusher commented on Sep 8, 2016

    @mkusher
    Member

    @golaod are you using master version?

  4. mkusher commented on Sep 8, 2016

    @mkusher
    Member

    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

  5. golaod commented on Sep 8, 2016

    @golaod
    Author

    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].
    
  6. golaod commented on Sep 9, 2016

    @golaod
    Author

    Any suggestions?

  7. mkusher commented on Sep 9, 2016

    @mkusher
    Member

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

  8. golaod commented on Sep 9, 2016

    @golaod
    Author

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

  9. mkusher commented on Sep 9, 2016

    @mkusher
    Member

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

  10. golaod commented on Sep 9, 2016

    @golaod
    Author
    ~/.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.
    
  11. mkusher commented on Sep 9, 2016

    @mkusher
    Member

    @golaod can you show your global composer.json?

  12. golaod commented on Sep 9, 2016

    @golaod
    Author
    cat composer.json 
    {
        "require": {
            "mkusher/padawan-di": "^0.1.1",
            "pbogut/padawan-magento": "dev-master"
        },
        "minimum-stability": "dev"
    }
    
  13. mkusher commented on Sep 9, 2016

    @mkusher
    Member

    @golaod please, try following:

    $ composer global remove react/react
    $ composer global require mkusher/padawan:dev-master
  14. golaod commented on Sep 9, 2016

    @golaod
    Author

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

  15. golaod commented on Sep 9, 2016

    @golaod
    Author

    Nope, still doesn't autocomplete.

  16. 11 remaining items

  17. golaod commented on Sep 9, 2016

    @golaod
    Author

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

  18. golaod commented on Sep 9, 2016

    @golaod
    Author

    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'
    
  19. mkusher commented on Sep 9, 2016

    @mkusher
    Member

    @golaod thx, will try to debug it later

  20. mkusher commented on Sep 9, 2016

    @mkusher
    Member

    @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?)?

  21. golaod commented on Sep 10, 2016

    @golaod
    Author

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

  22. golaod commented on Sep 10, 2016

    @golaod
    Author

    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

  23. mkusher commented on Sep 10, 2016

    @mkusher
    Member

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

  24. golaod commented on Sep 10, 2016

    @golaod
    Author

    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

  25. mkusher commented on Sep 10, 2016

    @mkusher
    Member

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

  26. golaod commented on Sep 10, 2016

    @golaod
    Author

    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

  27. mkusher commented on Sep 10, 2016

    @mkusher
    Member

    @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?

  28. golaod commented on Sep 10, 2016

    @golaod
    Author

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

  29. mkusher commented on Sep 10, 2016

    @mkusher
    Member

    @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

  30. golaod commented on Sep 10, 2016

    @golaod
    Author

    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

  31. mkusher commented on Sep 11, 2016

    @mkusher
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions