diff --git a/fixtures/constant-with-namespace.php b/fixtures/constant-with-namespace.php new file mode 100644 index 0000000..b91b6e7 --- /dev/null +++ b/fixtures/constant-with-namespace.php @@ -0,0 +1,22 @@ +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; + } } } diff --git a/src/Protocol/SymbolInformation.php b/src/Protocol/SymbolInformation.php index 5d442f0..c98d075 100644 --- a/src/Protocol/SymbolInformation.php +++ b/src/Protocol/SymbolInformation.php @@ -50,13 +50,9 @@ class SymbolInformation { $parent = $node->getAttribute('parentNode'); $symbol = new self; - if ($node instanceof Node\Stmt\Class_) { + if ($node instanceof Node\Stmt\Class_|| $node instanceof Node\Stmt\Trait_) { $symbol->kind = SymbolKind::CLASS_; - } else if ($node instanceof Node\Stmt\Trait_) { - $symbol->kind = SymbolKind::CLASS_; - } else if ($node instanceof Node\Stmt\Interface_) { - $symbol->kind = SymbolKind::INTERFACE; - } else if ($node instanceof Node\Name && $parent instanceof Node\Stmt\Namespace_) { + } else if ($node instanceof Node\Stmt\Interface_ || ($node instanceof Node\Name && $parent instanceof Node\Stmt\Namespace_)) { $symbol->kind = SymbolKind::NAMESPACE; } else if ($node instanceof Node\Stmt\Function_) { $symbol->kind = SymbolKind::FUNCTION; @@ -86,6 +82,17 @@ class SymbolInformation $symbol->name = $node->var; } else if (isset($node->name)) { $symbol->name = (string)$node->name; + } else 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_ + ) { + // constants with define() + $symbol->kind = SymbolKind::CONSTANT; + $symbol->name = (string)$node->args[0]->value->value; } else { return null; }