[PR] Intellisense autocomplete also suggests private or protected method and properties
Checking the visibility and the context from where the node is: inside a method declaration or after an instantiationpull/681/head
parent
18c6ccd137
commit
5835bd314b
|
@ -246,8 +246,10 @@ class CompletionProvider
|
||||||
// Collect all definitions that match any of the prefixes
|
// Collect all definitions that match any of the prefixes
|
||||||
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
||||||
foreach ($prefixes as $prefix) {
|
foreach ($prefixes as $prefix) {
|
||||||
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
|
if (substr($fqn, 0, strlen($prefix)) === $prefix &&
|
||||||
$list->items[] = CompletionItemFactory::fromDefinition($def);
|
$def->isMember &&
|
||||||
|
$def->isVisible($prefix, $prefixes[0], $node)) {
|
||||||
|
$list->items[] = CompletionItem::fromDefinition($def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,4 +133,33 @@ class Definition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the definition's visibility.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isVisible(string $match, string $caller, \Microsoft\PhpParser\Node $node): bool
|
||||||
|
{
|
||||||
|
$ancestor = $node->getFirstAncestor(\Microsoft\PhpParser\Node\MethodDeclaration::class);
|
||||||
|
|
||||||
|
if ($ancestor) {
|
||||||
|
if ($match !== $caller && $this->isPrivate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ($this->isProtected() || $this->isPrivate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isPrivate(): bool
|
||||||
|
{
|
||||||
|
return 'private' === substr($this->declarationLine, 0, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isProtected(): bool
|
||||||
|
{
|
||||||
|
return 'protected' === substr($this->declarationLine, 0, 9);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue