Skip to content

[Vim] Tell me how to use Laravel IDE Helper with phpactor? #611

Closed

Description

@maamo888

Hi. dantleech

First of all, I appreciate phpactor and related great tools.

Thank you for a useful phpactor.

Do you know the Laravel IDE Helper?

https://github.com/barryvdh/laravel-ide-helper

Please tell me how to use Laravel IDE Helper with phpactor.

Make a _ide_helper.php with called php artisan ide-helper:generate command.

Is there a way to use _ide_helper.php with phpactor?


similar vim plugin

An example of a similar vim plugin phpcd.vim.

e.g: https://github.com/lvht/phpcd.vim/wiki/Laravel-Facade-Support

Activity

  1. dantleech commented on Oct 9, 2018

    @dantleech
    Collaborator

    hi,

    support for this might come in the future (there is a PR for virtual methods which would easily extend to virtual propertes.

    But not sure eactly how the IDE helper stubs work for laravel, it shouldn't be too hard to implement given the above PR.

  2. maamo888 commented on Oct 9, 2018

    @maamo888
    Author

    Thank you for reply.

    I look forward to future updates.

  3. FatBoyXPC commented on Mar 2, 2019

    @FatBoyXPC

    Now that the above mentioned PR is done, how likely is it to see support for this soon? 😍 If you gave me some direction I might take a crack at adding support for this!

  4. dantleech commented on Mar 2, 2019

    @dantleech
    Collaborator

    The PR above enables virtual methods, i.e. it supports the @method Foobar bar() annotations. It doesn't support properties yet. What needs to be done in order to support this? (e.g. what is an _ide_helper.php file?)

  5. FatBoyXPC commented on Mar 2, 2019

    @FatBoyXPC

    Here's an example _ide_helper.php I found. It looks like for the most part it's just extending the classes and adding very simple function definitions on it.

    I believe that Laravel 5.6+ use a lot of virtual method stuff in the docblocks so this PR should just natively pick those up :)

  6. dantleech commented on Mar 3, 2019

    @dantleech
    Collaborator

    hmm. So does the method Illuminate\Support\Facades::version() (for example) exist? or all of these "magic" non-existing classes?

  7. dantleech commented on Mar 3, 2019

    @dantleech
    Collaborator

    I guess the easiest way would be to add a new StubSourceLocator, like this.

    ☝️ the "dir" would just need to be the directory containing _ide_helper.php (and it looks like we also need to specify the name of the cache file, as I guess it will currently overwrite the same on when we have multiple).

    You can then even create a new Phpactor Extension (e.g. laravel-extension) (and/or we can make it possible to configure multiple stub locators, although the laravel extension could maybe include the necessary stub file ??)

    The only problem I see is if the Laravel class / method can be found with the Composer source locator, in which case we would need to ensure the new stub locator has a higher priority (and probably I can add a feature to specify a priority)

  8. FatBoyXPC commented on Mar 3, 2019

    @FatBoyXPC

    So in this case version() exists on the class that the App facade resolves to, which is \Illuminate\Foundation\Application. Facades forward calls on to the resolved class via __callStatic.

    Given this code:

    use Illuminate\Support\Facades\App;
    
    App::version();

    In this case the App facade doesn't a static version() method defined. __callStatic is invoked and that method will pull \Illuminate\Foundation\Application from the dependency container and call that method on that object.

    RE: Composer vs IDE Helper priority: Is this a priority of which they show up in the list, or does this mean if it's found via one locator the other locator won't attempt to find it?

    I'll take a look at making an extension but I expect to have a lot of questions based off the quick glance I just took.

  9. dantleech commented on Mar 3, 2019

    @dantleech
    Collaborator

    Composer vs IDE Helper priority: Is this a priority of which they show up in the list, or does this mean if it's found via one locator the other locator won't attempt to find it?

    We are strictly talking about how the reflection code (worse reflection) is able to locate the class definition. If the composer locator gets there first, you will only see the members defined in that file (probably nothing I guess?) but if a stub locator got there first it would resolve to the version defined in _ide_helper.php.

    The extension in-itself would be quite simple (and should really be only plumbing -- we already have the code for this, but it might need some tweaking ... :) )

    This method would also mean that if you "jump to definition" on Illuminate\Support\Facades\App you will land in the _ide_helper.php file.

  10. FatBoyXPC commented on Mar 3, 2019

    @FatBoyXPC

    Oh, I see, so this is similar to when I want to "Find References" and it asks if I want to use git, composer, etc?

    probably nothing I guess?

    That depends on which Laravel version. Somewhere around 5.5 or 5.6 people started adding @method docblocks to some Facade classes in PRs, such as the App facade has this:

    /**
     * @method static string version()
     * @method static string basePath()
     * @method static string environment()
     * @method static bool isDownForMaintenance()
     * @method static void registerConfiguredProviders()
     * @method static \Illuminate\Support\ServiceProvider register(\Illuminate\Support\ServiceProvider|string $provider, array $options = [], bool $force = false)
     * @method static void registerDeferredProvider(string $provider, string $service = null)
     * @method static void boot()
     * @method static void booting(mixed $callback)
     * @method static void booted(mixed $callback)
     * @method static string getCachedServicesPath()
     *
     * @see \Illuminate\Foundation\Application
     */

    That's not a complete list, though, and not all Facades have them, so I would definitely prefer for the IDE Helper locator to do the searching instead of composer, at least for now until more of these annotations get added.

  11. dantleech commented on Mar 3, 2019

    @dantleech
    Collaborator

    Oh, I see, so this is similar to when I want to "Find References" and it asks if I want to use git, composer, etc?

    No this is different, "find references" needs a list of all the files in your project (and it can use some different strategies to do that). For the most part WorseRefelection can guess very quickly where to find a particular class based on the fully qualified name of the class.

    If the facade has those annotations then that should indeed work fine now.

    I guess it would make sense to allow additional stub files / directories to be specified, and then adding priority if necessary (if it's just configuration, then it can be in config order). If that worked really well, then maybe it would make sense to have a Laravel Extension which helped with that.

  12. FatBoyXPC commented on Mar 3, 2019

    @FatBoyXPC

    The annotations do work great for Laravel 5.6+, but again, it doesn't capture everything. It also doesn't include model attributes (though I could add those myself) or Query Builder methods (where, orWhere, etc, those all go through __call) and adding those myself would be tedious.

    So this "priority" concept - does the higher priority thing become what searches, or do they both get searched but the results are sorted via priority?

  13. FatBoyXPC commented on Mar 3, 2019

    @FatBoyXPC

    I guess it would make sense to allow additional stub files / directories to be specified, and then adding priority if necessary (if it's just configuration, then it can be in config order). If that worked really well, then maybe it would make sense to have a Laravel Extension which helped with that.

    Yeah, I think that would be a really easy solution to the problem if the supporting changes are easy enough.

  14. einenlum commented on Jul 15, 2019

    @einenlum
    Collaborator

    I unfortunately need to work with Laravel right now (first time) and… Wow. It's hard to understand where all the magic happens. Really struggling. Implementing this laravel-ide-helper could really help me, because I need to switch to PHPStorm right now to understand the code.

  15. dantleech commented on Jul 15, 2019

    @dantleech
    Collaborator

    I have never used Laravel, so it's difficult for me to help directly -- but it might be possible to try a potential fix easily:

    • try composer require the laravel-ide-helper package
    • set the stub_dir from "worse_reflection.stub_dir": "%application_root%\/vendor\/jetbrains\/phpstorm-stubs" to point to the laravel ide stubs
    • clear the cache

    this will replace the PHP built-in stubs with the laravel ones, not sure to what extent this will work, but might yield interesting results and subsequetly supporing multiple stub dirs would be easy I guess.

  16. dantleech commented on Jul 15, 2019

    @dantleech
    Collaborator

    IIRC Laravel also overrides the autoloader, to provide "convenient" shortcuts. In this case the existing source location methods might not work as expected, which could possibly be addressed with a new location strategy similar to this hack in BetterReflection.

  17. einenlum commented on Jul 15, 2019

    @einenlum
    Collaborator

    @dantleech Indeed, it uses "aliases" in the config/app.php file, that are not loaded by composer's autoload, but that Laravel can find however.

        'aliases' => [
            'App'       => 'Illuminate\Support\Facades\App',
            'Artisan'   => 'Illuminate\Support\Facades\Artisan',
            'Auth'      => 'Illuminate\Support\Facades\Auth',
            'Blade'     => 'Illuminate\Support\Facades\Blade',
            // ...
        ]

    Allowing \Auth anywhere in the code.

    Thanks for the above comment about the stub, gonna try when I have some time.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions