refactor: use FunctionLike Interface (#505)
parent
744062c14e
commit
1edbe35609
|
@ -415,7 +415,7 @@ class CompletionProvider
|
|||
|
||||
// Walk the AST upwards until a scope boundary is met
|
||||
$level = $node;
|
||||
while ($level && !ParserHelpers\isFunctionLike($level)) {
|
||||
while ($level && !($level instanceof PhpParser\FunctionLike)) {
|
||||
// Walk siblings before the node
|
||||
$sibling = $level;
|
||||
while ($sibling = $sibling->getPreviousSibling()) {
|
||||
|
@ -429,7 +429,7 @@ class CompletionProvider
|
|||
|
||||
// If the traversal ended because a function was met,
|
||||
// also add its parameters and closure uses to the result list
|
||||
if ($level && ParserHelpers\isFunctionLike($level) && $level->parameters !== null) {
|
||||
if ($level && $level instanceof PhpParser\FunctionLike && $level->parameters !== null) {
|
||||
foreach ($level->parameters->getValues() as $param) {
|
||||
$paramName = $param->getName();
|
||||
if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) {
|
||||
|
|
|
@ -509,7 +509,7 @@ class DefinitionResolver
|
|||
// Traverse the AST up
|
||||
do {
|
||||
// If a function is met, check the parameters and use statements
|
||||
if (ParserHelpers\isFunctionLike($n)) {
|
||||
if ($n instanceof PhpParser\FunctionLike) {
|
||||
if ($n->parameters !== null) {
|
||||
foreach ($n->parameters->getElements() as $param) {
|
||||
if ($param->getName() === $name) {
|
||||
|
@ -1018,7 +1018,7 @@ class DefinitionResolver
|
|||
// 1. doc block
|
||||
// 2. return type hint
|
||||
// 3. TODO: infer from return statements
|
||||
if (ParserHelpers\isFunctionLike($node)) {
|
||||
if ($node instanceof PhpParser\FunctionLike) {
|
||||
// Functions/methods
|
||||
$docBlock = $this->getDocBlock($node);
|
||||
if (
|
||||
|
|
|
@ -25,7 +25,7 @@ function isConstantFetch(Node $node) : bool
|
|||
$parent instanceof Node\Expression\CallExpression ||
|
||||
$parent instanceof Node\Expression\ObjectCreationExpression ||
|
||||
$parent instanceof Node\Expression\ScopedPropertyAccessExpression ||
|
||||
isFunctionLike($parent) ||
|
||||
$parent instanceof PhpParser\FunctionLike ||
|
||||
(
|
||||
$parent instanceof Node\Expression\BinaryExpression &&
|
||||
$parent->operator->kind === PhpParser\TokenKind::InstanceOfKeyword
|
||||
|
@ -38,14 +38,6 @@ function getFunctionLikeDeclarationFromParameter(Node\Parameter $node)
|
|||
return $node->parent->parent;
|
||||
}
|
||||
|
||||
function isFunctionLike(Node $node)
|
||||
{
|
||||
return
|
||||
$node instanceof Node\Statement\FunctionDeclaration ||
|
||||
$node instanceof Node\MethodDeclaration ||
|
||||
$node instanceof Node\Expression\AnonymousFunctionCreationExpression;
|
||||
}
|
||||
|
||||
function isBooleanExpression($expression) : bool
|
||||
{
|
||||
if (!($expression instanceof Node\Expression\BinaryExpression)) {
|
||||
|
|
|
@ -72,10 +72,10 @@ class TreeAnalyzer
|
|||
$range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->sourceFileNode->fileContents);
|
||||
|
||||
switch ($error->kind) {
|
||||
case \Microsoft\PhpParser\DiagnosticKind::Error:
|
||||
case PhpParser\DiagnosticKind::Error:
|
||||
$severity = DiagnosticSeverity::ERROR;
|
||||
break;
|
||||
case \Microsoft\PhpParser\DiagnosticKind::Warning:
|
||||
case PhpParser\DiagnosticKind::Warning:
|
||||
default:
|
||||
$severity = DiagnosticSeverity::WARNING;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue