vscode-intelephense
vscode-intelephense copied to clipboard
Mixin not autocompleting trait properties.
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:

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

Platform and version OS and Intelephense 1.7.1 Premium
@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?
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.
@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 justuse
it?
Don't let pride and prejudice blind your eyes!
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
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