Skip to content

Node at vs right before cursor #3032

@przepompownia

Description

@przepompownia
diff --git a/lib/Completion/Tests/Unit/Bridge/TolerantParser/NodeAtCursorProviderTest.php b/lib/Completion/Tests/Unit/Bridge/TolerantParser/NodeAtCursorProviderTest.php
index 1bf5ab3c..c65ebc33 100644
--- a/lib/Completion/Tests/Unit/Bridge/TolerantParser/NodeAtCursorProviderTest.php
+++ b/lib/Completion/Tests/Unit/Bridge/TolerantParser/NodeAtCursorProviderTest.php
@@ -9,6 +9,7 @@ use Microsoft\PhpParser\Node\CaseStatementNode;
 use Microsoft\PhpParser\Node\Expression\MemberAccessExpression;
 use Microsoft\PhpParser\Node\Expression\Variable;
 use Microsoft\PhpParser\Node\MethodDeclaration;
+use Microsoft\PhpParser\Node\QualifiedName;
 use Microsoft\PhpParser\Node\Statement\CompoundStatementNode;
 use PHPUnit\Framework\Attributes\DataProvider;
 use Phpactor\Completion\Bridge\TolerantParser\NodeAtCursorProvider;
@@ -75,6 +76,18 @@ class NodeAtCursorProviderTest extends TestCase
                 self::assertInstanceOf(Variable::class, $node);
             }
         ];
+        yield [
+            '<?php interfac<>',
+            function (Node $node): void {
+                self::assertInstanceOf(QualifiedName::class, $node);
+            }
+        ];
+        yield [
+            '<?php interface<>',
+            function (Node $node): void {
+                self::assertInstanceOf(QualifiedName::class, $node);
+            }
+        ];

NodeAtCursorProvider can show different result depending on whether the cursor ends incomplete or complete keyword like on the data sets above.

I started from debugging why in #2622 KeywordCompletor shows if results for i<>, but not if<>. It turned out this it is not specific to that PR, as the above example shows.

Including the result with no additional characters in completion results makes sense if we want to get the associated snippet, text edit etc, hence my investigation.

At the moment I don't have idea how to fix it without breaking the rest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions