Skip to content

Commit

Permalink
Expose code location raw line number
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 6, 2019
1 parent fc8d2bd commit 0051636
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/Psalm/CodeLocation.php
Expand Up @@ -27,7 +27,7 @@ class CodeLocation
public $file_name;

/** @var int */
protected $line_number;
public $raw_line_number;

/** @var int */
private $end_line_number = -1;
Expand Down Expand Up @@ -123,7 +123,7 @@ public function __construct(
$doc_comment = $stmt->getDocComment();
$this->preview_start = $doc_comment ? $doc_comment->getFilePos() : $this->file_start;
$this->docblock_start_line_number = $doc_comment ? $doc_comment->getLine() : null;
$this->line_number = $stmt->getLine();
$this->raw_line_number = $stmt->getLine();
}

/**
Expand Down Expand Up @@ -324,7 +324,7 @@ private function calculateRealLocation()
*/
public function getLineNumber()
{
return $this->docblock_line_number ?: $this->line_number;
return $this->docblock_line_number ?: $this->raw_line_number;
}

/**
Expand Down Expand Up @@ -409,4 +409,9 @@ public function getShortSummary() : string
{
return $this->file_name . ':' . $this->getLineNumber() . ':' . $this->getColumn();
}

public function getQuickSummary() : string
{
return $this->file_name . ':' . $this->raw_line_number;
}
}
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/DocblockTypeLocation.php
Expand Up @@ -25,6 +25,6 @@ public function __construct(
$this->single_line = false;

$this->preview_start = $this->file_start;
$this->line_number = $line_number;
$this->raw_line_number = $line_number;
}
}
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/ParseErrorLocation.php
Expand Up @@ -27,7 +27,7 @@ public function __construct(
$this->single_line = false;

$this->preview_start = $this->file_start;
$this->line_number = substr_count(
$this->raw_line_number = substr_count(
substr($file_contents, 0, $this->file_start),
"\n"
) + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/Raw.php
Expand Up @@ -26,7 +26,7 @@ public function __construct(
$this->single_line = false;

$this->preview_start = $this->file_start;
$this->line_number = substr_count(
$this->raw_line_number = substr_count(
substr($file_contents, 0, $this->file_start),
"\n"
) + 1;
Expand Down

0 comments on commit 0051636

Please sign in to comment.