1
0
Fork 0

feat(completion): exclude non-matching members after ::prefix and ->prefix

pull/607/head
Declspeck 2018-02-24 16:11:00 +02:00
parent 0bc5b81561
commit 90cb77e924
No known key found for this signature in database
GPG Key ID: F0417663122A2189
2 changed files with 10 additions and 48 deletions

View File

@ -231,14 +231,15 @@ class CompletionProvider
$this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression)
);
$prefix = '->' . ($node->memberName ? $node->memberName->getText($node->getFileContents()) : '');
// The FQNs of the symbol and its parents (eg the implemented interfaces)
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
// Add the object access operator to only get members of all parents
$prefix = $parentFqn . '->';
$prefixLen = strlen($prefix);
$namespacedPrefix = $parentFqn . $prefix;
// Collect fqn definitions
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
if (substr($fqn, 0, $prefixLen) === $prefix && $def->isMember) {
if (nameStartsWith($fqn, $namespacedPrefix)) {
$list->items[] = CompletionItem::fromDefinition($def);
}
}
@ -257,6 +258,8 @@ class CompletionProvider
//
// TODO: $a::|
$prefix = '::' . ($scoped->memberName ? $scoped->memberName->getText($scoped->getFileContents()) : '');
// Resolve all possible types to FQNs
$fqns = FqnUtilities\getFqnsFromType(
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
@ -265,11 +268,10 @@ class CompletionProvider
// The FQNs of the symbol and its parents (eg the implemented interfaces)
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
// Append :: operator to only get static members of all parents
$prefix = strtolower($parentFqn . '::');
$prefixLen = strlen($prefix);
$namespacedPrefix = $parentFqn . $prefix;
// Collect fqn definitions
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
if (substr(strtolower($fqn), 0, $prefixLen) === $prefix && $def->isMember) {
if (nameStartsWith($fqn, $namespacedPrefix)) {
$list->items[] = CompletionItem::fromDefinition($def);
}
}

View File

@ -396,7 +396,7 @@ class CompletionTest extends TestCase
new TextDocumentIdentifier($completionUri),
new Position(2, 13)
)->wait();
$this->assertCompletionsListSubset(new CompletionList([
$this->assertEquals(new CompletionList([
new CompletionItem(
'staticTestMethod',
CompletionItemKind::METHOD,
@ -417,7 +417,7 @@ class CompletionTest extends TestCase
new TextDocumentIdentifier($completionUri),
new Position(2, 13)
)->wait();
$this->assertCompletionsListSubset(new CompletionList([
$this->assertEquals(new CompletionList([
new CompletionItem(
'TEST_CLASS_CONST',
CompletionItemKind::VARIABLE,
@ -902,42 +902,12 @@ class CompletionTest extends TestCase
new Position(12, 16)
)->wait();
$this->assertEquals(new CompletionList([
new CompletionItem(
'foo',
CompletionItemKind::PROPERTY,
'mixed', // Type of the property
null
),
new CompletionItem(
'bar',
CompletionItemKind::PROPERTY,
'mixed', // Type of the property
null
),
new CompletionItem(
'method',
CompletionItemKind::METHOD,
'mixed', // Return type of the method
null
),
new CompletionItem(
'test',
CompletionItemKind::METHOD,
'mixed', // Return type of the method
null
),
new CompletionItem(
'testProperty',
CompletionItemKind::PROPERTY,
'\TestClass', // Type of the property
'Reprehenderit magna velit mollit ipsum do.'
),
new CompletionItem(
'testMethod',
CompletionItemKind::METHOD,
'\TestClass', // Return type of the method
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
),
], true), $items);
}
@ -953,21 +923,11 @@ class CompletionTest extends TestCase
new Position(17, 23)
)->wait();
$this->assertEquals(new CompletionList([
new CompletionItem(
'bar',
CompletionItemKind::METHOD,
'mixed' // Return type of the method
),
new CompletionItem(
'qux',
CompletionItemKind::METHOD,
'mixed' // Return type of the method
),
new CompletionItem(
'foo',
CompletionItemKind::METHOD,
'$this' // Return type of the method
),
], true), $items);
}
}