Skip to content

Commit 3d8d743

Browse files
committed
take starting line into account
1 parent 549db83 commit 3d8d743

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/Parsers/InlineHtmlParser.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Parser\Settings;
99
use Microsoft\PhpParser\Node\Statement\InlineHtml;
1010
use Microsoft\PhpParser\Parser;
11+
use Microsoft\PhpParser\PositionUtilities;
1112
use Microsoft\PhpParser\Range;
1213
use Stillat\BladeParser\Document\Document;
1314
use Stillat\BladeParser\Nodes\BaseNode;
@@ -24,6 +25,8 @@ class InlineHtmlParser extends AbstractParser
2425
'{{' => '}}',
2526
];
2627

28+
protected $startLine = 0;
29+
2730
/**
2831
* @var Blade
2932
*/
@@ -33,6 +36,16 @@ class InlineHtmlParser extends AbstractParser
3336

3437
public function parse(InlineHtml $node)
3538
{
39+
if ($node->getStartPosition() > 0) {
40+
$range = PositionUtilities::getRangeFromPosition(
41+
$node->getStartPosition(),
42+
mb_strlen($node->getText()),
43+
$node->getRoot()->getFullText(),
44+
);
45+
46+
$this->startLine = $range->start->line;
47+
}
48+
3649
$this->parseBladeContent(Document::fromText($node->getText()));
3750

3851
if (count($this->items)) {
@@ -81,8 +94,8 @@ protected function doEchoParse(BaseNode $node, $prefix, $content)
8194
$range->end->character += mb_strlen($suffix);
8295
}
8396

84-
$range->start->line += $node->position->startLine - 2;
85-
$range->end->line += $node->position->startLine - 2;
97+
$range->start->line += $this->startLine + $node->position->startLine - 2;
98+
$range->end->line += $this->startLine + $node->position->startLine - 2;
8699

87100
return $range;
88101
};
@@ -127,8 +140,8 @@ protected function parseBladeDirective(DirectiveNode $node)
127140
$range->end->character -= mb_strlen($safetyPrefix) - 1;
128141
}
129142

130-
$range->start->line += $node->position->startLine - 2;
131-
$range->end->line += $node->position->startLine - 2;
143+
$range->start->line += $this->startLine + $node->position->startLine - 2;
144+
$range->end->line += $this->startLine + $node->position->startLine - 2;
132145

133146
return $range;
134147
};

0 commit comments

Comments
 (0)