Skip to content

fix(completion): magic method names displayed inside argument list#2815

Merged
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:fix-complete-magic-methods
Jan 4, 2025
Merged

fix(completion): magic method names displayed inside argument list#2815
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:fix-complete-magic-methods

Conversation

@przepompownia
Copy link
Contributor

No description provided.

@przepompownia
Copy link
Contributor Author

I fixed this bug at work on #2622 but it turns to be independent on that PR and can be fixed separately.

Screenshot From 2025-01-02 20-34-02

@mamazu
Copy link
Contributor

mamazu commented Jan 4, 2025

I've just checked it out and yes, it doesn't suggest magic methods anymore but it still suggests keywords.
image

I think the only valid suggestions that should be allowed here is type names (as we can't suggest variable names).

@przepompownia
Copy link
Contributor Author

I caught it when made the recent fix for #2622 and fixed (0250c05#diff-2ba75b9069ec2e0eca8655a5fa214ecb0050bf8656e6c1842d2be83b91d31f27R93) but still cannot reproduce it here.

@przepompownia
Copy link
Contributor Author

That fix assumes that these two words make no sense inside StatementNode.

Even if we found test data for that, let keep this PR as small as possible and fix that separately - I keep #2795 (comment) in mind.

@mamazu
Copy link
Contributor

mamazu commented Jan 4, 2025

Yes, it's already better than before and I think this should be merged.

But in this case it doesn't make sense to have a StatementNode in the parameter definition. Maybe an ExpressionNode for default values.

@dantleech dantleech merged commit b5c1c52 into phpactor:master Jan 4, 2025
10 checks passed
@przepompownia przepompownia deleted the fix-complete-magic-methods branch January 4, 2025 18:04
@przepompownia
Copy link
Contributor Author

Thank you! I'll try to extract the function|const case fix too, assuming I'll have a reproducible test case.

@dantleech
Copy link
Collaborator

Note that this is all very unstable, adding one thing may break another as it's all just working around the parser being bad at invalid ASTs

@przepompownia
Copy link
Contributor Author

More, the logic needed to recognize the current context needs to be a bit hacky - at least I have no better ideas than some of uses in #2622

That's why we need more and more test cases.

return false;
}

if ($node->parent instanceof MethodDeclaration && $node->openBrace instanceof MissingToken) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this causes lots of warnings:

[ERROR][2025-01-27 09:45:46] .../vim/lsp/rpc.lua:770	"rpc"	"/home/daniel/.local/bin/phpactor"	"stderr"	"Warning: Undefined property: Microsoft\\PhpParser\\Node\\DelimitedList\\ParameterDeclarationList::$openBrace in /home/daniel/www/phpactor/phpactor/lib/Completion/Bridge/TolerantParser/CompletionContext.php on line 184\n"
[ERROR][2025-01-27 09:45:56] .../vim/lsp/rpc.lua:770	"rpc"	"/home/daniel/.local/bin/phpactor"	"stderr"	"Warning: Undefined property: Microsoft\\PhpParser\\Node\\DelimitedList\\ParameterDeclarationList::$openBrace in /home/daniel/www/phpactor/phpactor/lib/Completion/Bridge/TolerantParser/CompletionContext.php on line 184\n"
[ERROR][2025-01-27 09:45:56] .../vim/lsp/rpc.lua:770	"rpc"	"/home/daniel/.local/bin/phpactor"	"stderr"	"Warning: Undefined property: Microsoft\\PhpParser\\Node\\DelimitedList\\ParameterDeclarationList::$openBrace in /home/daniel/www/phpactor/phpactor/lib/Completion/Bridge/TolerantParser/CompletionContext.php on line 184\n"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#2832 should precise the type of $node in that case.

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.

3 participants