klesun / deep-assoc-completion

A phpstorm plugin for associative array key typing and completion
Other
267 stars 17 forks source link

Follow @see tags to get actual definition #193

Closed 1234ru closed 2 years ago

1234ru commented 2 years ago

PhpDoc has @see tag, which allows to reference methods and properties of the class.

In it's current implementation it doesn't affect autocompletion.

But it would be great if we could do something like that:

class Declarations {
    /**
     * @var = [
     *     'name' => string,
     *     'email' => string,
     *     'phone' => string
     * ]
     */
    public $user;
}

/**
 * @param $u {@see Declarations::$user}
 */
function do_someting($u) {
    $u['']; // suggests 'name', 'email' or 'phone'
}

This would make PHP much more convenient language, allowing to describe data structures in one particular place and reference to it anywhere we want — the feature native PHP lacks to this day.

P.S. Привет русскоязычным!

klesun commented 2 years ago

Hi. The plugin already has a similar format supported:

/**
 * @param $u = Declarations::$user
 */

image

P.S. Русскоязычные приветствуют в ответ!

1234ru commented 2 years ago

That is just great! Your plugin is very helpful.

1234ru commented 2 years ago

One little thing: IDE doesn't suggest autocompletion after = sign:

1

It also does not suggest property names:

2

So, I guess, one way here is to go to property's definition, press Ctrl+Alt+C to get a reference to it:

3

then paste the reference where it should be:

4

1234ru commented 2 years ago

Sadly, IDE doesn't treat that as references, and if the class or variable is renamed, it won't affect the definition:

5

1234ru commented 2 years ago

Also it does not support nested references like ClassName::property::subproperty:

<?php

class Declarations {
    /**
     * @var = [
     *     'name' => string,
     *     'email' => string,
     *     'phone' => string
     * ]
     */
    public $user;
}

class Another {

    /** @var Declarations */
    public $D;

    /**
     * @param $arg = self::$D::$user
     */
    function foo($arg) {
        $arg['']; // Doesn't suggest here
    }
}

/**
 * @param $u = Another::$D::user
 */
function do_someting($u) {
    $u['']; // Doesn't suggest here as well
}

I apologize for putting comments in such chaotic way. I didn't expect to find all this out. But I want those observations to be kept somewhere.

klesun commented 2 years ago

no problem, github will handle it =D