Skip to content

Commit 91ca99a

Browse files
committed
Revert "differenciate member and non member definitions"
This reverts commit 48bbbb5.
1 parent 67dd980 commit 91ca99a

File tree

5 files changed

+47
-105
lines changed

5 files changed

+47
-105
lines changed

src/CompletionProvider.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
221221
// The FQNs of the symbol and its parents (eg the implemented interfaces)
222222
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
223223
// Collect fqn definitions
224-
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn, true) as $fqn => $def) {
224+
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
225225
// Add the object access operator to only get members of all parents
226226
$prefix = $parentFqn . '->';
227-
if (substr($fqn, 0, strlen($prefix)) === $prefix) {
227+
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
228228
$list->items[] = CompletionItem::fromDefinition($def);
229229
}
230230
}
@@ -251,10 +251,10 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
251251
// The FQNs of the symbol and its parents (eg the implemented interfaces)
252252
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
253253
// Collect fqn definitions
254-
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn, true) as $fqn => $def) {
254+
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
255255
// Append :: operator to only get static members of all parents
256256
$prefix = strtolower($parentFqn . '::');
257-
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix) {
257+
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) {
258258
$list->items[] = CompletionItem::fromDefinition($def);
259259
}
260260
}
@@ -321,12 +321,14 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
321321
// Suggest global (ie non member) symbols that either
322322
// - start with the current namespace + prefix, if the Name node is not fully qualified
323323
// - start with just the prefix, if the Name node is fully qualified
324-
foreach ($this->index->getDefinitions(false) as $fqn => $def) {
324+
foreach ($this->index->getDefinitions() as $fqn => $def) {
325325

326326
$fqnStartsWithPrefix = substr($fqn, 0, $prefixLen) === $prefix;
327327

328328
if (
329-
(
329+
// Exclude methods, properties etc.
330+
!$def->isMember
331+
&& (
330332
!$prefix
331333
|| (
332334
// Either not qualified, but a matching prefix with global fallback

src/Index/AbstractAggregateIndex.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,25 @@ public function isStaticComplete(): bool
102102
* Returns a Generator providing an associative array [string => Definition]
103103
* that maps fully qualified symbol names to Definitions (global or not)
104104
*
105-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
106105
* @return \Generator yields Definition
107106
*/
108-
public function getDefinitions(bool $member = null): \Generator
107+
public function getDefinitions(): \Generator
109108
{
110109
foreach ($this->getIndexes() as $index) {
111-
yield from $index->getDefinitions($member);
110+
yield from $index->getDefinitions();
112111
}
113112
}
114113

115114
/**
116115
* Returns a Generator that yields all the descendant Definitions of a given FQN
117116
*
118117
* @param string $fqn
119-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
120118
* @return \Generator yields Definition
121119
*/
122-
public function getDescendantDefinitionsForFqn(string $fqn, bool $member = null): \Generator
120+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
123121
{
124122
foreach ($this->getIndexes() as $index) {
125-
yield from $index->getDescendantDefinitionsForFqn($fqn, $member);
123+
yield from $index->getDescendantDefinitionsForFqn($fqn);
126124
}
127125
}
128126

src/Index/Index.php

+17-74
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,21 @@ class Index implements ReadableIndex, \Serializable
1616

1717
/**
1818
* An associative array that maps splitted fully qualified symbol names
19-
* to non-member definitions, eg :
19+
* to definitions, eg :
2020
* [
2121
* 'Psr' => [
2222
* '\Log' => [
2323
* '\LoggerInterface' => [
24-
* '' => $definition,
24+
* '' => $def1, // definition for 'Psr\Log\LoggerInterface' which is non-member
25+
* '->log()' => $def2, // definition for 'Psr\Log\LoggerInterface->log()' which is a member definition
2526
* ],
2627
* ],
2728
* ],
2829
* ]
2930
*
3031
* @var array
3132
*/
32-
private $nonMemberDefinitions = [];
33-
34-
/**
35-
* An associative array that maps splitted fully qualified symbol names
36-
* to member definitions, eg :
37-
* [
38-
* 'Psr' => [
39-
* '\Log' => [
40-
* '\LoggerInterface' => [
41-
* '->log()' => $definition,
42-
* ],
43-
* ],
44-
* ],
45-
* ]
46-
*
47-
* @var array
48-
*/
49-
private $memberDefinitions = [];
33+
private $definitions = [];
5034

5135
/**
5236
* An associative array that maps fully qualified symbol names
@@ -115,29 +99,20 @@ public function isStaticComplete(): bool
11599
* Returns a Generator providing an associative array [string => Definition]
116100
* that maps fully qualified symbol names to Definitions (global or not)
117101
*
118-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
119102
* @return \Generator yields Definition
120103
*/
121-
public function getDefinitions(bool $member = null): \Generator
104+
public function getDefinitions(): \Generator
122105
{
123-
if (true === $member) {
124-
yield from $this->yieldDefinitionsRecursively($this->memberDefinitions);
125-
} elseif (false === $member) {
126-
yield from $this->yieldDefinitionsRecursively($this->nonMemberDefinitions);
127-
} else {
128-
yield from $this->yieldDefinitionsRecursively($this->memberDefinitions);
129-
yield from $this->yieldDefinitionsRecursively($this->nonMemberDefinitions);
130-
}
106+
yield from $this->yieldDefinitionsRecursively($this->definitions);
131107
}
132108

133109
/**
134110
* Returns a Generator that yields all the descendant Definitions of a given FQN
135111
*
136112
* @param string $fqn
137-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
138113
* @return \Generator yields Definition
139114
*/
140-
public function getDescendantDefinitionsForFqn(string $fqn, bool $member = null): \Generator
115+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
141116
{
142117
$parts = $this->splitFqn($fqn);
143118
if ('' === end($parts)) {
@@ -146,13 +121,12 @@ public function getDescendantDefinitionsForFqn(string $fqn, bool $member = null)
146121
array_pop($parts);
147122
}
148123

149-
if (true === $member) {
150-
yield from $this->doGetDescendantDefinitionsForFqn($fqn, $parts, $this->memberDefinitions);
151-
} elseif (false === $member) {
152-
yield from $this->doGetDescendantDefinitionsForFqn($fqn, $parts, $this->nonMemberDefinitions);
153-
} else {
154-
yield from $this->doGetDescendantDefinitionsForFqn($fqn, $parts, $this->memberDefinitions);
155-
yield from $this->doGetDescendantDefinitionsForFqn($fqn, $parts, $this->nonMemberDefinitions);
124+
$result = $this->getIndexValue($parts, $this->definitions);
125+
126+
if ($result instanceof Definition) {
127+
yield $fqn => $result;
128+
} elseif (is_array($result)) {
129+
yield from $this->yieldDefinitionsRecursively($result, $fqn);
156130
}
157131
}
158132

@@ -166,13 +140,8 @@ public function getDescendantDefinitionsForFqn(string $fqn, bool $member = null)
166140
public function getDefinition(string $fqn, bool $globalFallback = false)
167141
{
168142
$parts = $this->splitFqn($fqn);
143+
$result = $this->getIndexValue($parts, $this->definitions);
169144

170-
$result = $this->getIndexValue($parts, $this->memberDefinitions);
171-
if ($result instanceof Definition) {
172-
return $result;
173-
}
174-
175-
$result = $this->getIndexValue($parts, $this->nonMemberDefinitions);
176145
if ($result instanceof Definition) {
177146
return $result;
178147
}
@@ -195,12 +164,7 @@ public function getDefinition(string $fqn, bool $globalFallback = false)
195164
public function setDefinition(string $fqn, Definition $definition)
196165
{
197166
$parts = $this->splitFqn($fqn);
198-
199-
if ($definition->isMember) {
200-
$this->indexDefinition(0, $parts, $this->memberDefinitions, $definition);
201-
} else {
202-
$this->indexDefinition(0, $parts, $this->nonMemberDefinitions, $definition);
203-
}
167+
$this->indexDefinition(0, $parts, $this->definitions, $definition);
204168

205169
$this->emit('definition-added');
206170
}
@@ -215,8 +179,7 @@ public function setDefinition(string $fqn, Definition $definition)
215179
public function removeDefinition(string $fqn)
216180
{
217181
$parts = $this->splitFqn($fqn);
218-
$this->removeIndexedDefinition(0, $parts, $this->memberDefinitions, $this->memberDefinitions);
219-
$this->removeIndexedDefinition(0, $parts, $this->nonMemberDefinitions, $this->nonMemberDefinitions);
182+
$this->removeIndexedDefinition(0, $parts, $this->definitions, $this->definitions);
220183

221184
unset($this->references[$fqn]);
222185
}
@@ -316,26 +279,6 @@ public function serialize()
316279
]);
317280
}
318281

319-
/**
320-
* Returns a Generator that yields all the descendant Definitions of a given FQN
321-
* in the given definition index.
322-
*
323-
* @param string $fqn
324-
* @param string[] $parts The splitted FQN
325-
* @param array &$storage The definitions index to look into
326-
* @return \Generator yields Definition
327-
*/
328-
private function doGetDescendantDefinitionsForFqn(string $fqn, array $parts, array &$storage): \Generator
329-
{
330-
$result = $this->getIndexValue($parts, $storage);
331-
332-
if ($result instanceof Definition) {
333-
yield $fqn => $result;
334-
} elseif (is_array($result)) {
335-
yield from $this->yieldDefinitionsRecursively($result, $fqn);
336-
}
337-
}
338-
339282
/**
340283
* Returns a Generator that yields all the Definitions in the given $storage recursively.
341284
* The generator yields key => value pairs, e.g.
@@ -488,7 +431,7 @@ private function removeIndexedDefinition(int $level, array $parts, array &$stora
488431
$this->removeIndexedDefinition(0, array_slice($parts, 0, $level), $rootStorage, $rootStorage);
489432
}
490433
}
491-
} elseif (isset($storage[$part])) {
434+
} else {
492435
$this->removeIndexedDefinition($level + 1, $parts, $storage[$part], $rootStorage);
493436
}
494437
}

src/Index/ReadableIndex.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@ public function isStaticComplete(): bool;
3333
* Returns a Generator providing an associative array [string => Definition]
3434
* that maps fully qualified symbol names to Definitions (global or not)
3535
*
36-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
3736
* @return \Generator yields Definition
3837
*/
39-
public function getDefinitions(bool $member = null): \Generator;
38+
public function getDefinitions(): \Generator;
4039

4140
/**
4241
* Returns a Generator that yields all the descendant Definitions of a given FQN
4342
*
4443
* @param string $fqn
45-
* @param boolean|null $member Indicates if we want member or non-member definitions (null for both, default null)
4644
* @return \Generator yields Definition
4745
*/
48-
public function getDescendantDefinitionsForFqn(string $fqn, bool $member = null): \Generator;
46+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator;
4947

5048
/**
5149
* Returns the Definition object by a specific FQN

0 commit comments

Comments
 (0)