Skip to content

Renamed getStart => getStartPosition for consistency. #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function getNodeKindName() : string {
* @return int
* @throws \Exception
*/
public function getStart() : int {
public function getStartPosition() : int {
$child = $this->getChildNodesAndTokens()->current();
if ($child instanceof Node) {
return $child->getStart();
return $child->getStartPosition();
} elseif ($child instanceof Token) {
return $child->start;
}
Expand Down Expand Up @@ -285,7 +285,7 @@ public function getChildNames() {
* @return int
*/
public function getWidth() : int {
$first = $this->getStart();
$first = $this->getStartPosition();
$last = $this->getEndPosition();

return $last - $first;
Expand All @@ -308,7 +308,7 @@ public function getFullWidth() : int {
* @return string
*/
public function getText() : string {
$start = $this->getStart();
$start = $this->getStartPosition();
$end = $this->getEndPosition();

$fileContents = $this->getFileContents();
Expand Down Expand Up @@ -354,7 +354,7 @@ public function jsonSerialize() {
}

/**
* Get the end index of a Node.
* Get the end position of a Node.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index (=offset) is more precise than position. Position can also mean (line, column).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method uses the term Position. Maybe we should change the API to get[Start|End]Offset?

Copy link
Member

@roblourens roblourens Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about this, 'position' is not ideal because the language server protocol uses it for line/col and the parser also has LineCharacterPosition. There are a ton of references to 'position' so it would be a pain to change, but either index or offset would be better for this.

* @return int
* @throws \Exception
*/
Expand Down Expand Up @@ -417,7 +417,7 @@ public function getDescendantNodeAtPosition(int $pos) {
* @return bool
*/
private function containsPosition(int $pos): bool {
return $this->getStart() <= $pos && $pos <= $this->getEndPosition();
return $this->getStartPosition() <= $pos && $pos <= $this->getEndPosition();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Node/QualifiedName.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function isUnqualifiedName() : bool {
*/
public function getResolvedName($namespaceDefinition = null) {
// Name resolution not applicable to constructs that define symbol names or aliases.
if (($this->parent instanceof Node\Statement\NamespaceDefinition && $this->parent->name->getStart() === $this->getStart()) ||
if (($this->parent instanceof Node\Statement\NamespaceDefinition && $this->parent->name->getStartPosition() === $this->getStartPosition()) ||
$this->parent instanceof Node\Statement\NamespaceUseDeclaration ||
$this->parent instanceof Node\NamespaceUseClause ||
$this->parent instanceof Node\NamespaceUseGroupClause ||
Expand Down