Add support for constants with define()
parent
c479969758
commit
d8b0858166
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue