-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Auto-completion not working for Enum instances #2284
Comments
I agree with the fact that enums are a little wonky in php. Technically you are right you shouldn't be able to configure non-static methods on an enum. But looks like you can in PHP so phpactor supports it. One thing to note here is that if you start the expression outside of the enum with ScheduleType:: Then this will only suggest static methods and ScheduleType-> will also include the non-static methods. This is thanks to php's "You can call static methods non-statically"-rule. I don't like it but phpactor implements it correctly.
And your second example If I missunderstood your point feel free to correct me. |
Ah interesting, that explains it---I wasn't too concerned about that part but just thought I'd mention it.
This is incorrect,
You can find example of using methods on enum cases in the docs |
Okay, that doesn't make sense that the enum values are objects again. (But that's just php.) Do you happen to know what type of object they are? They seem to have at least a |
It's all in the docs...
They're singleton instances of the Enum class. The docs also list some differences with objects:
Note that while Enums cannot have state (i.e., properties), they do have a
The |
We have a "todo" test for this:
i'll check to see if this can now be implemented |
should be working now |
Thanks!! Auto-complete is working for cases! However, (I hate to keep bugging lol) I noticed that I am not able to go to the definition of methods called on Enum cases---to reuse the earlier example: <?php
namespace Phpactor\Enums;
enum ScheduleType: int
{
case ProductionDay = 1;
case Break = 2;
case Unscheduled = 3;
public function label(): string
{
return match ($this) {
self::ProductionDay => 'Production Day',
default => $this->name,
};
}
}
class Test
{
public function testing(): void
{
$a = ScheduleType::ProductionDay->label(); // unable to goto `label` definition here
}
} |
Hello! Thanks for all the work getting traits to work in Enums!
However, I noticed that auto-completion for Enum properties and methods does not work outside of the Enum (and the auto-completion that does occur inside the Enum is incorrect). Note that Enums are stateless and therefore are unable to have properties, but all Enums have a
name
property and BackedEnums have avalue
property.Inside the Enum, auto-completion sort of works:
but it's not showing properties and it is showing static methods (
cases
,from
, etc.) which don't make sense on an Enum instance.Outside the Enum, there's no auto-completion suggestions from the LS.
Thanks!
The text was updated successfully, but these errors were encountered: