Skip to content

Commit d1f85f1

Browse files
committed
use tree representation index
1 parent e9fd572 commit d1f85f1

File tree

4 files changed

+244
-125
lines changed

4 files changed

+244
-125
lines changed

src/CompletionProvider.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function provideCompletion(PhpDocument $doc, Position $pos): CompletionLi
207207
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) {
208208
// Add the object access operator to only get members of all parents
209209
$prefix = $parentFqn . '->';
210-
if (substr($fqn, 0, strlen($prefix)) === $prefix && !$def->isMember) {
210+
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
211211
$list->items[] = CompletionItem::fromDefinition($def);
212212
}
213213
}
@@ -237,7 +237,7 @@ public function provideCompletion(PhpDocument $doc, Position $pos): CompletionLi
237237
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) {
238238
// Append :: operator to only get static members of all parents
239239
$prefix = strtolower($parentFqn . '::');
240-
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && !$def->isMember) {
240+
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) {
241241
$list->items[] = CompletionItem::fromDefinition($def);
242242
}
243243
}
@@ -301,25 +301,29 @@ public function provideCompletion(PhpDocument $doc, Position $pos): CompletionLi
301301
}
302302
}
303303

304-
// Suggest global symbols that either
304+
// Suggest global (ie non member) symbols that either
305305
// - start with the current namespace + prefix, if the Name node is not fully qualified
306306
// - start with just the prefix, if the Name node is fully qualified
307-
foreach ($this->index->getGlobalDefinitions() as $fqn => $def) {
307+
foreach ($this->index->getDefinitions() as $fqn => $def) {
308308

309309
$fqnStartsWithPrefix = substr($fqn, 0, $prefixLen) === $prefix;
310310

311311
if (
312-
!$prefix
313-
|| (
314-
// Either not qualified, but a matching prefix with global fallback
315-
($def->roamed && !$isQualified && $fqnStartsWithPrefix)
316-
// Or not in a namespace or a fully qualified name or AND matching the prefix
317-
|| ((!$namespaceNode || $isFullyQualified) && $fqnStartsWithPrefix)
318-
// Or in a namespace, not fully qualified and matching the prefix + current namespace
312+
// Exclude methods, properties etc.
313+
!$def->isMember
314+
&& (
315+
!$prefix
319316
|| (
320-
$namespaceNode
321-
&& !$isFullyQualified
322-
&& substr($fqn, 0, $namespacedPrefixLen) === $namespacedPrefix
317+
// Either not qualified, but a matching prefix with global fallback
318+
($def->roamed && !$isQualified && $fqnStartsWithPrefix)
319+
// Or not in a namespace or a fully qualified name or AND matching the prefix
320+
|| ((!$namespaceNode || $isFullyQualified) && $fqnStartsWithPrefix)
321+
// Or in a namespace, not fully qualified and matching the prefix + current namespace
322+
|| (
323+
$namespaceNode
324+
&& !$isFullyQualified
325+
&& substr($fqn, 0, $namespacedPrefixLen) === $namespacedPrefix
326+
)
323327
)
324328
)
325329
// Only suggest classes for `new`

src/Index/AbstractAggregateIndex.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,11 @@ public function isStaticComplete(): bool
107107
public function getDefinitions(): \Generator
108108
{
109109
foreach ($this->getIndexes() as $index) {
110-
foreach ($index->getDefinitions() as $fqn => $definitions) {
111-
yield $fqn => $definition;
112-
}
113-
}
114-
}
110+
// foreach ($index->getDefinitions() as $fqn => $definition) {
111+
// yield $fqn => $definition;
112+
// }
115113

116-
/**
117-
* Returns a Generator providing an associative array [string => Definition]
118-
* that maps fully qualified symbol names to global Definitions
119-
*
120-
* @return \Generator providing Definitions[]
121-
*/
122-
public function getGlobalDefinitions(): \Generator
123-
{
124-
foreach ($this->getIndexes() as $index) {
125-
foreach ($index->getGlobalDefinitions() as $fqn => $definition) {
126-
yield $fqn => $definition;
127-
}
114+
yield from $index->getDefinitions();
128115
}
129116
}
130117

@@ -137,9 +124,11 @@ public function getGlobalDefinitions(): \Generator
137124
public function getDefinitionsForFqn(string $fqn): \Generator
138125
{
139126
foreach ($this->getIndexes() as $index) {
140-
foreach ($index->getDefinitionsForFqn($fqn) as $symbolFqn => $definition) {
141-
yield $symbolFqn => $definition;
142-
}
127+
// foreach ($index->getDefinitionsForFqn($fqn) as $symbolFqn => $definition) {
128+
// yield $symbolFqn => $definition;
129+
// }
130+
131+
yield from $index->getDefinitionsForFqn($fqn);
143132
}
144133
}
145134

@@ -168,9 +157,11 @@ public function getDefinition(string $fqn, bool $globalFallback = false)
168157
public function getReferenceUris(string $fqn): \Generator
169158
{
170159
foreach ($this->getIndexes() as $index) {
171-
foreach ($index->getReferenceUris($fqn) as $uri) {
172-
yield $uri;
173-
}
160+
// foreach ($index->getReferenceUris($fqn) as $uri) {
161+
// yield $uri;
162+
// }
163+
164+
yield from $index->getReferenceUris($fqn);
174165
}
175166
}
176167
}

0 commit comments

Comments
 (0)