phpactor: Import not working for phpdoc

With this code (Pipe character is the cursor position, right before Request btw):

        /** @var |Request $request */
        $request = $subject;

And this command:

:call phpactor#UseAdd()

Menu is shown but selecting any option doesn’t add the import in the use section.

However if I do it on this code it adds the import selected from the menu:

$request = new |Request();

This used to work before.

Not directly related, but I’ve tried the coc-phpactor extension, and it behaves same, but only shows 3 import options in the menu instead of all.

Neovim: 0.4.3 phpactor: 0.16.2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@Herz3h try Plug 'phpactor/phpactor' , {'branch': 'develop','do': 'composer install', 'for': 'php'}

Should probably try and push a new release (17) - last one was over four months ago 😱

I have some trouble updating all the packages right now (phpstan for some unknown reason…) so I could not test it yet. But I think the problem come from the commit 9df5d232

@@ -45,12 +48,16 @@ class TolerantImportClass implements ImportClass
         $sourceNode = $this->parser->parseSourceFile($source);
         $node = $sourceNode->getDescendantNodeAtPosition($offset);
 
+        if (!$node instanceof NamespacedNameInterface) {
+            return TextEdits::none();
+        }
+

Since the offset is in some phpdoc the reflector does not recognize it, I’ll try to confirm that when the packages will be installed. @dantleech do you remember why you added this check ?