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

KeywordCompletor: complete statement keywords #2622

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

przepompownia
Copy link
Contributor

No description provided.

@mamazu
Copy link
Contributor

mamazu commented Mar 29, 2024

If you are already on that topic would mind also adding readonly as a keyword?

@przepompownia
Copy link
Contributor Author

I initially wanted to add more keywords (abstract and final too) here but they seem to need a separate attention, while this PR can already be reviewed and possibly merged.

In other words, let do it separately.

@dantleech
Copy link
Collaborator

dantleech commented Apr 6, 2024

in general I'm nervous about adding these completions as the mechanism for determining if they should be provided or not is not good vs. the effort of typing a few well known characters.

image

image

probably more instances where the keywords are either not provided or provided in the wrong place.

@przepompownia
Copy link
Contributor Author

przepompownia commented Apr 6, 2024

in general I'm nervous about adding these completions as the mechanism for determining if they should be provided or not is not good vs. the effort of typing a few well known characters.

probably more instances where the keywords are either not provided or provided in the wrong place.

I will try to look at these cases again.

I share your annoyance with such cases, but on the other hand, I'm even more bothered by the lack of completions in expected places. Habits of using lua-language-server raise my expectations here too.

@przepompownia
Copy link
Contributor Author

At the moment I reproduced only the second case (in real use) - the first does not work after a few guesses.

Comparing node string to `{` could worked because of parsing truncated document.
Note that in the `method empty body keyword` data set CompoundStatementNode is `{}`.
to the place where it's needed.
@przepompownia
Copy link
Contributor Author

image
This condition checks nodes on truncated document (up to cursor).

@przepompownia
Copy link
Contributor Author

if ($nodeBeforeOffset instanceof CompoundStatementNode && $node->getStartPosition() < $nodeBeforeOffset->getEndPosition()) {
return false;
}

I noticed that commenting the above condition does not affect any test result. Where it could be needed?

@przepompownia
Copy link
Contributor Author

przepompownia commented Apr 6, 2024

image

dap> $nodeBeforeOffset === $node->parent->parent
true

Isn't it a bug?

At the moment I still confused about borders of classMembersBody: should we expect true if $node is like in your example (and the new failing data set)?

@przepompownia
Copy link
Contributor Author

przepompownia commented Apr 17, 2024

Now I think we need a separate method in CompletionContext to determine whether the current node is in CompoundStatement within some method or function declaration.

@przepompownia przepompownia changed the title KeywordCompletor: complete return and yield KeywordCompletor: complete statement keywords Apr 17, 2024
@przepompownia
Copy link
Contributor Author

Now it seems to be ready to review again.

Some keywords like break, continue needs additional conditions. Maybe I'll do it here, as well as it can be done later.

instanceof seems to be more separate case. It follows expression and does not start any statement.

@przepompownia
Copy link
Contributor Author

in general I'm nervous about adding these completions as the mechanism for determining if they should be provided or not is not good vs. the effort of typing a few well known characters.

image

image

probably more instances where the keywords are either not provided or provided in the wrong place.

I tried to set better priority for keywords:

https://github.com/phpactor/phpactor/pull/2622/files#diff-2ba75b9069ec2e0eca8655a5fa214ecb0050bf8656e6c1842d2be83b91d31f27R136

@przepompownia
Copy link
Contributor Author

Experience with this PR shows that there can still exist lots of cases to consider to be statement context or not. Since implementing the new method in CompletionContext adding any next case became simple - especially not mixed with other contexts.

IMHO we could already merge this PR as is and possibly support new cases in the future. Before possible merge please report any annoying cases that I haven't found yet.

@przepompownia
Copy link
Contributor Author

In practice I merge this and other PRs to one experimental branch and see what happens (independently of tests). For example I found

image
image
image
image

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.

None yet

3 participants