From b03b7c1954435ed0fe2db587dab1efea2e17174f Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 7 Dec 2016 20:09:07 +0100 Subject: [PATCH] Improved version --- src/CompletionProvider.php | 43 ++++++++------------ tests/Server/TextDocument/CompletionTest.php | 12 ------ 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index 8676b9d..0338e35 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -132,34 +132,25 @@ class CompletionProvider || $node instanceof Node\Expr\StaticPropertyFetch || $node instanceof Node\Expr\ClassConstFetch ) { - if (!is_string($node->name)) { - // If the name is an Error node, just filter by the class - if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { - // For instances, resolve the variable type - $prefixes = DefinitionResolver::getFqnsFromType( - $this->definitionResolver->resolveExpressionNodeToType($node->var) - ); - } else { - $prefixes = [$node->class instanceof Node\Name ? (string)$node->class : '']; - } - // If we are just filtering by the class, add the appropiate operator to the prefix - // to filter the type of symbol - foreach ($prefixes as &$prefix) { - if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { - $prefix .= '->'; - } else if ($node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\ClassConstFetch) { - $prefix .= '::'; - } else if ($node instanceof Node\Expr\StaticPropertyFetch) { - $prefix .= '::$'; - } - } + // If the name is an Error node, just filter by the class + if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { + // For instances, resolve the variable type + $prefixes = DefinitionResolver::getFqnsFromType( + $this->definitionResolver->resolveExpressionNodeToType($node->var) + ); } else { - $prefix = $this->definitionResolver->resolveReferenceNodeToFqn($node); - $index = ($index = strpos($prefix, '->')) ? $index : strpos($prefix, '::'); - if ($index) { - $prefix = substr($prefix, 0, $index + 2); + $prefixes = [$node->class instanceof \PhpParser\Node\Name ? (string)$node->class : '']; + } + // If we are just filtering by the class, add the appropiate operator to the prefix + // to filter the type of symbol + foreach ($prefixes as &$prefix) { + if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { + $prefix .= '->'; + } else if ($node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\ClassConstFetch) { + $prefix .= '::'; + } else if ($node instanceof Node\Expr\StaticPropertyFetch) { + $prefix .= '::$'; } - $prefixes = $prefix !== null ? [$prefix] : []; } foreach ($this->project->getDefinitions() as $fqn => $def) { diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index 496374d..f32503c 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -200,12 +200,6 @@ class CompletionTest extends TestCase new Position(2, 14) )->wait(); $this->assertEquals(new CompletionList([ - new CompletionItem( - 'TEST_CLASS_CONST', - CompletionItemKind::VARIABLE, - 'int', - 'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.' - ), new CompletionItem( 'staticTestProperty', CompletionItemKind::PROPERTY, @@ -214,12 +208,6 @@ class CompletionTest extends TestCase null, null, '$staticTestProperty' - ), - new CompletionItem( - 'staticTestMethod', - CompletionItemKind::METHOD, - 'mixed', - 'Do magna consequat veniam minim proident eiusmod incididunt aute proident.' ) ], true), $items); }