1
0
Fork 0

Improved version

pull/207/head
Michal Niewrzal 2016-12-07 20:09:07 +01:00
parent 9124b52904
commit b03b7c1954
2 changed files with 17 additions and 38 deletions

View File

@ -132,34 +132,25 @@ class CompletionProvider
|| $node instanceof Node\Expr\StaticPropertyFetch || $node instanceof Node\Expr\StaticPropertyFetch
|| $node instanceof Node\Expr\ClassConstFetch || $node instanceof Node\Expr\ClassConstFetch
) { ) {
if (!is_string($node->name)) { // If the name is an Error node, just filter by the class
// If the name is an Error node, just filter by the class if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) {
if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { // For instances, resolve the variable type
// For instances, resolve the variable type $prefixes = DefinitionResolver::getFqnsFromType(
$prefixes = DefinitionResolver::getFqnsFromType( $this->definitionResolver->resolveExpressionNodeToType($node->var)
$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 .= '::$';
}
}
} else { } else {
$prefix = $this->definitionResolver->resolveReferenceNodeToFqn($node); $prefixes = [$node->class instanceof \PhpParser\Node\Name ? (string)$node->class : ''];
$index = ($index = strpos($prefix, '->')) ? $index : strpos($prefix, '::'); }
if ($index) { // If we are just filtering by the class, add the appropiate operator to the prefix
$prefix = substr($prefix, 0, $index + 2); // 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) { foreach ($this->project->getDefinitions() as $fqn => $def) {

View File

@ -200,12 +200,6 @@ class CompletionTest extends TestCase
new Position(2, 14) new Position(2, 14)
)->wait(); )->wait();
$this->assertEquals(new CompletionList([ $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( new CompletionItem(
'staticTestProperty', 'staticTestProperty',
CompletionItemKind::PROPERTY, CompletionItemKind::PROPERTY,
@ -214,12 +208,6 @@ class CompletionTest extends TestCase
null, null,
null, null,
'$staticTestProperty' '$staticTestProperty'
),
new CompletionItem(
'staticTestMethod',
CompletionItemKind::METHOD,
'mixed',
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
) )
], true), $items); ], true), $items);
} }