phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

Autocomplete of class name in PHPDoc only works if you start typing the class name from scratch

Open php4fan opened this issue 4 months ago • 3 comments

To reproduce, start with this code:

<?php

class MyClass1 {
    public function whatever() {
        
    }
}

class MyClass2 {
    
    public $somevar;
}

Now I want to add a @var declaration in a PHPDoc comment above $somevar. Start by typing /**, which will autocomplete to this:

<?php

class MyClass1 {
    public function whatever() {
        
    }
}

class MyClass2 {
    
    /**
     * Summary of somevar
     * @var 
     */
    public $somevar;
}

Place the cursor after @var and start typing MyC: this will propose autocompletion options including MyClass1 and MyClass2 as expected:

Image

Nice. Select MyClass1, so now we have the complete code:

<?php

class MyClass1 {
    public function whatever() {
        
    }
}

class MyClass2 {
    
    /**
     * Summary of somevar
     * @var MyClass1
     */
    public $somevar;
}

Actually I could have started from here, but the above shows that autocomplete works fine as long as you start from scratch.

Now, say we want to change the type of the @var from MyClass1 to MyClass2.

  • Place the cursor after @var MyClass1
  • delete the last two characters "s1" and re-type the s, so now we have:
Image

and the cursor is where the red arrow points at.

At this point, autocomplete should kick in, as it normally does in similar cases in regular code (as opposed to PHPDoc sections). But it's dead, as can be seen in the screenshot.

In order to have autocomplete kick in, I have to delete the entire class name and restart typing it from scratch.

php4fan avatar Jul 17 '25 17:07 php4fan