barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.27k stars 1.17k forks source link

Laravel ColumnDefintion autocomplete in Blueprint does not work #984

Closed pasamsin closed 4 years ago

pasamsin commented 4 years ago

why not autocomplete. I use PHPStorm. My project is Laravel version 7

migration file; Schema::create('personel', function (Blueprint $table) { $table->id(); $table->timestamps(); $table->integer('us_id')->un // Cannot complate unique }); config/ide-helper.php

`<?php

return array(

/*
|--------------------------------------------------------------------------
| Filename & Format
|--------------------------------------------------------------------------
|
| The default filename (without extension) and the format (php or json)
|
*/

'filename'  => '_ide_helper',
'format'    => 'php',

'meta_filename' => '.phpstorm.meta.php',

/*
|--------------------------------------------------------------------------
| Fluent helpers
|--------------------------------------------------------------------------
|
| Set to true to generate commonly used Fluent methods
|
*/

'include_fluent' => true,

/*
|--------------------------------------------------------------------------
| Factory Builders
|--------------------------------------------------------------------------
|
| Set to true to generate factory generators for better factory()
| method auto-completion.
|
*/

'include_factory_builders' => true,

/*
|--------------------------------------------------------------------------
| Write Model Magic methods
|--------------------------------------------------------------------------
|
| Set to false to disable write magic methods of model
|
*/

'write_model_magic_where' => true,

/*
|--------------------------------------------------------------------------
| Write Eloquent Model Mixins
|--------------------------------------------------------------------------
|
| This will add the necessary DocBlock mixins to the model class
| contained in the Laravel Framework. This helps the IDE with
| auto-completion.
|
| Please be aware that this setting changes a file within the /vendor directory.
|
*/

'write_eloquent_model_mixins' => true,

/*
|--------------------------------------------------------------------------
| Helper files to include
|--------------------------------------------------------------------------
|
| Include helper files. By default not included, but can be toggled with the
| -- helpers (-H) option. Extra helper files can be included.
|
*/

'include_helpers' => true,

'helper_files' => array(
    base_path().'/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
),

/*
|--------------------------------------------------------------------------
| Model locations to include
|--------------------------------------------------------------------------
|
| Define in which directories the ide-helper:models command should look
| for models.
|
*/

'model_locations' => array(
    'app',
),

/*
|--------------------------------------------------------------------------
| Models to ignore
|--------------------------------------------------------------------------
|
| Define which models should be ignored.
|
*/

'ignored_models' => array(

),

/*
|--------------------------------------------------------------------------
| Extra classes
|--------------------------------------------------------------------------
|
| These implementations are not really extended, but called with magic functions
|
*/

'extra' => array(
    'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
    'Session' => array('Illuminate\Session\Store'),
),

'magic' => array(),

/*
|--------------------------------------------------------------------------
| Interface implementations
|--------------------------------------------------------------------------
|
| These interfaces will be replaced with the implementing class. Some interfaces
| are detected by the helpers, others can be listed below.
|
*/

'interfaces' => array(

),

/*
|--------------------------------------------------------------------------
| Support for custom DB types
|--------------------------------------------------------------------------
|
| This setting allow you to map any custom database type (that you may have
| created using CREATE TYPE statement or imported using database plugin
| / extension to a Doctrine type.
|
| Each key in this array is a name of the Doctrine2 DBAL Platform. Currently valid names are:
| 'postgresql', 'db2', 'drizzle', 'mysql', 'oracle', 'sqlanywhere', 'sqlite', 'mssql'
|
| This name is returned by getName() method of the specific Doctrine/DBAL/Platforms/AbstractPlatform descendant
|
| The value of the array is an array of type mappings. Key is the name of the custom type,
| (for example, "jsonb" from Postgres 9.4) and the value is the name of the corresponding Doctrine2 type (in
| our case it is 'json_array'. Doctrine types are listed here:
| http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html
|
| So to support jsonb in your models when working with Postgres, just add the following entry to the array below:
|
| "postgresql" => array(
|       "jsonb" => "json_array",
|  ),
|
*/
'custom_db_types' => array(

),

/*
 |--------------------------------------------------------------------------
 | Support for camel cased models
 |--------------------------------------------------------------------------
 |
 | There are some Laravel packages (such as Eloquence) that allow for accessing
 | Eloquent model properties via camel case, instead of snake case.
 |
 | Enabling this option will support these packages by saving all model
 | properties as camel case, instead of snake case.
 |
 | For example, normally you would see this:
 |
 |  * @property \Illuminate\Support\Carbon $created_at
 |  * @property \Illuminate\Support\Carbon $updated_at
 |
 | With this enabled, the properties will be this:
 |
 |  * @property \Illuminate\Support\Carbon $createdAt
 |  * @property \Illuminate\Support\Carbon $updatedAt
 |
 | Note, it is currently an all-or-nothing option.
 |
 */
'model_camel_case_properties' => false,

/*
|--------------------------------------------------------------------------
| Property Casts
|--------------------------------------------------------------------------
|
| Cast the given "real type" to the given "type".
|
*/
'type_overrides' => array(
    'integer' => 'int',
    'boolean' => 'bool',
),

/*
|--------------------------------------------------------------------------
| Include DocBlocks from classes
|--------------------------------------------------------------------------
|
| Include DocBlocks from classes to allow additional code inspection for
| magic methods and properties.
|
*/
'include_class_docblocks' => false,

); `

mfn commented 4 years ago

What command did you run exactly? What was the output? What version of ide-helper?

pasamsin commented 4 years ago

Phpstorm 2020.1 ide-helper version latest 2.7.0 The commands that I run respectively. composer require --dev barryvdh/laravel-ide-helper

And config/app.php add line; Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

And vendor/barryvdh/laravel-ide-helper/config/ide-helper.php edit line; 'include_fluent' => true,

and command run; php artisan ide-helper:generate php artisan ide-helper:meta

pasamsin commented 4 years ago

`composer require --dev barryvdh/laravel-ide-helper Using version ^2.7 for barryvdh/laravel-ide-helper ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 14 installs, 0 updates, 0 removals

pasamsin commented 4 years ago

I created a new project with laravel v6.18.8. I installed barryvdh/laravel-ide-helper. I wrote "$table->string('test')->u" in the migration file and completed it as "$table->string('test')->unique();". Doesn't there support for barryvdh/laravel-ide-helper in laravel 7.x?

mfn commented 4 years ago

Thanks, got it. Turns out I can't read properly, it's what you wrote in the first comment 😅

Would you mind adjusting the issue title so something more useful? E.g. "Blueprint unique autocomplete not working"

mfn commented 4 years ago

Maybe it's a bug in phpstorm, because yes, autocomplete for tit doesn't not work however it recognizes the property and you can ctrl-click and jump to it! image

but image

The strange color 😅 indicates it is "recognized", when I ctrl-click on it I get to https://github.com/laravel/framework/blob/52d95bb75b1744d74dcedb1d465ad3316fecbda5/src/Illuminate/Database/Schema/ColumnDefinition.php#L25

mfn commented 4 years ago

Aha, this change "broke" it => https://github.com/laravel/framework/pull/33293

If you change the file back to the previous version using ColumnDefinition instead of static, autocomplete works for me => https://github.com/laravel/framework/blob/06ba2a99956161cca51008f19b6a18e548b31b6d/src/Illuminate/Database/Schema/ColumnDefinition.php

mfn commented 4 years ago

However: this is nothing ide-helper actually "does" 😄 in this case

This is pure standard IDE autocomplete behavior and you're not autocompleting on anything provided by ide-helper.

The Blueprint method string returns ColumnDefinition and therein a change caused the problem.

(for example we've the config include_fluent for then Blueprint methods return just Fluent, but this is not the case here).

I think needs to needs to be taken up with PhpStorm support https://youtrack.jetbrains.com/

mfn commented 4 years ago

I could not find anything in YouTrack (can't actually believe this, but the for "static method phpdoc" have me hundreds of results I did quickly scan without luck), so I created a new issue => https://youtrack.jetbrains.com/issue/WI-54071

Let's see what the feedback will there.

Although in a sense this issue here is not related to the package, we deal a lot with the IDE autocomplete / interop so I think it make sense to keep it open for tracking/discussing and observing what Jetbrains thinks about this.

mfn commented 4 years ago

@barryvdh we can close this issue:

mfn commented 4 years ago

Closing, as I still believe nothing to be done here anymore.

Laravels phpdoc for \Illuminate\Database\Schema\ColumnDefinition was already fixed an it's working.