barryvdh/laravel-ide-helper

Mixin Information Provided by Packages

tpetry opened this issue · 2 comments

The Laravel Idea plugin recently added support for packages to register mixins to existing Laravel classes that can't use the simple mixin methods (as the underlying driver needs to be replaced). With this new feature packages can finally enable autocomplete and proper jump-to-code functionality where it was impossible until now.

It would be nice if the IDE helper could support this json file or invent their own configuration file. Packages would then place this config at the root dir and the meta file generation would merge their information. The configuration file for my Laravel PostgreSQL driver for example looks like this:

{
    "$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
    "helperCode": {
        "classMixins": [
            {
                "classFqn": "Illuminate\\Contracts\\Database\\Query\\Builder",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Query\\Builder"
            },
            {
                "classFqn": "Illuminate\\Database\\Query\\Builder",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Query\\Builder"
            },
            {
                "classFqn": "Illuminate\\Database\\Schema\\Blueprint",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Schema\\Blueprint"
            },
            {
                "classFqn": "Illuminate\\Database\\Schema\\ColumnDefinition",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Schema\\ColumnDefinition"
            },
            {
                "classFqn": "Illuminate\\Database\\Schema\\IndexDefinition",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Schema\\IndexDefinition"
            },
            {
                "classFqn": "Illuminate\\Support\\Facades\\Schema",
                "mixinFqn": "Tpetry\\PostgresqlEnhanced\\Support\\Facades\\Schema"
            }
        ]
    }
}

All these mixins are currently impossible for e.g. Eloquent drivers/packages as they need to replace the existing driver instead of just exexuting QueryBuilder::mixin. And there is even no way currently no way to extend the IndexDefinition class with mixin methods. But with custom drivers it is possible but then auto-suggest is lost.

mfn commented

But how would ide-helper do this? Can you give an example how you imagine ide-helper helps here?

The IDE helper would (additionally to its normal work) scan the root directory of each installed package in the vendors package. When it finds an ide-helper.json file (this is the current name by the Laravel Idea plugin) it evaluates the information. It would then write (for example) a Builder class in _ide_helper.php file the methods it found in Illuminate\\Contracts\\Database\\Query\\Builder.