klesun / deep-assoc-completion

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

Nice feature TODO list #8

Closed klesun closed 3 years ago

klesun commented 7 years ago

Not Resolved Yet

Here are listed some small things that are relatively easy to implement and do not affect the whole behaviour much. Some stuff lays here for pretty long time, so if you are interested in some of these features, you can ping me, I'll start doing it. Otherwise I will implement the feature only when I need it in some of my php projects (whcih may happen... not very soon).

klesun commented 7 years ago

Resolved

}


- ~~It would be very very good if `Find Usages` on a method used this way would return something:~~
```php
Fp::any(
    [static::class, 'isTourFare'],
    $pricingStoreInfo['pricingList'] ?? []
)

0364a222275da8e2708e8255fc1f5287d206beb4

Jurigag commented 5 years ago

@klesun how about suggetions of keys from arrays returned by php internal functions? Like for example debug_backtrace

klesun commented 5 years ago

@Jurigag, sounds good. I'm actually already doing this for a set of functions I managed to find, but apparently debug_backtrace wasn't among them. I'll add debug_backtrace to the list soon. If there are any other functions on your mind, I'll gladly add them as well.

klesun commented 5 years ago

Added support for debug_backtrace() in 2019.04.11.001 image

Jurigag commented 5 years ago

Cool.

I'm also wondering if you could provide some way to define those possible keys for 3-rd party php extensions using php stubs(just empty php classes with phpdocs definitions)? Like for example, there is c-based framework called phalcon, which just works as extension. There is method like \Phalcon\Mvc\Model::findFirst() which can accept array like this:

$robot = Robots::findFirst(
    [
        "type = 'virtual'",
        'order' => 'name DESC',
        'limit' => 30,
    ]
);

Of course adding it for all extensions possible would be a a lot of effort. Maybe you could implement syntax using some kind of annotations so for example here https://github.com/phalcon/ide-stubs/blob/master/src/Phalcon/mvc/Model.php#L559 we could just add some magic thing which would your extension then use and autocomplete those keys above, like order limit etc?

klesun commented 5 years ago

@Jurigag, if you are a contributor of phalcon/ide-stubs, you can specify function argument type for the plugin like this:

    /**
     * @param mixed $parameters = [
     *     'type' => 'virtual',
     *     'order' => 'name DESC',
     *     'limit' => 30,
     * ]
     * @return Model
     */
    public static function findFirst($parameters = null) {}

image

Jurigag commented 5 years ago

Oh, thanks for this.

GDXbsv commented 5 years ago

It would be nice to have an ability to use annotation from the PSALM static analysis. We already use it for the type analysis, so autocompleat would be the great feature in additional.

This is an example from the documentation https://psalm.dev/docs/docblock_type_syntax/#array-types

and one from me:

        /** @var \Generator<array{
         *                      itemNo:string,
         *                      variants:array<array{
         *                          Code:string,
         *                          stock:array<array{
         *                                     serialNo:string,
         *                                     locationCode:string,
         *                                     differentialTaxation:bool
         *                                      }>
         *                           }>
         *                      }>
         * $products
         */

Thanks!

klesun commented 5 years ago

Filed a separate issue - https://github.com/klesun/deep-assoc-completion/issues/77

mialex commented 5 years ago

Hello, could you tell me if it's possible to describe somehow the possibility to support a collection of assoc arrays? What I mean is the next:

[
    [
        'user' => [
            'id' => 123,
            'name' => 'Joe',
        ],
    ], [
        'order' => [
            'id' => 21,
            'offer_id' => 212,
        ],
    ], [
        'offer' => [
            'id' => 212,
            'name' => 'Toys',
        ],
    ],
]

So I could describe a possible set of options and then I can use it in any order?

klesun commented 5 years ago

@mialex, you can use psalm format (just added support for | in 2019.05.29.001): image

Another trick would be to use an undefined var (for example $any) as key: image

@param $records = [
    $any => ['user' => ['id' => 123, 'name' => 'Joe']],
    $any => ['order' => ['id' => 21, 'offer_id' => 212]],
    $any => ['offer' => ['id' => 212, 'name' => 'Toys']],
]
Jurigag commented 5 years ago

Im wondering if it's somehow possible - add autocomplete based on xdebug variables? @klesun

klesun commented 5 years ago

@Jurigag, if this is just a static set of keywords, no problem. Could you provide a link describing them?

Jurigag commented 5 years ago

Well i mean when xdebug session is active. Like suggest keys here:

image

klesun commented 5 years ago

https://github.com/klesun/deep-assoc-completion/issues/110 I'll look into that. If there will be a usable xdebug API in the phpstorm I'll add it.

klesun commented 3 years ago

Closing as no time for implementing the remaining minor features in the list. If someone considers some particular ones a must-have, please open a separate ticket.