Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,35 @@ public function __construct(SourceCodeReflector $reflector, Parser $parser = nul

public function find(TextDocument $source, ByteOffset $offset): ByteOffset
{
if ($interestingOffset = $this->resolveInterestingOffset($source, $offset)) {
return $interestingOffset;
}

$node = $this->parser->parseSourceFile($source->__toString())->getDescendantNodeAtPosition($offset->toInt());

do {
$reflectionOffset = $this->reflector->reflectOffset($source, $node->getStart());

$symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType();
$offset = ByteOffset::fromInt($node->getStart());

if ($symbolType !== Symbol::UNKNOWN) {
return ByteOffset::fromInt($node->getStart());
if ($interestingOffset = $this->resolveInterestingOffset($source, $offset)) {
return $interestingOffset;
}

$node = $node->parent;
} while ($node);

return $offset;
}

private function resolveInterestingOffset(TextDocument $source, ByteOffset $offset): ?ByteOffset
{
$reflectionOffset = $this->reflector->reflectOffset($source, $offset->toInt());

$symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType();

if ($symbolType !== Symbol::UNKNOWN) {
return $offset;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,30 @@ public function methodOne()
<>
}
}
EOT
, Symbol::METHOD,
];

yield 'offset in method call' => [
<<<'EOT'
<?php

class Foobar
{
public function methodOne()
{
$this->ba<>r();
}

private function bar()
{
}
}
EOT
, Symbol::METHOD,
];


yield 'offset on var' => [
<<<'EOT'
<?php
Expand All @@ -114,7 +134,7 @@ class Foobar
{
public function methodOne()
{
$foo = $bar + 3 / 2 <>+ $foo;
$foo = $bar + 3 / 2 + $<>foo;
}
}
EOT
Expand Down