-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
FunctionDeclarationIndexer.php
34 lines (29 loc) · 1.15 KB
/
FunctionDeclarationIndexer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Phpactor\Indexer\Adapter\Tolerant\Indexer;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\Node\Statement\FunctionDeclaration;
use Phpactor\Indexer\Adapter\Tolerant\TolerantIndexer;
use Phpactor\Indexer\Model\Index;
use Phpactor\TextDocument\ByteOffset;
use Phpactor\Indexer\Model\Record\FunctionRecord;
use Phpactor\TextDocument\TextDocument;
class FunctionDeclarationIndexer implements TolerantIndexer
{
public function canIndex(Node $node): bool
{
return $node instanceof FunctionDeclaration;
}
public function index(Index $index, TextDocument $document, Node $node): void
{
assert($node instanceof FunctionDeclaration);
$record = $index->get(FunctionRecord::fromName($node->getNamespacedName()->getFullyQualifiedNameText()));
assert($record instanceof FunctionRecord);
$record->setStart(ByteOffset::fromInt($node->getStartPosition()));
$record->setEnd(ByteOffset::fromInt($node->getEndPosition()));
$record->setFilePath($document->uriOrThrow());
$index->write($record);
}
public function beforeParse(Index $index, TextDocument $document): void
{
}
}