Repository: phpactor/phpactor (php)

Issue:
Strange completion from 2022.11.12 onwards.
When I am entering a string with quotes as an argument to a method, after closing the string with a quote the LSP will provide completions.

A screenshot of just before I close the quote:

![Screenshot 2023-05-06 160418 phpactor before completion](https://user-images.githubusercontent.com/216721/236644911-3449cfb5-8017-457d-8a19-2a560e8aac1d.png)

and just after I close the quote:

![Screenshot 2023-05-06 160606 phpactor after completion](https://user-images.githubusercontent.com/216721/236644939-4b7db6d5-217f-4a95-acf2-a227e7923b44.png)

The provided completions are the names of the arguments of the method  [I assume for named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments), but not useful in this context.

The named arguments do work as expected:

![Screenshot 2023-05-06 165217 phpactor named argument as expected](https://user-images.githubusercontent.com/216721/236646184-41fb1631-42d6-4f66-a42d-36f5a83d61a3.png)

Thank you 🙇 

Pull request description:
Gh 2259: Do not suggest named parameters after string literal
Fixes #2259 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97fc5b35..b93420e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,7 @@ Improvements:
 
 Bug fixes:
 
+  - Do not show named parameters after string literal argument #2259
   - Fix "instanceof" behavior for statically reflected classes #2273
   - Fix behavior when user cancels type selection on goto type #2270
   - Fix docblock parsing of `array<'quoted'|'strings'>` #2264
diff --git a/lib/Completion/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletor.php b/lib/Completion/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletor.php
index 85b2ba35..6b0b4c28 100644
--- a/lib/Completion/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletor.php
+++ b/lib/Completion/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletor.php
@@ -12,6 +12,7 @@ use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;
 use Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression;
 use Microsoft\PhpParser\Node\Expression\Variable;
 use Microsoft\PhpParser\Node\QualifiedName;
+use Microsoft\PhpParser\Node\StringLiteral;
 use Phpactor\Completion\Bridge\TolerantParser\TolerantCompletor;
 use Phpactor\Completion\Bridge\TolerantParser\Helper\NodeQuery;
 use Phpactor\Completion\Core\Formatter\ObjectFormatter;
@@ -35,7 +36,7 @@ class WorseNamedParameterCompletor implements TolerantCompletor
 
     public function complete(Node $node, TextDocument $source, ByteOffset $offset): Generator
     {
-        if (null === $creation = NodeQuery::firstAncestorOrSelfInVia(
+        $subject = NodeQuery::firstAncestorOrSelfInVia(
             $node,
             [
                 MemberAccessExpression::class,
@@ -46,20 +47,22 @@ class WorseNamedParameterCompletor implements TolerantCompletor
                 ArgumentExpression::class,
                 ArgumentExpressionList::class
             ]
-        )) {
+        );
+
+        if (null === $subject) {
             return true;
         }
 
-        if ($node instanceof Variable) {
+        if ($node instanceof Variable || $node instanceof StringLiteral) {
             return true;
         }
 
-        if ($creation instanceof ObjectCreationExpression) {
-            return yield from $this->fromObjectCreation($creation);
+        if ($subject instanceof ObjectCreationExpression) {
+            return yield from $this->fromObjectCreation($subject);
         }
 
-        if ($creation instanceof CallExpression) {
-            return yield from $this->fromCallExpression($creation);
+        if ($subject instanceof CallExpression) {
+            return yield from $this->fromCallExpression($subject);
         }
 
         return true;


Test patch:
diff --git a/lib/Completion/Tests/Integration/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletorTest.php b/lib/Completion/Tests/Integration/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletorTest.php
index c968cd44..8c70df83 100644
--- a/lib/Completion/Tests/Integration/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletorTest.php
+++ b/lib/Completion/Tests/Integration/Bridge/TolerantParser/WorseReflection/WorseNamedParameterCompletorTest.php
@@ -47,6 +47,11 @@ class WorseNamedParameterCompletorTest extends TolerantCompletorTestCase
                 ]
             ]
         ];
+        yield 'no completion after string literal' => [
+            '<?php class A{function bee(string $one){}} $a = new A(); $a->bee(\'foo\'<>',
+            [
+            ]
+        ];
 
         yield 'Ignore when completing a variable' => [
             '<?php class A{function bee(string $one){}} $a = new A(); $a->bee($o<>',