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 · 58 comments
Closed

not interprets @mixin annotations. #123

xiaohuilam opened this issue Aug 5, 2018 · 58 comments
Labels
enhancement premium
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

andreshg112 commented Oct 30, 2018

Same here!

@xiaohuilam
Copy link
Author

xiaohuilam commented Feb 26, 2019

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

@nmsmith22389
Copy link

nmsmith22389 commented May 27, 2019

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

@xiaohuilam
Copy link
Author

xiaohuilam commented Aug 24, 2019

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

star2000 commented Sep 11, 2019

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

xiaohuilam 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.

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

xiaohuilam commented Oct 6, 2019

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

@xiaohuilam
Copy link
Author

xiaohuilam commented Oct 12, 2019

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

benyaminl commented Oct 12, 2019

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

bmewburn commented Oct 12, 2019

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

zedisdog commented Oct 16, 2019

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

@benyaminl
Copy link

benyaminl commented Oct 16, 2019

@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

neoighodaro commented Jan 26, 2020

@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

WilliamStam commented Apr 12, 2020

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

bmewburn commented May 26, 2020

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

@tjventurini
Copy link

tjventurini commented Nov 25, 2020

That's like the main feature I'm still missing in vscode/intelephense since I moved from phpstorm. Sad that is somewhat refused ... but my hope dies last. I hope that the devs will keep up with the expectations of their supporters 👍 😉

@piotrjoniec
Copy link

piotrjoniec commented Dec 19, 2020

Any updates on this? @mixin is widely used by many frameworks including Laravel. Most of the time, you can't get complete code suggestions without this feature. I'd think that having complete and accurate suggestions should have top priority in an extension like this.

@gm-lunatix
Copy link

gm-lunatix commented Jan 15, 2021

Just in to support the feature request. Would love to see @mixin support, and then I'd buy a license.

@cognitus
Copy link

cognitus commented Jan 20, 2021

Any updates on this? @mixin is widely used by many frameworks including Laravel. Most of the time, you can't get complete code suggestions without this feature. I'd think that having complete and accurate suggestions should have top priority in an extension like this.

yes! is really annoying must change every model and create a facade for get this extension working... the ideal is this extension works out of the box

I hope @bmewburn put some attention on this

@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

alielmajdaoui commented Feb 17, 2021

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

@tjventurini
Copy link

tjventurini commented Mar 4, 2021

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

alielmajdaoui commented Mar 4, 2021

@tjventurini I am in if someone needs any collaboration!

@bmewburn
Copy link
Owner

bmewburn commented Mar 21, 2021

implemented in 1.7

@benyaminl
Copy link

benyaminl commented Mar 21, 2021

@flexchar
Copy link

flexchar commented Mar 21, 2021

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

@tjventurini
Copy link

tjventurini commented Mar 21, 2021

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

@mgerasimchuk
Copy link

mgerasimchuk commented Mar 21, 2021

🎉 🎉 🎉

@neoighodaro
Copy link

neoighodaro commented Mar 21, 2021

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

alielmajdaoui commented Apr 14, 2021

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 label Apr 26, 2021
@xiaohuilam
Copy link
Author

xiaohuilam 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

@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

alielmajdaoui commented Apr 26, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement premium
Projects
None yet
Development

No branches or pull requests