Skip to content

[vim] Support for Laravel IDE Helper #807

Closed

Description

@andersondanilo

Activity

  1. changed the title [-][vim[/-] [+][vim] Support for Laravel IDE Helper[/+] on Aug 6, 2019
  2. andersondanilo commented on Aug 6, 2019

    @andersondanilo
    Author
  3. dantleech commented on Aug 6, 2019

    @dantleech
    Collaborator

    I'm not familiar with Larvel - why is the helper file necessary - are the methods "magic" ? (also not sure why the methods have bodies, if this is a stub they would never be executed?)

    As an experiment (with no idea if it will work) you might try including the helper file by setting:

    "worse_reflection.stub_dir": "%application_root%\/vendor\/jetbrains\/phpstorm-stubs"
    

    in phpactor.yml (or phpactor.json) to the directory of the helper (instead of the php(storm stubs) (and then clearing the cache - phpactor cache:clear) this will break standard PHP function/class completion, but i it fixes the laravel issue, it would be simple to allow multiple files to be specified here.

    Otherwise if you have a link to a recent open laravel project on Github, I can try and have a look and see what the problems are.

    cc @einenlum will the above fix help, or do we need to support the Laravel autoloading mechanism (or do we need to support both stubs and the autoloading?)

  4. einenlum commented on Aug 7, 2019

    @einenlum
    Collaborator

    TBH, I was so pissed off by Laravel and its aliases (man, I miss Sf so much), I took a week to remove aliases everywhere on every project I could find, with a search and replace. Took me a week because even PHPStorm is not good to replace these aliases with the real classes…

    Now, this said, I can try on a previous version that have the aliases. Will try today.

  5. einenlum commented on Aug 7, 2019

    @einenlum
    Collaborator

    @dantleech The file is generated through an artisan command: artisan ide-helper:generate.
    It generates a _ide_helper.php file in the root of the app.

    ls -1
    
    app
    artisan
    bootstrap
    composer.json
    composer.lock
    config
    database
    deploy
    docker
    docker-compose.yml
    _ide_helper.php
    public
    README.md
    storage
    tests
    vendor

    I added the stub dir in my phpactor configuration:

    phpactor config:dump | grep worse
    
        "completion_worse.completor.class.limit": 100,
        "worse_reflection.enable_cache": true,
        "worse_reflection.cache_dir": "%cache%\/worse-reflection",
        "worse_reflection.stub_dir": "%application_root%\/_ide_helper.php",
        "worse_reference_finder.plain_text_break_chars": [

    Given the following file:

    <?php
    
    namespace App\Http\Controllers;
    
    class TestController extends BaseController
    {
        /**
         * @return \Illuminate\View\View
         */
        public function test()
        {
            // Get the data
            $foo = \C<>onfig::get('foo');
    
            // ...
        }
    }

    When I try to jump on definition, I get: Error from Phpactor: Unable to locate class "Config", Word "\Config" could not be resolved to a class.

    Edit: I forgot to clear the cache. Otherwise it would have said _ide_helper.php is not a directory.

  6. einenlum commented on Aug 7, 2019

    @einenlum
    Collaborator

    Oh! My bad @dantleech ! It works!

    I moved the _ide_helper.php file to vendor/ide-test. Then updated my config:

    ➜  ~ phpactor config:dump | grep worse
        "completion_worse.completor.class.limit": 100,
        "worse_reflection.enable_cache": true,
        "worse_reflection.cache_dir": "%cache%\/worse-reflection",
        "worse_reflection.stub_dir": "\/tmp\/somefolder\/vendor\/ide-test",
        "worse_reference_finder.plain_text_break_chars": [
    ➜  ~ 

    Updated the cache, and it works!
    It just does not work with a relative path. It seems %application_root% is transformed to the path of phpactor and not where the application lives (it's probably wanted?).

    Edit: of course it's wanted cause phpactor can be run outside vim 🤦‍♂️

  7. andersondanilo commented on Aug 7, 2019

    @andersondanilo
    Author

    I tried to copy the file _ide_helper.php to ~/.vim/bundle/phpactor/vendor/jetbrains/phpstorm-stubs and now its working (after cache:clear)

  8. dantleech commented on Aug 7, 2019

    @dantleech
    Collaborator

    It just does not work with a relative path.

    Maybe %project_root% if you want the root of the project?

    ... and now its working (after cache:clear)

    Great news :) I will keep this ticket open in order to change the code to accept an array of locations for stubs (and maybe add a Laravel integration page in the docs

  9. FatBoyXPC commented on Jan 15, 2021

    @FatBoyXPC

    Now that phpactor uses an index, _ide_helper.php and _ide_helper_model.php seem to be picked up by the indexer. There is currently a looming issue with the @mixin tag not being supported yet, so technically this doesn't work, but it's a closer than I previously realized! The stubs path isn't necessary!

  10. robclancy commented on Jan 10, 2023

    @robclancy

    It seems the helper is "overriding" some vendor files in phpactor too. For example it doesn't see $request->user() as valid because the request it is using is from the _ide_helper.php file only. I think it's meant to "magically" use that along with the file from vendor.

    The linked example above has all methods defined but mine has just magic ones, so I'm going to see if there is a way to just do all methods again like it used to.

  11. calebdw commented on Feb 10, 2023

    @calebdw

    I was pleasantly surprised to see that phpactor picked up on the _ide_helper.php and _ide_helper_models.php files out-of-the-box (using Neovim and the phpactor language server), however, there's two issues:

    1. All of my Laravel classes and models are overridden, so jumping to definitions takes me straight to the _ide_helper* files.
    2. I tried to circumvent this behaviour by using the @mixin tag, but it phpactor doesn't pick up on this.

    Also, it doesn't look like the PhpStorm meta file (.phpstorm.meta.php) is picked up, is support for that on the roadmap? I saw some other issues mention it.

  12. haringsrob commented on Apr 16, 2023

    @haringsrob
    Contributor

    Running into this now as well. IDE helper generates a same class names with docs in a separate file. This files is being indexed but it loses the scope of the original class.

    While mixin works, ideally this would not be required.

    I might try to tackle this, but some pointers on where to start digging would be welcome :).

  13. dantleech commented on Apr 16, 2023

    @dantleech
    Collaborator

    I'm not sure what needs to be done exactly. Would we want the analysis and docs to use the "helper" while goto definition / find references ignores the stub file? Without actually working on a Laravel project I'm not sure.

  14. haringsrob commented on Apr 16, 2023

    @haringsrob
    Contributor

    So ide helper generates for example _ide_models.php with something like this:

    namespace App\Models{
    /**
     * App\Models\Board
     *
     * @property int $id
     * @property string $name
     * @property bool $available
     * @property int $event_id
     * @property \Illuminate\Support\Carbon|null $created_at
     * @property \Illuminate\Support\Carbon|null $updated_at
     * @property-read \App\Models\Event|null $event
     * @property-read \App\Models\Game|null $game
     * @method static \Illuminate\Database\Eloquent\Builder|Board newModelQuery()
     * @method static \Illuminate\Database\Eloquent\Builder|Board newQuery()
     * @method static \Illuminate\Database\Eloquent\Builder|Board query()
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereAvailable($value)
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereCreatedAt($value)
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereEventId($value)
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereId($value)
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereName($value)
     * @method static \Illuminate\Database\Eloquent\Builder|Board whereUpdatedAt($value)
     * @mixin \Eloquent
     */
    	class Board extends Model {}
    }

    The helper only documents things that are not part of the model itself.

    Now what happens (I think) is because the class Board is the same as my actual Board class, it ignores that one and only indexes the helper file.

    This results in actually defined methods to be ignored.

    It is perfectly fine for goto-definition to go to the helper file if it is a documented property/method/.., however, the original class should continue to work.

    Sorry if this is not explained well.

  15. 9 remaining items

  16. xtvk commented on May 30, 2023

    @xtvk

    I would also like to know how people are using phpactor with laravel-ide-helper.

    Currently, (1) if I use laravel-ide-helper, things like $request->user() are regarded as undefined methods because of the overriding behavior described above. (2) On the other hand, if I don't use laravel-ide-helper, I can't handle Laravel's (problematic) magic methods like User::create(...).

    Both of the options aren't desirable. Did anyone find any workarounds?

  17. danrot commented on Jun 19, 2023

    @danrot

    As an experiment (with no idea if it will work) you might try including the helper file by setting:

    "worse_reflection.stub_dir": "%application_root%\/vendor\/jetbrains\/phpstorm-stubs"
    

    in phpactor.yml (or phpactor.json) to the directory of the helper (instead of the php(storm stubs) (and then clearing the cache - phpactor cache:clear) this will break standard PHP function/class completion, but i it fixes the laravel issue, it would be simple to allow multiple files to be specified here.

    is it already possible to specifiy multiple files here?

  18. dantleech commented on Jun 19, 2023

    @dantleech
    Collaborator

    No, but you should be able to do it here: https://phpactor.readthedocs.io/en/master/reference/configuration.html#indexer-stub-paths but I don't know if related to this issue?

  19. danrot commented on Jun 20, 2023

    @danrot

    Well, the thing is that in Laravel there is an _ide_helper.php and _id_helper_models.php file, and both need to be loaded. And in addition I also want the plain PHP functions to work. So I think this is related. I tried the indexer.stub_paths option, but it seems like I cannot set files here, directories must be passed instead. Wouldn't it make sense to be able to pass files as well to this option?

    However, putting both files in the same folder and add this folder to this indexer.stub_paths option works fine.

  20. einenlum commented on Jan 11, 2024

    @einenlum
    Collaborator

    I tried again and everything works out of the box with _ide_helper.php and _ide_helper_models.php. Not sure this issue still needs to stay open.

  21. calebdw commented on Jan 12, 2024

    @calebdw

    @einenlum, it does not work out of the box, #2420 is still an issue.

  22. einenlum commented on Jan 12, 2024

    @einenlum
    Collaborator

    Oh my bad 👍

  23. dave2309 commented on Aug 19, 2024

    @dave2309

    Hi all,

    Using the laravel ide helper here with vim and some laravel projects.
    Generating _ide_helper.php and _ide_helper_models.php into a folder (.ide_helpers) at the root of the project.
    Adding to .phpactor.json the line "indexer.stub_paths": ["%project_root%\/.ide_helpers\/"]
    The above resolve for me the facades (models mostly) functions to be known.
    Now something I came across is the reflection getting only interfaces function definition instead of concrete class.
    Example is for $this->app->isLocal() for instance does underline isLocal() not to be part of the interface (which is true).
    but isLocal() can be found in _ide_helper.php

    Any news on this front?

  24. vivere-dally commented on Nov 22, 2024

    @vivere-dally

    Coming to this issue since I upgrade my neovim version and config (my bad lol?) and I can't manage to get this to work (it was working previously). Could there be any issue with the new phpactor version?

    Previously I only generated the ide helper in my project root, and phpactor would work out of the box (no config needed). But now, I tried all config options here, the indexer says it is loading them, and I still get issues reported for Model::query()->join for example.

    Anyone know how to address this?

  25. dantleech commented on Nov 22, 2024

    @dantleech
    Collaborator

    I think somebody needs to investigate it, as I probably won't have time and as it doesn't affect my work directly there isn't much motivation for me to look into it. I'm happy to provide pointers in a discussion and help out.

  26. bilogic commented on Nov 3, 2025

    @bilogic
    1. I explain how Laravel facades work here and eventually found the @mixin solution Possible to handle Laravel Facades? vscode-phpactor#209
  27. dantleech commented on Nov 29, 2025

    @dantleech
    Collaborator

    This should finally be addresed by Additive Stubs.

    Note that for Larvel you should change the indexer.include_patterns to includes the project source directories explicitly to avoid _ide_helper.php from being indexed (it should only be incldued as an "additive stub file").

    Closing the issue for now, please re-open or comment if it is not fixed.

  28. nickkadutskyi commented on Nov 29, 2025

    @nickkadutskyi

    @dantleech

    I have files output from ide-helper in a subdirectory .ide_helpers and then I add that directory as stab_paths like this:

    {
      "language_server_phpstan.enabled": false,
      "language_server_psalm.enabled": false,
      "language_server_php_cs_fixer.enabled": false,
      "indexer.stub_paths": [
        "%project_root%\/.ide_helpers\/"
      ],
      "indexer.exclude_patterns": [
        "\/vendor\/**\/Tests\/**\/*",
        "\/vendor\/**\/tests\/**\/*",
        "\/vendor\/composer\/**\/*",
        "\/.direnv\/",
        "\/.devenv\/",
        "\/.git\/",
        "\/.jj\/"
      ],
      "language_server.diagnostic_ignore_codes": [
        "worse.docblock_missing_param",
        "worse.missing_member"
      ]
    }
    

    Do I need to limit what I add to indexer.include_patterns in this case? Or maybe I can add "%project_root%\/.ide_helpers\/" to indexer.exclude_patterns?

    From the docs default value in indexer.include_patterns is ["\/**\/*.php","\/**\/*.phar"] which will include contents of my .ide_helpers directory, but my assumption was that since that dir is in stub_paths it should be excluded.

  29. dantleech commented on Nov 30, 2025

    @dantleech
    Collaborator

    Do I need to limit what I add to

    As noted in the docs, you probably do not want to override the stub paths as these are used for PHP core stubs and should be set by defualt to the jetbrains ide stubs - which you need.

    You need to use the "additive stubs".

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions