vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Some methods of Laravel Model cannot be completed by classes belonging to namespace (v1.9.x after)

Open yaegassy opened this issue 1 year ago • 7 comments

Describe the bug

It seems that input completion and other functions that worked fine in v1.8.2 and earlier no longer work in v1.9.x.

Some methods do not appear in the completion candidates for the following use cases.

Therefore, you need to downgrade your version to v1.8.2 to comfortably use intelephense...

To Reproduce

Prepare:

# Creating a Laravel Project
cd /tmp
composer create-project laravel/laravel example-app

# Installing barryvdh/laravel-ide-helper
cd example-app
composer require --dev barryvdh/laravel-ide-helper

# Configure .env files to use sqlite
sed -i -e "s/^DB_CONNECTION=mysql/DB_CONNECTION=sqlite/g" .env
sed -i -e "s/^DB_DATABASE=/#DB_DATABASE=/g" .env

# Creation of database.sqlite file
touch database/database.sqlite

# Create controllers, etc. along with the creation of the model
php artisan make:model Dummy --all

# Creation of _ide_helper.php file
php artisan ide-helper:generate
# Creation of _ide_hepler_models.php file
php artisan ide-helper:model -N

DEMO (mp4)

[OK] routes/web.php

Files that do not belong to a namespace

Methods such as Dummy::where are correctly displayed in the completion candidates.

https://user-images.githubusercontent.com/188642/221446254-a83996c0-368b-4920-a2b0-b7fa3bd68640.mp4

[NG] app/Http/Controllers/DummyController.php

Files belonging to namespace file

Some completion candidates such as Dummy::where are not displayed...

https://user-images.githubusercontent.com/188642/221446265-3b417e32-fd0a-4a84-bba1-75c96b3b0bf8.mp4

[OK] app/Http/Controllers/DummyController.php (Use "v1.8.2")

Files belonging to namespace file

Methods such as Dummy::where are correctly displayed in the completion candidates.

https://user-images.githubusercontent.com/188642/221446288-f69c2894-6141-4bee-b98f-a2516f12e1c3.mp4

Platform and version

  • macOS Venture 13.2.1
  • intelephense v1.9.5

yaegassy avatar Feb 27 '23 00:02 yaegassy

This could be the same issue. https://github.com/bmewburn/vscode-intelephense/issues/2459

yaegassy avatar Feb 27 '23 04:02 yaegassy

NOTE: One current temporary solution is to add @mixin \Eloquent to the actual model file.

e.g.:

/**
 * @mixin \Eloquent
 */
class Dummy extends Model
{
    // ...snip
}

yaegassy avatar Mar 13 '23 07:03 yaegassy

@yaegassy are you sure @mixin works? Just tried and is not working. I am on v1.9.5 . It works properly on 1.8.2 but not 1.9.5

The Dummy::where() autocompleting just works while indexing workspace, but after that it does not work anymore.

image

robsontenorio avatar Sep 24 '23 22:09 robsontenorio

@yaegassy are you sure @mixin works? Just tried and is not working. I am on v1.9.5 . It works properly on 1.8.2 but not 1.9.5

@robsontenorio I tried it again in my environment and it works fine.

yaegassy avatar Sep 25 '23 00:09 yaegassy

@yaegassy hum... it seems it is a premium feature. Right?

robsontenorio avatar Sep 25 '23 00:09 robsontenorio

@robsontenorio It's working with or without premium features.

yaegassy avatar Sep 25 '23 00:09 yaegassy

I cannot get the @mixin autocomplete to work. I'm Using PHP Intelephense v1.10.2, with VSCode 1.85.1.

This is my model class:

/**
 * App\Models\Game
 *
 * @property int $id
 * @property string $name
 * @property OperativeSystem $operative_system
 * @property GamePlatform $platform
 * @property string $latest_version
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @mixin \Eloquent
 */
class Game extends Model
{
    // 
}

And when I try to autocomplete for where, whereNotIn, newQuery and other static magic methods, I only get the autocomplete from Github Copilot and the built in basic text autocomplete, but not the autocomplete from Intelephense showing me the method arguments and docs:

GIF

Any idea of what am I missing?

The \Eloquent class is defined in the _ide_helper.php file.

jhm-ciberman avatar Jan 16 '24 18:01 jhm-ciberman

Closing as my understanding is the @mixin with ide helper solves this. @mixin is only recognised in the premium version. You can also extend \Eloquent instead of using mixing.

bmewburn avatar Jul 06 '24 01:07 bmewburn