diff --git a/app/Contexts/Variable.php b/app/Contexts/Variable.php new file mode 100644 index 0000000..2988512 --- /dev/null +++ b/app/Contexts/Variable.php @@ -0,0 +1,24 @@ + $this->name, + ]; + } +} diff --git a/app/Parser/Walker.php b/app/Parser/Walker.php index d2c2f5f..06a9d8f 100644 --- a/app/Parser/Walker.php +++ b/app/Parser/Walker.php @@ -49,9 +49,20 @@ protected function documentSkipsClosingQuote() return false; } + protected function documentSkipsObjectOperator(): bool + { + if (count($this->sourceFile->statementList) === 1 && $this->sourceFile->statementList[0] instanceof InlineHtml) { + $lastChars = substr($this->sourceFile->getFullText(), -2); + + return $lastChars === '->'; + } + + return false; + } + public function walk() { - if (!$this->documentSkipsClosingQuote()) { + if (!$this->documentSkipsClosingQuote() && !$this->documentSkipsObjectOperator()) { return new Base; } diff --git a/app/Parsers/MemberAccessExpressionParser.php b/app/Parsers/MemberAccessExpressionParser.php index 7fb14d9..923ce66 100644 --- a/app/Parsers/MemberAccessExpressionParser.php +++ b/app/Parsers/MemberAccessExpressionParser.php @@ -17,8 +17,23 @@ class MemberAccessExpressionParser extends AbstractParser */ protected AbstractContext $context; + /** + * Check if the node has a object operator and + * is a last element in the string + */ + private function hasObjectOperator(MemberAccessExpression $node): bool + { + $name = $node->memberName->getFullText($node->getRoot()->getFullText()); + + return preg_match('/->' . $name . '->;$/s', $node->getFileContents()); + } + public function parse(MemberAccessExpression $node) { + if ($this->hasObjectOperator($node)) { + $this->context->autocompleting = true; + } + $this->context->methodName = $node->memberName->getFullText($node->getRoot()->getFullText()); foreach ($node->getDescendantNodes() as $child) { diff --git a/app/Parsers/VariableParser.php b/app/Parsers/VariableParser.php new file mode 100644 index 0000000..2de95a4 --- /dev/null +++ b/app/Parsers/VariableParser.php @@ -0,0 +1,58 @@ +getName(); + + return preg_match('/\$' . $name . '->;$/s', $node->getFileContents()); + } + + public function parse(Variable $node) + { + if ($this->hasObjectOperator($node)) { + $this->context->autocompleting = true; + } + + $this->context->name = $node->getName(); + + if (Settings::$capturePosition) { + $range = PositionUtilities::getRangeFromPosition( + $node->getStartPosition(), + mb_strlen($node->getText()), + $node->getRoot()->getFullText(), + ); + + if (Settings::$calculatePosition !== null) { + $range = Settings::adjustPosition($range); + } + + $this->context->setPosition($range); + } + + return $this->context; + } + + public function initNewContext(): ?AbstractContext + { + return new VariableContext; + } +}