1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix issue adjusting offsets after multiple file changes

This commit is contained in:
Brown 2018-10-26 13:22:41 -04:00
parent 89e91f6ae2
commit 303d3ee6a2
2 changed files with 66 additions and 1 deletions

View File

@ -109,6 +109,14 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
$start_offset = $b_s2 - $a_s2;
}
if ($a_e2 < $stmt_start_pos) {
$start_offset = $end_offset;
$line_offset = $line_diff;
continue;
}
if ($a_s2 >= $stmt_start_pos && $a_e2 <= $stmt_end_pos) {
$this->non_method_changes--;
}
@ -139,6 +147,14 @@ class OffsetMapCheckerVisitor extends PhpParser\NodeVisitorAbstract implements P
|| !$replacement_stmts[0] instanceof PhpParser\Node\Stmt\ClassLike
|| count($replacement_stmts[0]->stmts) > 1
) {
if ($replacement_stmts
&& $replacement_stmts[0] instanceof PhpParser\Node\Stmt\ClassLike
&& count($replacement_stmts[0]->stmts) > 1
) {
$this->must_rescan = true;
return PhpParser\NodeTraverser::STOP_TRAVERSAL;
}
$hacky_class_fix = preg_replace('/(\)[\s]*):([\s]*\{)/', '$1 $2', $fake_class);
/** @var array<PhpParser\Node\Stmt> */

View File

@ -160,7 +160,7 @@ class FileDiffTest extends TestCase
if ($a_doc = $a_stmt->getDocComment()) {
$b_doc = $b_stmt->getDocComment();
$this->assertNotNull($b_doc);
$this->assertNotNull($b_doc, var_export($a_doc, true));
if (!$b_doc) {
throw new \UnexpectedValueException('');
@ -1246,6 +1246,55 @@ class FileDiffTest extends TestCase
['bar\foo::b'],
[[229, 8]]
],
'removeStatementsAbove' => [
'<?php
namespace A;
class B
{
/**
* @return void
*/
public static function foo() {
echo 4;
echo 5;
}
/**
* @return void
*/
public static function bar() {
echo 4;
echo 5;
}
}',
'<?php
namespace A;
class B
{
/**
* @return void
*/
public static function foo() {
echo 5;
}
/**
* @return void
*/
public static function bar() {
echo 5;
}
}',
[],
[
'a\b::foo',
'a\b::bar',
],
[],
[]
],
];
}
}