diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index 0548e49..f058bac 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -201,12 +201,12 @@ class CompletionProvider $this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression) ); - // The namespaces of the symbol and its parents (eg the implemented interfaces) - foreach ($this->expandParentFqns($fqns) as $namespace) { - // Collect namespaces definitions - foreach ($this->index->getDefinitionsForNamespace($namespace) as $fqn => $def) { + // The FQNs of the symbol and its parents (eg the implemented interfaces) + foreach ($this->expandParentFqns($fqns) as $parentFqn) { + // Collect fqn definitions + foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) { // Add the object access operator to only get members of all parents - $prefix = $namespace . '->'; + $prefix = $parentFqn . '->'; if (substr($fqn, 0, strlen($prefix)) === $prefix && !$def->isMember) { $list->items[] = CompletionItem::fromDefinition($def); } @@ -231,12 +231,12 @@ class CompletionProvider $classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier) ); - // The namespaces of the symbol and its parents (eg the implemented interfaces) - foreach ($this->expandParentFqns($fqns) as $namespace) { - // Collect namespaces definitions - foreach ($this->index->getDefinitionsForNamespace($namespace) as $fqn => $def) { + // The FQNs of the symbol and its parents (eg the implemented interfaces) + foreach ($this->expandParentFqns($fqns) as $parentFqn) { + // Collect fqn definitions + foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) { // Append :: operator to only get static members of all parents - $prefix = strtolower($namespace . '::'); + $prefix = strtolower($parentFqn . '::'); if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && !$def->isMember) { $list->items[] = CompletionItem::fromDefinition($def); } diff --git a/src/Index/AbstractAggregateIndex.php b/src/Index/AbstractAggregateIndex.php index 7ba3870..e4e33b3 100644 --- a/src/Index/AbstractAggregateIndex.php +++ b/src/Index/AbstractAggregateIndex.php @@ -129,16 +129,16 @@ abstract class AbstractAggregateIndex implements ReadableIndex } /** - * Returns a Generator providing the Definitions that are in the given namespace + * Returns a Generator providing the Definitions that are in the given FQN * - * @param string $namespace + * @param string $fqn * @return \Generator providing Definitions[] */ - public function getDefinitionsForNamespace(string $namespace): \Generator + public function getDefinitionsForFqn(string $fqn): \Generator { foreach ($this->getIndexes() as $index) { - foreach ($index->getDefinitionsForNamespace($namespace) as $fqn => $definition) { - yield $fqn => $definition; + foreach ($index->getDefinitionsForFqn($fqn) as $symbolFqn => $definition) { + yield $symbolFqn => $definition; } } } diff --git a/src/Index/Index.php b/src/Index/Index.php index 649ba29..bb1e6b4 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -15,7 +15,7 @@ class Index implements ReadableIndex, \Serializable use EmitterTrait; /** - * An associative array that maps namespaces to + * An associative array that maps fully qualified names to * an associative array that maps fully qualified symbol names * to global Definitions, e.g. : * [ @@ -27,7 +27,7 @@ class Index implements ReadableIndex, \Serializable * * @var array */ - private $namespaceDefinitions = []; + private $fqnDefinitions = []; /** * An associative array that maps fully qualified symbol names @@ -108,8 +108,8 @@ class Index implements ReadableIndex, \Serializable */ public function getDefinitions(): \Generator { - foreach ($this->namespaceDefinitions as $namespaceDefinition) { - foreach ($namespaceDefinition as $fqn => $definition) { + foreach ($this->fqnDefinitions as $fqnDefinition) { + foreach ($fqnDefinition as $fqn => $definition) { yield $fqn => $definition; } } @@ -129,15 +129,15 @@ class Index implements ReadableIndex, \Serializable } /** - * Returns a Generator providing the Definitions that are in the given namespace + * Returns a Generator providing the Definitions that are in the given FQN * - * @param string $namespace + * @param string $fqn * @return \Generator providing Definitions[] */ - public function getDefinitionsForNamespace(string $namespace): \Generator + public function getDefinitionsForFqn(string $fqn): \Generator { - foreach ($this->namespaceDefinitions[$namespace] ?? [] as $fqn => $definition) { - yield $fqn => $definition; + foreach ($this->fqnDefinitions[$fqn] ?? [] as $symbolFqn => $definition) { + yield $symbolFqn => $definition; } } @@ -150,8 +150,8 @@ class Index implements ReadableIndex, \Serializable */ public function getDefinition(string $fqn, bool $globalFallback = false) { - $namespace = $this->extractNamespace($fqn); - $definitions = $this->namespaceDefinitions[$namespace] ?? []; + $namespacedFqn = $this->extractNamespacedFqn($fqn); + $definitions = $this->fqnDefinitions[$namespacedFqn] ?? []; if (isset($definitions[$fqn])) { return $definitions[$fqn]; @@ -173,12 +173,12 @@ class Index implements ReadableIndex, \Serializable */ public function setDefinition(string $fqn, Definition $definition) { - $namespace = $this->extractNamespace($fqn); - if (!isset($this->namespaceDefinitions[$namespace])) { - $this->namespaceDefinitions[$namespace] = []; + $namespacedFqn = $this->extractNamespacedFqn($fqn); + if (!isset($this->fqnDefinitions[$namespacedFqn])) { + $this->fqnDefinitions[$namespacedFqn] = []; } - $this->namespaceDefinitions[$namespace][$fqn] = $definition; + $this->fqnDefinitions[$namespacedFqn][$fqn] = $definition; $this->setGlobalDefinition($fqn, $definition); $this->emit('definition-added'); } @@ -192,12 +192,12 @@ class Index implements ReadableIndex, \Serializable */ public function removeDefinition(string $fqn) { - $namespace = $this->extractNamespace($fqn); - if (isset($this->namespaceDefinitions[$namespace])) { - unset($this->namespaceDefinitions[$namespace][$fqn]); + $namespacedFqn = $this->extractNamespacedFqn($fqn); + if (isset($this->fqnDefinitions[$namespacedFqn])) { + unset($this->fqnDefinitions[$namespacedFqn][$fqn]); - if (empty($this->namespaceDefinitions[$namespace])) { - unset($this->namespaceDefinitions[$namespace]); + if (empty($this->fqnDefinitions[$namespacedFqn])) { + unset($this->fqnDefinitions[$namespacedFqn]); } } @@ -277,8 +277,8 @@ class Index implements ReadableIndex, \Serializable $this->$prop = $val; } - foreach ($this->namespaceDefinitions as $namespaceDefinition) { - foreach ($namespaceDefinition as $fqn => $definition) { + foreach ($this->fqnDefinitions as $fqnDefinition) { + foreach ($fqnDefinition as $fqn => $definition) { $this->setGlobalDefinition($fqn, $definition); } } @@ -291,7 +291,7 @@ class Index implements ReadableIndex, \Serializable public function serialize() { return serialize([ - 'namespaceDefinitions' => $this->namespaceDefinitions, + 'fqnDefinitions' => $this->fqnDefinitions, 'references' => $this->references, 'complete' => $this->complete, 'staticComplete' => $this->staticComplete @@ -313,10 +313,10 @@ class Index implements ReadableIndex, \Serializable } /** - * @param string $fqn - * @return string The namespace extracted from the given FQN + * @param string $fqn The symbol FQN + * @return string The namespaced FQN extracted from the given symbol FQN */ - private function extractNamespace(string $fqn): string + private function extractNamespacedFqn(string $fqn): string { foreach (['::', '->'] as $operator) { if (false !== ($pos = strpos($fqn, $operator))) { diff --git a/src/Index/ReadableIndex.php b/src/Index/ReadableIndex.php index 6e2b8c6..7d3750e 100644 --- a/src/Index/ReadableIndex.php +++ b/src/Index/ReadableIndex.php @@ -46,12 +46,12 @@ interface ReadableIndex extends EmitterInterface public function getGlobalDefinitions(): \Generator; /** - * Returns a Generator providing the Definitions that are in the given namespace + * Returns a Generator providing the Definitions that are in the given FQN * - * @param string $namespace + * @param string $fqn * @return \Generator providing Definitions[] */ - public function getDefinitionsForNamespace(string $namespace): \Generator; + public function getDefinitionsForFqn(string $fqn): \Generator; /** * Returns the Definition object by a specific FQN