Skip to content
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

not interprets @mixin annotations. #123

Closed
xiaohuilam opened this issue Aug 5, 2018 · 64 comments
Closed

not interprets @mixin annotations. #123

xiaohuilam opened this issue Aug 5, 2018 · 64 comments
Labels
feature premium Premium feature accessible to licence key holders
Milestone

Comments

@xiaohuilam
Copy link

xiaohuilam commented Aug 5, 2018

This extension works perfect under vscode.

but interprets @mixin annotations. eg: laravel's framework code..

<?php

namespace Illuminate\Database\Eloquent;

use Exception;
use ArrayAccess;
use JsonSerializable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Contracts\Queue\QueueableEntity;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Contracts\Queue\QueueableCollection;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\ConnectionResolverInterface as Resolver;

/**
 * 
 *
 * @mixin \Eloquent
 * @mixin \Illuminate\Database\Query\Builder
 * @mixin \Illuminate\Database\Eloquent\Builder
 */
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
{
    use Concerns\HasAttributes,
        Concerns\HasEvents,
        Concerns\HasGlobalScopes,
        Concerns\HasRelationships,
        Concerns\HasTimestamps,
        Concerns\HidesAttributes,
        Concerns\GuardsAttributes;
@andreshg112
Copy link

Same here!

@xiaohuilam
Copy link
Author

That's a so great feature, It will be bravo if only vsc-intel did recognize mixin.

@nmsmith22389
Copy link

Any updates on this? This is one of the only things that this extension is missing. Please implement it! 🙏

@xiaohuilam
Copy link
Author

Hey @bmewburn, did you forget this feature?

@d8vjork
Copy link

d8vjork commented Aug 29, 2019

Also get the same feature request today working with traits (1 year old issue, wow)

This will be wonderful for everything on PHP

@star2000
Copy link

Is it difficult to support @mixin? @bmewburn

@bmewburn
Copy link
Owner

bmewburn commented Oct 6, 2019

Is it just Laravel that needs this? With barryvdh/laravel-ide-helper ? Reason I haven't prioritised it is because @mixin is not a standard annotation and doesn't look like it will be standardised. I think it only gained some support back before PHP had traits.

@xiaohuilam
Copy link
Author

Is it just Laravel that needs this? With barryvdh/laravel-ide-helper ? Reason I haven't prioritised it is because @mixin is not a standard annotation and doesn't look like it will be standardised. I think it only gained some support back before PHP had traits.

I guess not, There should be many frameworks which prefer to use __call or __callStatic magic, they will ask for @mixin to support annotations.

@xiaohuilam
Copy link
Author

barryvdh/laravel-ide-helper

The package barryvdh/laravel-ide-helper is helpless with @mixin, it can only help to generate Facade methods、Model column properties and scope methods, and ioc (phpstorm.meta.php), but can't enhancement for @mixin(i guess the reason is that phpstorm native support @mixin )

@bmewburn
Copy link
Owner

bmewburn commented Oct 6, 2019

Models can extend the \Eloquent class it generates instead of \Illuminate\Database\Eloquent\Model.

@benyaminl
Copy link

benyaminl commented Oct 8, 2019

Models can extend the \Eloquent class it generates instead of \Illuminate\Database\Eloquent\Model.

I have tried the extension. No hope for it. Still rely on mixin and Barry extension doesn't support all facade

@bmewburn
Copy link
Owner

bmewburn commented Oct 8, 2019

Can I get an example of what methods aren't shown when extending \Eloquent? In my tests barryvdh/laravel-ide-helper works well.

Screenshot from 2019-10-08 21-27-11

@benyaminl
Copy link

benyaminl commented Oct 8, 2019 via email

@xiaohuilam
Copy link
Author

Not only the lumen, But also App\User which extends from Illuminate\Foundation\Auth\User is hardcoded to extend Illuminate\Database\Eloquent\Model, makes us hard to manipulate to Eloquent

@benyaminl
Copy link

Illuminate\Foundation\Auth\User

Ugh seems yes. https://laravel.com/api/5.6/Illuminate/Foundation/Auth/User.html I never touch it because it's my friend job so I never know this.

Anyway let Ben decide first, I think if it's about money then why don't we set up the patreon again :v
So like new features will be shipped faster if it gets supporter.

@bmewburn
Copy link
Owner

I'm not saying this won't get implemented. I'm just trying to understand the need for it and to decide the priority amongst all the other issues.

@zedisdog
Copy link

with this feature, I can use vscode instead of phpstorm.:satisfied:

@benyaminl
Copy link

benyaminl commented Oct 16, 2019 via email

@slcastroj
Copy link

slcastroj commented Dec 17, 2019

@bmewburn Mixin is required for it to show both \Eloquent and MyModel methods e.g. where vs whereField or all vs get while using IDE helper. A workaround is to use /** @var MyModel|\Eloquent */ over each variable so you can get full autocompletion.

Edit: Sorry, this is not the case, or maybe I didn't use IDE helper the right way before. Mixin support would enable full autocompletion with IDE helper without having to replace all model extends with \Eloquent for it to work. It would be pretty laravel-specific.

@neoighodaro
Copy link

@bmewburn Mixin is required for it to show both \Eloquent and MyModel methods e.g. where vs whereField or all vs get while using IDE helper. A workaround is to use /** @var MyModel|\Eloquent */ over each variable so you can get full autocompletion.

Edit: Sorry, this is not the case, or maybe I didn't use IDE helper the right way before. Mixin support would enable full autocompletion with IDE helper without having to replace all model extends with \Eloquent for it to work. It would be pretty laravel-specific.

What he said. I was a little surprised to know it did not support it. Its a very useful feature. I wont type everything he said as a reason since he alrewady mentioned it, but it's very useful.

@WilliamStam
Copy link

im using it for another library other than laravel stuff. @mixin is amazing in phpstorm but in vscode :/

@flexchar
Copy link

flexchar commented May 5, 2020

@bmewburn I'd like to ping you on this.

There are many PHP frameworks that utilize some kind of magic, thus making it harder for IDEs to track down what properties/methods are available. Speaking of Laravel, there is an ide-helper plugin that helps generate missing docs and helps IDE also by inserting @mixin.

While @mixin is not an official api, it would allow inherit those methods for many classes. In Laravel it would provide complete set of methods for model classes, for facades, for static calls. I understand that it may be hard to foresee the need, however having auto completion, method signatures are insanely helpful.

I already use it as a main extension and loving all the full features. This would improve PHP developers performance by a significant amount!

For reference, I include phpStorm issue https://youtrack.jetbrains.com/issue/WI-1730 and a practical article about it https://freek.dev/1482-the-mixin-php-docblock

@andreshg112
Copy link

andreshg112 commented May 7, 2020

If a class extends \Eloquent
imagen

Then it doesn't autocomplete doc-defined methods or properties after the first one:
imagen

imagen

However, if I change \Eloquent to ...\Builder in doc-defined properties or if it extends Model instead of \Eloquent, it works.

So, I think it would be better using @mixin than extending \Eloquent.

@bmewburn bmewburn added this to the shortlist milestone May 20, 2020
@Deji69
Copy link

Deji69 commented May 24, 2020

Thanks, late to the party here. Just want to point out that extending \Eloquent is not a good option. You generally don't want to have laravel-ide-helper a main dependency of your project. You'd generally add it as a dev dependency and only use _ide_helper.php (which also won't be autoloaded by default) to, you know, help your IDE out, not as a legitimate part of your application. Thus if you extend \Eloquent your code will break when it reaches production.

The addition of @mixin will also make the development of many new PHP libraries feel more open to using certain magic since there will be support on the 2 major editors (PHPStorm & VSCode), as well as obviously just making any existing use of magic in libraries easier to deal with in VSCode.

Also...

@mixin is not a standard annotation

PHPDoc doesn't even have a formal standardisation. PSR is/was working on it but I'm not sure whether to hold out hope for it. The draft doesn't even have @property-read yet! PHPDoc is informally standardised, so basically whatever large enough portions of the community forms somewhat of a consensus on, will probably make it into the standard, @mixin is as standard as it gets really.

@bmewburn
Copy link
Owner

Thus if you extend \Eloquent your code will break when it reaches production.

@Deji69 isn't Eloquent a default alias for Illuminate\Database\Eloquent\Model? Why would it break? No one is suggesting to include _ide_helper.php in executable code.

Screenshot from 2020-05-26 22-33-29

@blueo
Copy link

blueo commented Feb 16, 2021

For what it's worth the Silverstripe CMS also relies on @mixin for hinting/linting for runtime extensions and its the main reason my phpstorm friends make fun of me :P

@alielmajdaoui
Copy link

Replicating PHPDocs is annoying!
@bmewburn please we need @mixin support.

@tjventurini
Copy link

I guess we will need to do it on our own ... Did anyone look into the topic already? If anyone gathered some info on how to add an annotation please share it. Let's see if someone has a pull request for it until Monday 😉

@alielmajdaoui
Copy link

@tjventurini I am in if someone needs any collaboration!

@bmewburn
Copy link
Owner

implemented in 1.7

@benyaminl
Copy link

benyaminl commented Mar 21, 2021 via email

@flexchar
Copy link

Christmas came early guys!! The best message to wake up to!

@tjventurini
Copy link

🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳

@mgerasimchuk
Copy link

🎉 🎉 🎉

@neoighodaro
Copy link

Finally! Whoop whoop!

@bgrrtt
Copy link

bgrrtt commented Mar 21, 2021

THANK YOU!!!

@stotes
Copy link

stotes commented Mar 25, 2021

Awesome!!!! When do you expect to release 1.7?

@xiaohuilam
Copy link
Author

xiaohuilam commented Mar 26, 2021

Hope @bmewburn can do a pre-release~

the 1.7 milestone now only 14 percent, we are too difficult to wait.

@topex-psy
Copy link

topex-psy commented Apr 8, 2021

Is it just Laravel that needs this? With barryvdh/laravel-ide-helper ? Reason I haven't prioritised it is because @mixin is not a standard annotation and doesn't look like it will be standardised. I think it only gained some support back before PHP had traits.

no, CodeIgniter 4.1.1 need this too for the Controller's $request variable because it is now refer to @var RequestInterface, not directly to @var HTTP\IncomingRequest.

e.g. this code will error on getPost part:

$email = $this->request->getPost('email');

please fix it :(

@alielmajdaoui
Copy link

Hope @bmewburn can do a pre-release~

the 1.7 milestone now only 14 percent, we are too difficult to wait.

It's 96% now :D

@bmewburn bmewburn added the premium Premium feature accessible to licence key holders label Apr 26, 2021
@xiaohuilam
Copy link
Author

Guys~ Finnally th 1.7 was release! Just go to have a try!

But a sadness news is my favorite framework laravel, removed mixin from src/Illuminate/Database/Eloquent/Model.php.
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/Eloquent/Model.php#L24

@benyaminl
Copy link

benyaminl commented Apr 26, 2021

Guys~ Finnally th 1.7 was release! Just go to have a try!

But a sadness news is my favorite framework laravel, removed mixin from src/Illuminate/Database/Eloquent/Model.php.
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/Eloquent/Model.php#L24

So how we get around it? Still need Barry Package? What a joke :/

@bmewburn work so hard to implement it, and they removed it.. what...

@alielmajdaoui
Copy link

@xiaohuilam @benyaminl

You can @mixin whatever in your Models, where is the problem?

If Laravel deleted some @mixin from their eloquent Model.php, create a new one inside your Models folder, extend it from src/Illuminate/Database/Eloquent/Model.php and @mixin whatever you want. So in your existing Models, extend them from the new created model.

Example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model as EloquentModel;

/**
 * @mixin WHATEVER
 */
class Model extends EloquentModel {
}

Your existing models should be extending from App\Models\Model

<?php

namespace App\Models;

class Post extends Model {
...
}

@xiaohuilam
Copy link
Author

xiaohuilam commented Apr 26, 2021

Thanks to @alielmajdaoui,
I've already @mixin for my abstract baseModel class

<?php

namespace App\Models;

use App\Traits\SetTransformer;
use Illuminate\Database\Eloquent\Model;

/**
 * @mixin \Illuminate\Database\Query\Builder
 * @mixin \Illuminate\Database\Eloquent\Builder
 */
abstract class BaseModel extends Model
{
    use SetTransformer;
}

Because all my final models are extending from baseModel

<?php

namespace App\Models;

use App\Models\Relations\BelongsToUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Cert extends BaseModel
{
    use HasFactory;
    use BelongsToUser;
}

Seems that's the perfect solution for now.

@jhm-ciberman
Copy link

Sorry for commenting on this old issue, but I cannot get it 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.

@flexchar
Copy link

Have you tried re-indexing just in case? @jhm-ciberman

@piotrjoniec
Copy link

Sorry for commenting on this old issue, but I cannot get it 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 GIF

Any idea of what am I missing?

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

Do you have the premium license?

https://intelephense.com/

@jhm-ciberman
Copy link

Have you tried re-indexing just in case? @jhm-ciberman

@flexchar I just re-indexed and it still doesn't work.

Do you have the premium license?

https://intelephense.com/

@piotrjoniec Nope. But as far as I understand that feature should be under the "Code completion" category, and that is included in the non premium license.

@flexchar
Copy link

The premium licence is unfairly cheap so I'd totally suggest getting it. Make sure VS Code native PHP extension is off and check for the extension output to see for hints.

@jhm-ciberman
Copy link

I have the VSCode native PHP disabled:

image

The Intelephense output log doesn't seem to have any info:

[Info  - 3:33:19 PM] Initialising intelephense 1.10.2
[Info  - 3:33:19 PM] Initialised in 13 ms
[Info  - 3:33:19 PM] Environment changed. Refreshing 3 in memory documents.
[Info  - 3:33:19 PM] Searching file:///home/ciberman/.vscode-server/extensions/bmewburn.vscode-intelephense-client-1.10.2/node_modules/intelephense/lib/stub for files to index.
[Info  - 3:33:19 PM] Searching file:///home/ciberman/code/foo-web for files to index.
[Warn  - 3:33:20 PM] file:///home/ciberman/code/foo-web/vendor/fakerphp/faker/src/Faker/Provider/nl_BE/Text.php is over the maximum file size of 1000000 bytes.
[Info  - 3:33:20 PM] Indexing started.
[Info  - 3:33:32 PM] Indexing ended. 8467 files indexed in 11s.
[Info  - 3:33:32 PM] Writing state to /home/ciberman/.vscode-server/data/User/workspaceStorage/c94f15695b5c4df6f332414aed13122e/bmewburn.vscode-intelephense-client/1fb8f4f0.
[Info  - 3:33:33 PM] Wrote state in 0.9s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature premium Premium feature accessible to licence key holders
Projects
None yet
Development

No branches or pull requests