Allow getTypeFromNode() to take Variable nodes
parent
59670af7bd
commit
49b526d7e1
|
@ -85,16 +85,9 @@ class CompletionProvider
|
||||||
foreach ($this->suggestVariablesAtNode($node) as $var) {
|
foreach ($this->suggestVariablesAtNode($node) as $var) {
|
||||||
$item = new CompletionItem;
|
$item = new CompletionItem;
|
||||||
$item->kind = CompletionItemKind::VARIABLE;
|
$item->kind = CompletionItemKind::VARIABLE;
|
||||||
|
$item->label = '$' . ($var instanceof Node\Expr\ClosureUse ? $var->var : $var->name);
|
||||||
$item->documentation = $this->definitionResolver->getDocumentationFromNode($var);
|
$item->documentation = $this->definitionResolver->getDocumentationFromNode($var);
|
||||||
if ($var instanceof Node\Param) {
|
$item->detail = (string)$this->definitionResolver->getTypeFromNode($var);
|
||||||
$item->label = '$' . $var->name;
|
|
||||||
$item->detail = (string)$this->definitionResolver->getTypeFromNode($var); // TODO make it handle variables as well. Makes sense because needs to handle @var tag too!
|
|
||||||
} else if ($var instanceof Node\Expr\Variable || $var instanceof Node\Expr\ClosureUse) {
|
|
||||||
$item->label = '$' . ($var instanceof Node\Expr\ClosureUse ? $var->var : $var->name);
|
|
||||||
$item->detail = (string)$this->definitionResolver->resolveExpressionNodeToType($var->getAttribute('parentNode'));
|
|
||||||
} else {
|
|
||||||
throw new \LogicException;
|
|
||||||
}
|
|
||||||
$items[] = $item;
|
$items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,13 +113,8 @@ class DefinitionResolver
|
||||||
$def->declarationLine = $this->getDeclarationLineFromNode($defNode);
|
$def->declarationLine = $this->getDeclarationLineFromNode($defNode);
|
||||||
// Documentation
|
// Documentation
|
||||||
$def->documentation = $this->getDocumentationFromNode($defNode);
|
$def->documentation = $this->getDocumentationFromNode($defNode);
|
||||||
if ($defNode instanceof Node\Param) {
|
// Get type from docblock
|
||||||
// Get parameter type
|
$def->type = $this->getTypeFromNode($defNode);
|
||||||
$def->type = $this->getTypeFromNode($defNode);
|
|
||||||
} else {
|
|
||||||
// Resolve the type of the assignment/closure use node
|
|
||||||
$def->type = $this->resolveExpressionNodeToType($defNode);
|
|
||||||
}
|
|
||||||
return $def;
|
return $def;
|
||||||
}
|
}
|
||||||
// Other references are references to a global symbol that have an FQN
|
// Other references are references to a global symbol that have an FQN
|
||||||
|
@ -608,7 +603,7 @@ class DefinitionResolver
|
||||||
* For functions and methods, this is the return type.
|
* For functions and methods, this is the return type.
|
||||||
* For parameters, this is the type of the parameter.
|
* For parameters, this is the type of the parameter.
|
||||||
* For classes and interfaces, this is the class type (object).
|
* For classes and interfaces, this is the class type (object).
|
||||||
* Variables are not indexed for performance reasons.
|
* For variables / assignments, this is the documented type or type the assignment resolves to.
|
||||||
* Can also be a compound type.
|
* Can also be a compound type.
|
||||||
* If it is unknown, will be Types\Mixed.
|
* If it is unknown, will be Types\Mixed.
|
||||||
* Returns null if the node does not have a type.
|
* Returns null if the node does not have a type.
|
||||||
|
@ -666,16 +661,28 @@ class DefinitionResolver
|
||||||
// Unknown return type
|
// Unknown return type
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
}
|
}
|
||||||
if ($node instanceof Node\Stmt\PropertyProperty || $node instanceof Node\Const_) {
|
if ($node instanceof Node\Expr\Variable) {
|
||||||
// Property or constant
|
$node = $node->getAttribute('parentNode');
|
||||||
$docBlock = $node->getAttribute('parentNode')->getAttribute('docBlock');
|
}
|
||||||
|
if (
|
||||||
|
$node instanceof Node\Stmt\PropertyProperty
|
||||||
|
|| $node instanceof Node\Const_
|
||||||
|
|| $node instanceof Node\Expr\Assign
|
||||||
|
|| $node instanceof Node\Expr\AssignOp
|
||||||
|
) {
|
||||||
|
// Property, constant or variable
|
||||||
if (
|
if (
|
||||||
$docBlock !== null
|
($parent = $node->getAttribute('parentNode'))
|
||||||
|
&& ($docBlock = $parent->getAttribute('docBlock'))
|
||||||
&& !empty($varTags = $docBlock->getTagsByName('var'))
|
&& !empty($varTags = $docBlock->getTagsByName('var'))
|
||||||
&& $varTags[0]->getType()
|
&& ($type = $varTags[0]->getType())
|
||||||
) {
|
) {
|
||||||
// Use @var tag
|
// Use @var tag
|
||||||
return $varTags[0]->getType();
|
return $type;
|
||||||
|
}
|
||||||
|
if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignOp) {
|
||||||
|
// Resolve the expression
|
||||||
|
return $this->resolveExpressionNodeToType($node);
|
||||||
}
|
}
|
||||||
// TODO: read @property tags of class
|
// TODO: read @property tags of class
|
||||||
// TODO: Try to infer the type from default value / constant value
|
// TODO: Try to infer the type from default value / constant value
|
||||||
|
|
Loading…
Reference in New Issue