Skip to content

Commit

Permalink
GH-2603: Do not filter static method invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Apr 6, 2024
1 parent 43d5719 commit 1fd51c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Expand Up @@ -35,6 +35,13 @@ public function __construct(private TolerantCompletor $inner, private Reflector
public function complete(Node $node, TextDocument $source, ByteOffset $offset): Generator
{
$generator = $this->inner->complete($node, $source, $offset);
if (
!$node instanceof CallExpression &&
($node instanceof QualifiedName && !$node->parent instanceof ObjectCreationExpression)
) {
yield from $generator;
return $generator->getReturn();
}

$type = $this->resolveFilterableType($node, $source, $offset);
if (null === $type) {
Expand Down Expand Up @@ -77,6 +84,7 @@ private function resolveFilterableType(Node $node, TextDocument $source, ByteOff
{
$argumentNb = 0;
$memberAccessOrObjectCreation = $node;
$node = NodeUtil::firstDescendantNodeBeforeOffset($node, $offset->toInt());
if ($node instanceof QualifiedName) {
$memberAccessOrObjectCreation = null;
$argumentExpression = $node->getFirstAncestor(ArgumentExpression::class);
Expand All @@ -89,9 +97,10 @@ private function resolveFilterableType(Node $node, TextDocument $source, ByteOff
$memberAccessOrObjectCreation = $list->parent;
}
}
if ($node instanceof ArgumentExpressionList) {
$argumentNb = count(iterator_to_array($node->getValues()));
$memberAccessOrObjectCreation = $node->parent;
$argumentList = $node->getFirstAncestor(ArgumentExpressionList::class);
if ($argumentList instanceof ArgumentExpressionList) {
$argumentNb = max(0, count(iterator_to_array($argumentList->getValues())) - 1);
$memberAccessOrObjectCreation = $argumentList->parent;
}

if (!$memberAccessOrObjectCreation instanceof CallExpression && !$memberAccessOrObjectCreation instanceof ObjectCreationExpression) {
Expand All @@ -103,7 +112,6 @@ private function resolveFilterableType(Node $node, TextDocument $source, ByteOff
return null;
}
try {
;
$memberAccessOrObjectCreation = $this->reflector->reflectOffset($source, $offset)->nodeContext();
} catch (NotFound $e) {
return null;
Expand Down
Expand Up @@ -78,7 +78,7 @@ class Obj {}
class Foo { public function bar(Obj $obj){}}
$f = new Foo();
$f->bar(<>)
$f->bar(F<>)
EOT,
[
'Bar\Foo',
Expand All @@ -97,7 +97,7 @@ class Obj {}
class Foo { public function bar(Obj $obj){}}
$f = new Foo();
$f->bar(new <>
$f->bar(new <>)
EOT,
[
'Bar\Obj',
Expand All @@ -114,7 +114,7 @@ class Obj {}
class Foo { public function bar(Obj $obj){}}
$f = new Foo();
$f->bar(new <>
$f->bar(new <>)
EOT,
[
'Obj',
Expand Down Expand Up @@ -167,12 +167,13 @@ class Baz {}
class Foo { public function bar(Obj $obj, Baz $baz){}}
$f = new Foo();
$f->bar(Obj::new(),new <>
$f->bar(Obj::new(), new <>)
EOT,
[
'Baz',
],
];

yield '2nd arg partial' => [
[
'Obj',
Expand Down
4 changes: 0 additions & 4 deletions lib/Indexer/Model/IndexJob.php
Expand Up @@ -3,12 +3,8 @@
namespace Phpactor\Indexer\Model;

use Generator;
use Phar;
use PharFileInfo;
use Phpactor\TextDocument\TextDocumentBuilder;
use RecursiveIteratorIterator;
use SplFileInfo;
use UnexpectedValueException;

class IndexJob
{
Expand Down

0 comments on commit 1fd51c0

Please sign in to comment.