Skip to content

Commit

Permalink
Tweak hover indices to include the entire expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Ronde committed Dec 2, 2023
1 parent f59e562 commit 638e49f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions php/TreeFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function convertCharIndicesToPositions(array $fileDatas): array {

// Use binary search to find the line number efficiently
$findPos = static function (int $filePos) use ($lineOffsets) {
$line = self::binarySearch($lineOffsets, $filePos) - 1;
$line = self::binarySearch($lineOffsets, $filePos);
$lineStart = $lineOffsets[$line];
$char = $filePos - $lineStart;
return [
Expand All @@ -112,12 +112,16 @@ public static function convertCharIndicesToPositions(array $fileDatas): array {

foreach ($fileData as $nodeData) {
foreach ($nodeData as $datum) {
$endPos = $findPos($datum['pos']['end']);
$results[$filePath][] = [
'typeDescr' => $datum['typeDescr'],
'name' => $datum['name'],
'pos' => [
'start' => $findPos($datum['pos']['start']),
'end' => $findPos($datum['pos']['end'])
'end' => [
'line' => $endPos['line'],
'char' => $endPos['char']
]
]
];
}
Expand Down Expand Up @@ -284,8 +288,9 @@ private function processNodeWithType(Variable|PropertyFetch $node, Type $type):
'typeDescr' => $typeDescr,
'name' => $varName,
'pos' => [
'start' => $node->getStartFilePos(),
'end' => $node->getEndFilePos()
// Include `$` for variables
'start' => $node->getStartFilePos() - ($node instanceof Variable ? 1 : 0),
'end' => $node->getEndFilePos() + 1
]
];
}
Expand Down Expand Up @@ -315,7 +320,7 @@ protected function onClosure(ExprClosure|ArrowFunction $node, ParametersAcceptor
'name' => $parameter->getName(),
'pos' => [
'start' => $paramNode->getStartFilePos(),
'end' => $paramNode->getEndFilePos()
'end' => $paramNode->getEndFilePos() + 1
]
];
}
Expand Down Expand Up @@ -348,7 +353,7 @@ protected function onFunction(FunctionLike $node, PhpMethodFromParserNodeReflect
'name' => $parameter->getName(),
'pos' => [
'start' => $paramNode->getStartFilePos(),
'end' => $paramNode->getEndFilePos()
'end' => $paramNode->getEndFilePos() + 1
]
];
}
Expand Down

0 comments on commit 638e49f

Please sign in to comment.