Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Commit

Permalink
WorseNamedParameterCompletor: ignored when completing a variable (#59)
Browse files Browse the repository at this point in the history
* WorseNamedParameterCompletor: ignored when completing a variable

I often find myself in the situation where a function/method's parameter
name match the name of a local variable I want to provide as argument.

In this situation the completion results include the named parameter
which can be anoying depending on the sort done by the client side.

I think it's sane to not include named parameters when we already
started to type a variable name, our little `$` in php will finally pay
off :)

* phpstan: fix error in the CI
  • Loading branch information
camilledejoye authored Sep 20, 2021
1 parent e4486dc commit f2a2320
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Microsoft\PhpParser\Node\Expression\MemberAccessExpression;
use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;
use Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression;
use Microsoft\PhpParser\Node\Expression\Variable;
use Microsoft\PhpParser\Node\QualifiedName;
use Phpactor\Completion\Bridge\TolerantParser\TolerantCompletor;
use Phpactor\Completion\Bridge\TolerantParser\Helper\NodeQuery;
Expand Down Expand Up @@ -58,6 +59,10 @@ public function complete(Node $node, TextDocument $source, ByteOffset $offset):
return true;
}

if ($node instanceof Variable) {
return true;
}

if ($creation instanceof ObjectCreationExpression) {
return yield from $this->fromObjectCreation($creation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function priority(?TextDocumentUri $one, ?TextDocumentUri $two): int

$range = Suggestion::PRIORITY_LOW - Suggestion::PRIORITY_MEDIUM;

return Suggestion::PRIORITY_MEDIUM + $range - $range * $similarity;
return (int) (Suggestion::PRIORITY_MEDIUM + $range - $range * $similarity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public function provideComplete(): Generator
]
];

yield 'Ignore when completing a variable' => [
'<?php class A{function bee(string $one){}} $a = new A(); $a->bee($o<>',
[
]
];

yield 'Method call in partial method call' => [
'<?php class B {function boo(): B{}}' .
'class A{function bee(string $one){}} $b=new B();$a=new A(); $a->bee($b->boo()-><>',
Expand Down

0 comments on commit f2a2320

Please sign in to comment.