feat(completion): exclude non-matching members after ::prefix and ->prefix
parent
0bc5b81561
commit
90cb77e924
|
@ -231,14 +231,15 @@ class CompletionProvider
|
||||||
$this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression)
|
$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)
|
// The FQNs of the symbol and its parents (eg the implemented interfaces)
|
||||||
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
|
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
|
||||||
// Add the object access operator to only get members of all parents
|
// Add the object access operator to only get members of all parents
|
||||||
$prefix = $parentFqn . '->';
|
$namespacedPrefix = $parentFqn . $prefix;
|
||||||
$prefixLen = strlen($prefix);
|
|
||||||
// Collect fqn definitions
|
// Collect fqn definitions
|
||||||
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
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);
|
$list->items[] = CompletionItem::fromDefinition($def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,6 +258,8 @@ class CompletionProvider
|
||||||
//
|
//
|
||||||
// TODO: $a::|
|
// TODO: $a::|
|
||||||
|
|
||||||
|
$prefix = '::' . ($scoped->memberName ? $scoped->memberName->getText($scoped->getFileContents()) : '');
|
||||||
|
|
||||||
// Resolve all possible types to FQNs
|
// Resolve all possible types to FQNs
|
||||||
$fqns = FqnUtilities\getFqnsFromType(
|
$fqns = FqnUtilities\getFqnsFromType(
|
||||||
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
|
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
|
||||||
|
@ -265,11 +268,10 @@ class CompletionProvider
|
||||||
// The FQNs of the symbol and its parents (eg the implemented interfaces)
|
// The FQNs of the symbol and its parents (eg the implemented interfaces)
|
||||||
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
|
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
|
||||||
// Append :: operator to only get static members of all parents
|
// Append :: operator to only get static members of all parents
|
||||||
$prefix = strtolower($parentFqn . '::');
|
$namespacedPrefix = $parentFqn . $prefix;
|
||||||
$prefixLen = strlen($prefix);
|
|
||||||
// Collect fqn definitions
|
// Collect fqn definitions
|
||||||
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
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);
|
$list->items[] = CompletionItem::fromDefinition($def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ class CompletionTest extends TestCase
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 13)
|
new Position(2, 13)
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'staticTestMethod',
|
'staticTestMethod',
|
||||||
CompletionItemKind::METHOD,
|
CompletionItemKind::METHOD,
|
||||||
|
@ -417,7 +417,7 @@ class CompletionTest extends TestCase
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 13)
|
new Position(2, 13)
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'TEST_CLASS_CONST',
|
'TEST_CLASS_CONST',
|
||||||
CompletionItemKind::VARIABLE,
|
CompletionItemKind::VARIABLE,
|
||||||
|
@ -902,42 +902,12 @@ class CompletionTest extends TestCase
|
||||||
new Position(12, 16)
|
new Position(12, 16)
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertEquals(new CompletionList([
|
$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(
|
new CompletionItem(
|
||||||
'method',
|
'method',
|
||||||
CompletionItemKind::METHOD,
|
CompletionItemKind::METHOD,
|
||||||
'mixed', // Return type of the method
|
'mixed', // Return type of the method
|
||||||
null
|
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);
|
], true), $items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -953,21 +923,11 @@ class CompletionTest extends TestCase
|
||||||
new Position(17, 23)
|
new Position(17, 23)
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
|
||||||
'bar',
|
|
||||||
CompletionItemKind::METHOD,
|
|
||||||
'mixed' // Return type of the method
|
|
||||||
),
|
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'qux',
|
'qux',
|
||||||
CompletionItemKind::METHOD,
|
CompletionItemKind::METHOD,
|
||||||
'mixed' // Return type of the method
|
'mixed' // Return type of the method
|
||||||
),
|
),
|
||||||
new CompletionItem(
|
|
||||||
'foo',
|
|
||||||
CompletionItemKind::METHOD,
|
|
||||||
'$this' // Return type of the method
|
|
||||||
),
|
|
||||||
], true), $items);
|
], true), $items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue