Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

Commit 9fc33a4

Browse files
committed
Take constants into account in import name
Validate constants but do not offer the possiblity to import them yet.
1 parent 35c2564 commit 9fc33a4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/LanguageServerCodeTransform/CodeAction/ImportNameProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Phpactor\Extension\LanguageServerBridge\Converter\PositionConverter;
99
use Phpactor\Extension\LanguageServerCodeTransform\LspCommand\ImportNameCommand;
1010
use Phpactor\Indexer\Model\Query\Criteria;
11+
use Phpactor\Indexer\Model\Record;
12+
use Phpactor\Indexer\Model\Record\ConstantRecord;
1113
use Phpactor\Indexer\Model\Record\HasFullyQualifiedName;
1214
use Phpactor\Indexer\Model\SearchClient;
1315
use Phpactor\LanguageServerProtocol\CodeAction;
@@ -150,6 +152,15 @@ private function diagnosticsFromUnresolvedName(NameWithByteOffset $unresolvedNam
150152
];
151153
}
152154

155+
// Remove constants for now
156+
$candidates = array_filter($candidates, function (Record $record) {
157+
return !$record instanceof ConstantRecord;
158+
});
159+
160+
if (count($candidates) === 0) {
161+
return [];
162+
}
163+
153164
return [
154165
new Diagnostic(
155166
$range,
@@ -170,6 +181,7 @@ private function findCandidates(NameWithByteOffset $unresolvedName): array
170181
$candidates = [];
171182
foreach ($this->client->search(Criteria::and(
172183
Criteria::or(
184+
Criteria::isConstant(),
173185
Criteria::isClass(),
174186
Criteria::isFunction()
175187
),

0 commit comments

Comments
 (0)