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

Complete inside class constant declaration #1985

Conversation

przepompownia
Copy link
Contributor

@przepompownia przepompownia commented Dec 9, 2022

Closes #1978

@przepompownia
Copy link
Contributor Author

I'm not sure if it's the correct logic but first tests suggest that it works.

'<?php class Foobar { private const FOO; private const BAR = self::F<> }', [
[
'type' => Suggestion::TYPE_CONSTANT,
'name' => 'self::FOO',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the expectation is correct.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you suspect it not to be correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the first I started with name => 'FOO' - the whole 'self::FOO' caught my attention.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yeah that doesn't seem quite right, did you test it in the editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,

complete-in-class-declaration.mp4

but I found that the new test case checks something that works already on master 😁 so I need to add the proper case before refactoring discussed in the other comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is an artificial suggestion:

image

@@ -42,6 +43,10 @@ public static function expression(?Node $node): bool
return false;
}

if ($parent instanceof ConstElement) {
Copy link
Collaborator

@dantleech dantleech Dec 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we can move this to the similar expressions in the final return below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is it triggered by classMembersBody somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final return is unavailable in this case because of classMembersBody:
image

Maybe moving the new condition into classMembersBody() would be good idea but

  • I need to ensure if we expect true if the parent of $node is ConstElement
  • it's public and used in other places so we need to inspect what will happen then (with the hope that existing tests tests cover enough amount of cases first).

@przepompownia
Copy link
Contributor Author

It's still not what I need:
image

@dantleech
Copy link
Collaborator

What are you missing ?

@przepompownia
Copy link
Contributor Author

Note that it does not work inside array. I need some free time to fix it again.

@dantleech
Copy link
Collaborator

it's a mine field, good luck!

@przepompownia
Copy link
Contributor Author

complete-in-class-declaration-2.mp4

Now it's time to return to the question where $parent instanceof ConstElement should be placed. Including this condition in classMembersBody requires repeat the query again in expression().

@dantleech
Copy link
Collaborator

I think it's fine, its not a "query" but just an instanceof and it's true, it's not a direct child of the class members _bod but we should complete expressions on ConstElements.

I've just spent the past 30m trying to stop function and const being completed:

image

but I think we can merge this in it's current state as an improvement?

@przepompownia
Copy link
Contributor Author

przepompownia commented Dec 10, 2022

I agree that at the moment almost accurate suggestion list is better than none and we could merge this PR.

Independently it would be good to keep in master PHPUnit test cases that fails (but should/could pass, like that shown by you on the picture below) but marked to exclude them with --exclude-group (or using XML configuration, see https://phpunit.readthedocs.io/en/9.5/annotations.html#group) by CI. What do you think about such approach?

@dantleech dantleech merged commit 057c443 into phpactor:master Dec 23, 2022
@dantleech
Copy link
Collaborator

thanks,I updated the changelog and changed the test to simulate something more realistic...

@przepompownia przepompownia deleted the complete-inside-class-constant-declaration branch December 26, 2022 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Class completion does not work inside a constant value
2 participants