You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also face the same issue, and in the first glance i feel that there is no check specifically to check the access modifiers. May be it is there which i couldn't understand. I am trying to implement this. If I complete will ask to merge.
Hi, I was checking this issue and I came up with a solution. I added this to the \LanguageServer\Definition class
/**
* 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;
}
Also, the \LanguageServer\CompletionProvider must be modified too.
Line: 245
// Collect all definitions that match any of the prefixes
foreach ($this->index->getDefinitions() as $fqn => $def) {
foreach ($prefixes as $prefix) {
if (substr($fqn, 0, strlen($prefix)) === $prefix &&
$def->isMember &&
$def->isVisible($prefix, $prefixes[0], $node)) {
$list->items[] = CompletionItem::fromDefinition($def);
}
}
}
Activity
duplicate-issues commentedon Aug 24, 2017
Hey @zodiark23,
We did a quick check and this issue looks very darn similar to
This could be a coincidence, but if any of these issues solves your problem then I did a good job 😄
If not, the maintainers will get to this issue shortly.
Cheers,
Your Friendly Neighborhood ProBot
raheelkhan commentedon Nov 13, 2017
I also face the same issue, and in the first glance i feel that there is no check specifically to check the access modifiers. May be it is there which i couldn't understand. I am trying to implement this. If I complete will ask to merge.
gnoe commentedon Nov 9, 2018
Hi, I was checking this issue and I came up with a solution. I added this to the \LanguageServer\Definition class
/**
* 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;
}
gnoe commentedon Nov 9, 2018
Also, the \LanguageServer\CompletionProvider must be modified too.
Line:
245
// Collect all definitions that match any of the prefixes
foreach ($this->index->getDefinitions() as $fqn => $def) {
foreach ($prefixes as $prefix) {
if (substr($fqn, 0, strlen($prefix)) === $prefix &&
$def->isMember &&
$def->isVisible($prefix, $prefixes[0], $node)) {
$list->items[] = CompletionItem::fromDefinition($def);
}
}
}
felixfbecker commentedon Nov 9, 2018
@gnoe want to submit a pull request? https://help.github.com/articles/creating-a-pull-request/
gnoe commentedon Nov 9, 2018
@felixfbecker, yes, I am going to do it!