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

Update highlighter to be aware of use statements #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/LanguageServerReferenceFinder/Model/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression;
use Microsoft\PhpParser\Node\Expression\Variable;
use Microsoft\PhpParser\Node\MethodDeclaration;
use Microsoft\PhpParser\Node\NamespaceUseClause;
use Microsoft\PhpParser\Node\Parameter;
use Microsoft\PhpParser\Node\PropertyDeclaration;
use Microsoft\PhpParser\Node\QualifiedName;
Expand Down Expand Up @@ -258,6 +259,15 @@ private function constants(SourceFileNode $rootNode, string $name): Generator
private function namespacedNames(Node $rootNode, string $fullyQualfiiedName): Generator
{
foreach ($rootNode->getDescendantNodes() as $node) {
if ($node instanceof NamespaceUseClause && $node->namespaceName instanceof QualifiedName && (string)$node->namespaceName === $fullyQualfiiedName) {
yield new DocumentHighlight(
new Range(
PositionConverter::intByteOffsetToPosition($node->namespaceName->getStart(), $node->getFileContents()),
PositionConverter::intByteOffsetToPosition($node->namespaceName->getEndPosition(), $node->getFileContents())
),
DocumentHighlightKind::TEXT
);
}
if ($node instanceof ClassDeclaration && (string)$node->getNamespacedName() === $fullyQualfiiedName) {
yield new DocumentHighlight(
new Range(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ function (Highlights $highlights) {
self::assertEquals(DocumentHighlightKind::TEXT, $highlights->at(0)->kind);
}
];

yield 'class name and use statement' => [
'<?php use Barfoo\Foobar; new Foo<>bar()',
function (Highlights $highlights) {
self::assertCount(2, $highlights);
self::assertEquals(DocumentHighlightKind::TEXT, $highlights->at(0)->kind);
}
];

yield 'class name and multiple use statements' => [
<<<'EOT'
<?php
use Bartoo\Barf;
use Barfoo\Foobar;
use BazBar;

new Foo<>bar()
EOT
,
function (Highlights $highlights) {
self::assertCount(2, $highlights);
self::assertEquals(DocumentHighlightKind::TEXT, $highlights->at(0)->kind);
}
];
}

/**
Expand Down