mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Shift all comments, not just docblocks
This commit is contained in:
parent
addaea2c1c
commit
dbb155f18d
@ -57,9 +57,9 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
|
||||
{
|
||||
$attrs = $node->getAttributes();
|
||||
|
||||
if ($c = $node->getDocComment()) {
|
||||
if ($cs = $node->getComments()) {
|
||||
/** @var int */
|
||||
$stmt_start_pos = $c->getFilePos();
|
||||
$stmt_start_pos = $cs[0]->getFilePos();
|
||||
} else {
|
||||
/** @var int */
|
||||
$stmt_start_pos = $attrs['startFilePos'];
|
||||
@ -229,14 +229,26 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
|
||||
|
||||
if ($start_offset !== 0 || $end_offset !== 0 || $line_offset !== 0) {
|
||||
if ($start_offset !== 0) {
|
||||
if ($c) {
|
||||
$node->setDocComment(
|
||||
new PhpParser\Comment\Doc(
|
||||
$c->getText(),
|
||||
$c->getLine() + $line_offset,
|
||||
$c->getFilePos() + $start_offset
|
||||
)
|
||||
);
|
||||
if ($cs) {
|
||||
$new_comments = [];
|
||||
|
||||
foreach ($cs as $c) {
|
||||
if ($c instanceof PhpParser\Comment\Doc) {
|
||||
$new_comments[] = new PhpParser\Comment\Doc(
|
||||
$c->getText(),
|
||||
$c->getLine() + $line_offset,
|
||||
$c->getFilePos() + $start_offset
|
||||
);
|
||||
} else {
|
||||
$new_comments[] = new PhpParser\Comment(
|
||||
$c->getText(),
|
||||
$c->getLine() + $line_offset,
|
||||
$c->getFilePos() + $start_offset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$node->setAttribute('comments', $new_comments);
|
||||
|
||||
/** @psalm-suppress MixedOperand */
|
||||
$node->setAttribute('startFilePos', $attrs['startFilePos'] + $start_offset);
|
||||
|
@ -27,14 +27,26 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract implements PhpP
|
||||
{
|
||||
$attrs = $node->getAttributes();
|
||||
|
||||
if ($c = $node->getDocComment()) {
|
||||
$node->setDocComment(
|
||||
new PhpParser\Comment\Doc(
|
||||
$c->getText(),
|
||||
$c->getLine() + $this->line_offset,
|
||||
$c->getFilePos() + $this->file_offset
|
||||
)
|
||||
);
|
||||
if ($cs = $node->getComments()) {
|
||||
$new_comments = [];
|
||||
|
||||
foreach ($cs as $c) {
|
||||
if ($c instanceof PhpParser\Comment\Doc) {
|
||||
$new_comments[] = new PhpParser\Comment\Doc(
|
||||
$c->getText(),
|
||||
$c->getLine() + $this->line_offset,
|
||||
$c->getFilePos() + $this->file_offset
|
||||
);
|
||||
} else {
|
||||
$new_comments[] = new PhpParser\Comment(
|
||||
$c->getText(),
|
||||
$c->getLine() + $this->line_offset,
|
||||
$c->getFilePos() + $this->file_offset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$node->setAttribute('comments', $new_comments);
|
||||
}
|
||||
|
||||
/** @psalm-suppress MixedOperand */
|
||||
|
Loading…
Reference in New Issue
Block a user