1
0
Fork 0

Add support for constants with define()

define-constants
Felix Becker 2016-10-14 01:10:44 +02:00
parent c479969758
commit d8b0858166
2 changed files with 23 additions and 6 deletions

View File

@ -326,6 +326,11 @@ class PhpDocument
} }
return (string)$class->namespacedName . '::' . $node->name; return (string)$class->namespacedName . '::' . $node->name;
} }
} else if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && (string)$node->name === 'define') {
if (!isset($node->args[0]) || !($node->args[0]->value instanceof Node\Scalar\String_)) {
return null;
}
return (string)$node->args[0]->value->value;
} }
} }

View File

@ -58,13 +58,25 @@ class SymbolInformation
Node\Stmt\PropertyProperty::class => SymbolKind::PROPERTY, Node\Stmt\PropertyProperty::class => SymbolKind::PROPERTY,
Node\Const_::class => SymbolKind::CONSTANT Node\Const_::class => SymbolKind::CONSTANT
]; ];
$symbol = new self;
if (
$node instanceof Node\Expr\FuncCall
&& $node->name instanceof Node\Name
&& (string)$node->name === 'define'
&& isset($node->args[0])
&& $node->args[0]->value instanceof Node\Scalar\String_
) {
// define() constant
$symbol->kind = SymbolKind::CONSTANT;
$symbol->name = (string)$node->args[0]->value->value;
} else {
$class = get_class($node); $class = get_class($node);
if (!isset($nodeSymbolKindMap[$class])) { if (!isset($nodeSymbolKindMap[$class])) {
throw new Exception("Not a declaration node: $class"); throw new Exception("Not a declaration node: $class");
} }
$symbol = new self;
$symbol->kind = $nodeSymbolKindMap[$class]; $symbol->kind = $nodeSymbolKindMap[$class];
$symbol->name = (string)$node->name; $symbol->name = (string)$node->name;
}
$symbol->location = Location::fromNode($node); $symbol->location = Location::fromNode($node);
if ($fqn !== null) { if ($fqn !== null) {
$parts = preg_split('/(::|\\\\)/', $fqn); $parts = preg_split('/(::|\\\\)/', $fqn);