Vscode-intelephense: not interprets @mixin annotations.

Created on 5 Aug 2018  ·  39Comments  ·  Source: bmewburn/vscode-intelephense

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;
enhancement

Most helpful comment

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.

All 39 comments

Same here!

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

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

Hey @bmewburn, did you forget this feature?

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

This will be wonderful for everything on PHP

Is it difficult to support @mixin? @bmewburn

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.

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.

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 )

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

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

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

I forgot to clarify. Eloquent isn't available on Lumen, so that's why I said no hope. Only eloquent file stub that you share to me can make the autocomplete work. If without that file stub even I use PHP artisan ide-helper:generate it won't add any facade for model and I still need to extend from Illuminate... Model

On October 8, 2019 5:27:52 PM GMT+07:00, Ben Mewburn notifications@github.com wrote:

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<br />
  21-27-11

--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/bmewburn/vscode-intelephense/issues/123#issuecomment-539452210

--
Sent from my ASUS Pegasus X005 with K-9 Mail.

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

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.

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.

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

Yeah. Just left phpstrom. It's not tpo great. I hate java memory management especially on windows. It sucks.

On October 16, 2019 5:22:11 PM GMT+07:00, zed notifications@github.com wrote:

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

--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/bmewburn/vscode-intelephense/issues/123#issuecomment-542634236

--
Sent from my ASUS Pegasus X005 with K-9 Mail.

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

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

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

@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

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.

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.

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

This issue has been opened since Feb 2019, and people clearly still want it. I think maybe we should close it if it's not coming. It's a shame but I think we are just arguing over if it should be or not and it's no longer constructive anymore in my opinion. Many people want it but also it does not seem like it would be implemented soon or ever.

Edit: Aug, 2018

Frankly, I think the last couple comments were discussing other things and
might have been mislead somewhere the way. The requested support for @mixin
does not include extra code execution. It is merely helping IDE to discover
methods. :)

@bmewburn I thought they were just facades within the Illuminate\Support\Facades namespace? If not that's news to me. Not sure how I feel about Laravel creating so many classes with common names in the global namespace.

This feature would be very helpful. I hope it will get added.

Hope to support @mixin soon

I wish we could bring Ben's @bmewburn attention on this again. I am back after summer holiday and this feature would greatly help remembering what all those real-time facades do :))

Yes. Even it need any fund raising, it deserve some fund if it's taking
some time. We're waiting 💪😎.

*anyway intelephense working good on VIM and Neovim with CoC.NVIM.haha..

Regards,
Benyamin Limanto
sent from my Sony XPERIA XZ Premium

On Wed, 26 Aug 2020, 13:56 Lukas Vanagas, notifications@github.com wrote:

I wish we could bring Ben's @bmewburn https://github.com/bmewburn
attention on this again. I am back after summer holiday and this feature
would greatly help remembering what all those real-time facades do :))


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/bmewburn/vscode-intelephense/issues/123#issuecomment-680696460,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAVP2NHL3LJL4GKQ2QSAXATSCSWYHANCNFSM4FN54DVQ
.

Gonna join the long list of supporters, this would be super helpful to make my life a tad easier and this extension even better.

This feature is also helpful for developing a trait that will be used with a specific class or their subclasses. For example, I'm currently developing a trait that can be used by Laravel's \Illuminate\Console\Command subclasses, and was hoping that I could autocomplete the properties and methods of $this inside the trait:

/**
 * @mixin \Illuminate\Console\Command
 */
trait SpecialCommand
{
    protected function specialHandle()
    {
        $requested = $this->option('table');

        // ...
    }
}

Being able to see the option method on the autocomplete would be greatly appreciated.

For Yii2 framework, it is also can be useful. Because of Yii2 has a system of behaviors, and models can look like this:

class UploadFileBehavior {
    public function getFileName() {
        ...
    }
}

/**
 * @mixin UploadFileBehavior
 */
class User extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            UploadFileBehavior::class,
        ];
    }

    public function getFileUrl() {
        return "https://example.com/static/" . $this->getFileName(); // getFileName() provides by UploadFileBehavior
    }
}

And also want to leave a link to the same issue in PHP Storm: https://youtrack.jetbrains.com/issue/WI-1730
And comment from core contributor of Yii2 team:

mixins are also supported by CakePhp, Symfony, Propel and Doctrine.

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 :+1: :wink:

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.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steven7mwesigwa picture steven7mwesigwa  ·  4Comments

nn-hh picture nn-hh  ·  3Comments

mushmelty picture mushmelty  ·  4Comments

swashata picture swashata  ·  3Comments

ghnp5 picture ghnp5  ·  3Comments