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

Mixin not autocompleting trait properties.

Open myleshyson opened this issue 3 years ago • 5 comments

Describe the bug @mixin doesn't autocomplete properties on traits, just methods. I'm using premium as well.

Using Craft CMS and they somewhat recently refactored their service container, living in Craft::$app, like so.

//Craft.php

/**
 * Craft is helper class serving common Craft and Yii framework functionality.
 * It encapsulates [[Yii]] and ultimately [[yii\BaseYii]], which provides the actual implementation.
 *
 * @mixin CraftTrait
 * @author Pixel & Tonic, Inc. <[email protected]>
 * @since 3.0.0
 */
class Craft extends Yii
{
    //...stuff
}

//CraftTrait.php
/**
 * Helps with IDE auto-completion.
 *
 * @author Pixel & Tonic, Inc. <[email protected]>
 * @since 3.5.12.1
 */
trait CraftTrait
{
    /**
     * @var \craft\web\Application|\craft\console\Application
     */
    public static $app;
}

The problem is that intelephese doesn't seem to autocomplete the $app property on the trait class even though the Craft class defines @mixin for that trait. Since all of Craft's functionality essentially lives through that one trait property, it would be nice if intelephense also picked up trait properties.

Expected behavior In this case, typing Craft::$app-> would autocomplete methods and properties for \craft\web\Application|\craft\console\Application.

Screenshots What currently happens:

Screen Shot 2021-11-17 at 10 28 40 AM

What it should look like (got this by manually adding @property \craft\web\Application|\craft\console\Application $app on the Craft class):

Screen Shot 2021-11-17 at 10 31 04 AM

Platform and version OS and Intelephense 1.7.1 Premium

myleshyson avatar Nov 17 '21 15:11 myleshyson

@mixin might be getting limited to mixing in classes only here. This seems like a really strange use of @mixin which from my understanding was a way to mimic traits before they were a thing. If it's a trait then why not just use it?

bmewburn avatar Nov 20 '21 03:11 bmewburn

Yea I think it's a Yii2 thing and the way Yii initializes that $app variable as basically a service container. Some php magic is happening for that $app variable to show up on the Craft class with Craft specific stuff.

Opened this up though because in PHPStorm this indexes as expected and I was hoping the same thing would be possible in VS Code via intelephense. Is it possible to support traits as well for '@mixin', however weird this use case is? It would help out us Craft Cms developers a ton in VS Code.

myleshyson avatar Dec 01 '21 20:12 myleshyson

@mixin might be getting limited to mixing in classes only here. This seems like a really strange use of @mixin which from my understanding was a way to mimic traits before they were a thing. If it's a trait then why not just use it?

Don't let pride and prejudice blind your eyes!

lip8up avatar Apr 01 '22 08:04 lip8up

Many package use @mixin for doc, if intelephense support it, I can use vscode development of PHP and buy a license vscode remote development is convenience

qa2080639 avatar Jun 21 '22 09:06 qa2080639

A class has some logic separated into "concerns" (traits), which contain constants. VSC will get confused in one of those traits if you're trying to use static::SOME_CONSTANT that exists in another sibling trait! And this is a perfect case for @mixin where you'd use it to convey that those ARE in fact sibling traits that should be applied on their class...

Is this really not that much needed?

trait A
{
    public const SOMETHING = [1, 2];
}

/** @mixin A */
trait B
{
    public const ANOTHER = [3, 4];

    public function getConstants(): array
    {
        return array_merge(static::SOMETHING, static::ANOTHER); // VSC still complains!
    }
}

class X
{
    use A;
    use B;
}

To be fair, the example above isn't that convincing, so here's a real one:

  • Main class: https://github.com/VPremiss/Arabicable/blob/main/src/Arabic.php
  • Concern 1: https://github.com/VPremiss/Arabicable/blob/main/src/Support/Concerns/HandlesPunctuation.php
  • Concern 2: https://github.com/VPremiss/Arabicable/blob/main/src/Support/Concerns/HandlesSpaces.php

Notice how in HandlesSpaces method validateForTextSpacing, we need to rely on those constants from HandlesPunctuation and Intelephense doesn't help using @mixin doc-block.

Is this a "strange" case? And if so, how would it be organized better, if I may? @bmewburn

GoodM4ven avatar Apr 30 '24 04:04 GoodM4ven