Skip to content

IDE Builder and Blueprint completions with ide.json #73

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

Merged
merged 4 commits into from
Feb 26, 2024

Conversation

adelf
Copy link
Contributor

@adelf adelf commented Feb 13, 2024

Hey. As promised, ide.json with new completions. I added only for Builder and Blueprint, maybe you will add some more.

It just adds /** @mixin YourBuilder */ class DatabaseBuilder{} during Laravwl Idea's Helper Code generation
So, PhpStorm will complete this class methods.

P.S. If you try to edit the ide.json file inside the vendor directory, Laravel Idea won't automatically load the changes. So, you will need to Laravel Idea Code Generation > Update ide.json metadata to load all changes:

image

It's only for your editing) users will fetch this file and all changes will be loaded automatically. They will need only to generate the helper file.

@tpetry
Copy link
Owner

tpetry commented Feb 13, 2024

@adelf Its so awesome that the QueryBuilder methods finally work. Thanks! ❤️

But the ColumnDefinition and IndexDefinition classes seem not to work:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('users', function (Blueprint $table) {
    // For $table->boolean('acl_admin') the initial() modifier is not suggested
    // For $table->boolean('acl_admin')->initial(true) all following modifiers are not
    //  suggested anymore and code-inspect does not work
    $table->boolean('acl_admin')
      ->initial(true)
      ->default(false);

    // For $table->index(['acl_admin']) the where() modifier is not suggested
    // For $table->index(['acl_admin'])->where('acl_admin = TRUE') all following modifiers are not
    //  suggested anymore and code-inspect does not work
    $table->index(['acl_admin'])
      ->where('acl_admin = TRUE')
      ->algorithm('brin');
});

@adelf
Copy link
Contributor Author

adelf commented Feb 13, 2024

So, you will need to Laravel Idea Code Generation > Update ide.json metadata to load all changes:
You probably forgot to make this and generate Helper Code after that. It works.

304527743-49c493a7-1c9c-4a2d-b80c-fcd774f8a6ae

However, I don't like creating classes in the library just for IDE completions. Maybe better to add "mixinMethods" to the ide.json file? And Laravel Idea will add needed methods to the classes?

@tpetry
Copy link
Owner

tpetry commented Feb 14, 2024

So, you will need to Laravel Idea Code Generation > Update ide.json metadata to load all changes

I extecuted that dozens of times. Together with the IDE helper re-generating all the stuff. I really don't understand how they interact with each other and what the correct sequence to call is. Or do I have to wait a few minutes after the ide.json update process?

However, I don't like creating classes in the library just for IDE completions. Maybe better to add "mixinMethods" to the ide.json file? And Laravel Idea will add needed methods to the classes?

I refactored it this way because then those new files are also helping PHPStan to know of these methods. I was able to remove some complex PHPStan extension code by that.

@tpetry
Copy link
Owner

tpetry commented Feb 14, 2024

I've now installed this PR directly instead of fiddling with the files directly and running manual update commands. Still only the query builder suggestions do work. I don't know what I am doing wrong as this would be the standard way for everyone installing the package.

@adelf
Copy link
Contributor Author

adelf commented Feb 19, 2024

Sorry for the long response; I had a little vacation. Could you just reopen the project, Generate Helper code, and then take a look at vendor/_laravel_idea/_ide_helper_macro.php

There should be

namespace Illuminate\Database\Schema {
    
    /**
     * @mixin \Tpetry\PostgresqlEnhanced\Schema\Blueprint
     */
    class Blueprint {}
    
    /**
     * @mixin \Tpetry\PostgresqlEnhanced\Schema\ColumnDefinition
     */
    class ColumnDefinition {}
    
    /**
     * @mixin \Tpetry\PostgresqlEnhanced\Schema\IndexDefinition
     */
    class IndexDefinition {}
}

@tpetry
Copy link
Owner

tpetry commented Feb 26, 2024

@adelf Its working - but very unreliable. I've deleted my project and recreated it and was presented with the blue PHP Storm bubble that I could run the Laravel Idea code generation. There I saw some progess bar working and everything works.

But nothing happens when I am running the Update ide.json data command. But Generate Helper Code works.

@tpetry tpetry merged commit 80066a2 into tpetry:master Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants