Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nice feature TODO list #8

Closed
klesun opened this issue Aug 24, 2017 · 16 comments
Closed

Nice feature TODO list #8

klesun opened this issue Aug 24, 2017 · 16 comments

Comments

@klesun
Copy link
Owner

klesun commented Aug 24, 2017

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).

  • Make used key completion support key chain like this: $rcvd['rcvd']['originData']['receivedFrom'] (currentyl it only suggests the 'rcvd' key)

  • Rewrite getBriefValueStr so that it worked with the iterator, not array - just take first few type till string fits into the n characters.

  • It would be cool to have both project-level and IDE-level settings...

  • It would be nice if functions in doc comments were captured by the reference provider...

  • Maybe make dependency on DB plugin optional? It would make sense if you keep useless plugins disabled to speed up startup...

  • Maybe infer type of json_decode('{"a":"5", "b": 6}'), but with very strict depth limit and guards for >1 MiB files.

  • Support GoTo method name in multi-line php doc

  • Infer dynamic property assignment and json_decode(json_encode(..., $flag)). BagAccess.php:

    private function getChain(array $keys)
    {
        $parent = $this->root;
        foreach ($keys as $key) {
            $parent = $parent->{$key} ?? null;
        }
        return $parent;
    }
  • It would be pretty cool if completion worked here:

    'JOIN '.FlightOption::TABLE.' fo ON fo.',

    IDEA does the job when there is no concatenation, but this is not always the case. So I suggest to provide the completion in any string that matches pattern JOIN {tableName} alias ON alias.{suggestColumnsHere}. Could go even further and actually semi-parse whole SQL string and provide completion in WHERE, SELECT, GROUP BY, etc... as well.

  • Go To column in DB schema in the "Database" tab instead of just the Db::exec() expression.

  • It would be nice if Reference Provider highlighted same key on same variable/field in a function.

  • Used key completion should work here:

     $handler = [\Rbs\Process\Common\ImportPnr\ImportPnrAction::class, 'reportManyCmdsFromSameStoreTds'];
     $handler([
     	''
     ]);
  • Infer arguments inside lambda passed to something other than array_map like here: 50f0bf2

     function runUpdatePnrJobs(string $gds, callable $processPnrJob) {
     	$processPnrJob(['pcc' => 'KL65', 'queue_number' => 80, 'record_locator' => 'ZXCFR2']);
     }
     runUpdatePnrJobs('apollo', function($jobRow){
     	$jobRow['']; // should suggest: 'pcc', 'queue_number', 'record_locator'
     });

    Actually I already do something similar - ArgRes::getFuncVarUsageArg(). Could at least make it infer type only from the direct function it is passed to to not waste performance... or put some sane depth limit. Should support array_map and other built-in functions there. See TODO in ArgRes::getArgFromMethodCall()

  • Provide array structure description in built-in "Show Docs" pop-up that is shown when you press Ctrl + Q instead of separate (Ctrl + Alt + Q) shortcut. This time i should handle it, it did not work initially because of absence of "order"="first" likely. Btw, would be nice if docs were also shown when you press the shortcut inside quotes (we don't always have a var).

  • Support vars in "" string literals:
    image

@klesun
Copy link
Owner Author

klesun commented Sep 12, 2017

Resolved

  • When you are typing array keys in a doc it would be VERY convenient if caret position was indented after a line break. (and add closing brackets btw) e28b45e

  • image should not suggest numeric keys for indexed arrays in usage-based completion. 2f08286

  • Provide array static method name completion even with $this, like [$this, 'getRateAmount'] since writing $this is usually more convenient than self::class (5 characters vs 11). These options should be highlighted somehow and put to the bottom to make it clear that they are static.

    Could show them without bold like IDEA does for inherited methods. Would be also nice to do same with 1,2,3,4,5 completion when there are string key name options, from recursive ParamUtil::sample() for example. a4cd89c

  • When both this plugin and deep-js-completion are loaded, make /** @var $formData = at('mcoForm.js').makeFormData() */ provide completion using the type resolution from the other plugin. 9a5a829

  • A bug, plugin makes static calls suggest non-static methods:
    image 56ab8c5

  • For some reason, using undeclared $i variable in the doc does not give me any key, whereas using $any does. Is there some global $i variable declared in the project? Same expression in the code does give completion so I guess not...
    image
    image
    image
    Also, an unrelated issue, but $object type does not get resolved from private func usages when you specify type in some other file like this: @param $agents = [AgentImportV11::normalizeActive()]
    3cb5ac2

  • There are also various function that take/return some constant values, would be nice to hardcode them as well (regex, curl, mysql, PDO, LIBXML, FILE_APPEND, SORT). Making built-in function constants popup without '' woul be good too. Would be nice if completion worked in a bit mask as well. 460a802

  • Support SQL::select in CMS. I guess all that is needed is to start supporting mysqli, not just PDO. 36bcca2

  • A bug, when you try to Ctrl + B on a non-literal key in an assignment, you get redirected to this same assignment instead of built-in Go To of the key expression:

    $gdsToStatus[$gds->getName()] = $status;
    

    When I Ctrl + Click getName I want to get to the function getName definition, but I don't - should fix. (Reproduces only when getName is a magic method, plugin's member Go To fires otherwise probably) e0c56dc

  • Implement used key completion for built-in functions like stream_context_create():

    stream_context_create([
        'http' => [
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data)
        ]
    ]);

    I believe there were some more functions that take associative array arguments... curl_setopt_array() maybe? 793e494

  • Completion of string value passed to the function if this string is used as key name inside: 6e43e28

     public function __construct(string $profile)
     {
     	$this->profile = $profile;
     	if ($settings = $this->getProfiles()[$profile] ?? null) {
     		$this->setting = $settings;
     	} else {
     		throw new \Exception('Unknown profile ['.$profile.']');
     	}
     }
     $client = new \Delpaso\DelpasoSoapClient('');
  • Show comments typed above or right to a key in the completion if any instead of a brief value: 83be277

/**
 * @param $dict = [
 *     'dbName' => 'rbstools', // name of the MySQL database
 *    // IP address of the database
 *     'host' => '192.168.0.1',
 * ]
 */
  • Class/Method completion should work in the multi-line doc comments: d30957e

        /** @param $params = [
         *     'status' => 'price_dropped',
         *     'oldPrice' => '1500.00',
         *     'newPrice' => '1400.00',
         *     'oldPtcBlock' => ApolloPricingAdapter::transformPtcBlock(),
         *     'newPtcBlock' => [], // ...
         *     'oldMods' => [], // ...
         *     'newMods' => [], // ...
         *     'oldPricingDump' => '>*LF ...',
         *     'newPricingDump' => '>$B ...',
         *     'pnr' => ApolloPnr::makeFromDump(),
         * ]; */
        public function execute(array $params);

    I guess next lines are a separate PSI, that's why completion does not work. Related to Allow specifying use-d class without namespace in php doc #40

  • Provide variable name completion and Go To from extract(). Since we already do so for compact() and $GLOBALS. 2197a04

  • Provide Used Key Completion in CMS framework Model::getOne(['' => '123']), Model::get(['' => '123']) and ModelParams::filter(['' => '123']). 4bb771d

  • Infer type of $someCls = static::class and $obj = new $someCls(); so that I would get completion in $obj->.... (GTL, Amadeus Controller) d6d9718

    /** @var RbsPnrAdapter $rbsAdapter */
    $rbsAdapter = app()->make(RbsPnrAdapter::class);
    $parsedPnr = $rbsAdapter->parsePnr($data['msg']);
  • Add support for array_fill_keys. Also, array_replace should take type from all passed arrays, not just first. 5be88a4

  • It should be easy to make Used Key Completion suggest SQL query params used in the query like col_name = :var_name. At least suggest completion in the array. Though to suggest completion in the SQL string it should also be pretty easy:

    $row = Db::inst()->fetchOne(implode(PHP_EOL, [
        'SELECT * FROM pnrs_for_price_drop_monitoring',
        'WHERE gds = :gds AND record_locator = :record_locator;',
    ]), [
        '' => $job['record_locator'], // completion here
    ]);

    ef0abbf

  • To N-th test should work even when caret is not inside a function - take all @dataProvider-s in the file, if there are many - use first having at least N tests. a8ebf5a

  • When you Ctrl + B on a key you got from array_keys() call, you should be redirected to the definition of this key, not to the array_keys expression:

    $arr = ['itinerary' => ['KIVKBP', 'KBPRIX'], 'paxes' => ['Vova', 'Petja']];
    $keys = array_keys($arr);
    $newArr = [];
    foreach ($keys as $key) {
        $newArr[$key] = 'new value';
    }
    $newArr['itinerary'];

    Same probably should apply to other functions like array_combine, etc... I believe, for array_combine it was even already implemented. ff42812

  • I believe irrelevant options (oneOf, minLen, pattern, etc...) can be removed from here if you check for class when getting constructor arguments:
    image
    The irrelevant options get here from the second argument passed to new StringP because plugin thinks they are same thing as second argument passed to new DictP. And it thinks this way because IDEA assigns DictP type to the $scheme var in $scheme instanceof DictP.
    678f4b5

  • Method name completion should work on 'processPnrSchema' here: /** @param $params = ParamUtil::sample(AmadeusController::processPnrSchema()) */ 5de5d72

  • @return doc should be infered from implemented interface:

    $gtlResult = GtlProvider::get()->getAmadeusPnr([
        'recordLocator' => $this->recordLocator,
        'sessionToken' => $this->getSession()->getSessionToken(),
    ]);
    $gtlResult->unwrap()['']; // completion should be here

    0879071

  • Add key completion from stream_get_meta_data and curl_getinfo that return associative array. It would also be nice to add more such functions if I manage to find them. 74263ff

  • Add completion and Go To to the array_key_exists same way as it is done for array_column 896d8d4

  • explode() and other similar functions return type should be resolved as indexed array of strings. e3f54bf

  • Completion should work here:

$onlyRaw = function($matches){return ['raw' => $matches[0], 'parsed' => null];};
$lexer = new Lexer([
    (new Lexeme('returnDate', '/^¥R(\d{1,2}[A-Z]{3}\d{0,2})/'))->preprocessData($onlyRaw),
]);
$lexed = $lexer->lex($modsPart);
$lexed['lexemes'][0][''];
$lexed['lexemes'][0]['lexeme'] === '';

Does it not work because of caching? eeee3f9

  • A bug: method name completion in @return tag does not work if neither array type nor = are specified. Class name completion works though... 4c879a7

  • Also provide completion of methods from self:: by the way. 5b51242

  • Provide doc completion in @var tag same as in @param tag. c483038

/** @var $avail = AbstractTravelportController:: */
$avail = $gtl->performRequest('apollo.xml.getHotelAvailability', [
  • Also provide function name completion and GoTo in @return tag. 6f2ed38

  • It would be much more usefull if Ctrl + Alt + Q keys were in php array format, not json, since you would usually have to change :-s to => when you copy them somewhere. Also Ctrl + C stopped working in this dialog window, should fix this too. 15d48a2

  • 'ptc' should be suggested here: 15db087

        if ((new Lexeme('ptc', '/^\*([A-Z0-9]{3})/'))->name === '') {
            // ...
        }
  • 'start' and 'value' should be suggested here (and in in following map chains). 15db087
\Lib\Result::makeOk(['start' => 123, 'value' => 123])
    ->flatMap(function($value){$value[''];});
  • 'cat', 'dog', 'monkey' should be suggested here adb505d
$animals = ['cat', 'dog', 'monkey'];
$i = rand(0, 10);
if (($animals[$i] ?? null) === '') {
    
}
  • It would be very very good if Find Usages on a method used this way would return something:
Fp::any(
    [static::class, 'isTourFare'],
    $pricingStoreInfo['pricingList'] ?? []
)

0364a22

  • When you are writing php doc for completion, it would be nice if it suggested you key names here, not just method name:
/** @param $ssrs = SiParser::parse()[''] */
public static function transformDocSsrs(array $ssrs)
{
}

bfa6a63

  • Used keys completion should be inferred from abstract method implementation. Moreover, it would be very nice if we used only the function of exact class if we know it. Completion should work here:
$result = (new \Gtl\AmadeusSoapActions\AmadeusListQueuePnrs('GENERIC'))
    ->execute([
        ''
    ]);

c12fad2

  • Support @return array like ['a' => 5] and @return array ['a' => 5] and @return ['a' => 5] 7dbc9d7

  • array_intersect($cmdTypes, ['redisplayPnr', 'itinerary', 'airItinerary', 'storeKeepPnr', 'changeArea', '']) ...please? 7ab23fa

  • Top Featur: Go To Test by number.
    You press Ctrl + Alt + ;, enter the test number $i from here:

~~70) Rbs\GdsDirect\DialectTranslator\GdsDialectTranslatorTest::testTranslator with data set #2078~~

Plugin looks at return type of @dataProvider function and navigates you to the declaration of $i-th element (if just one).
eedb81b

  • Also the string values completion $type === 'ITINERARY_SEGMENT' should also work with in_array($type, ['ITINERARY_SEGMENT']) d6883a3

  • Similar to recent feature, if (in_array('deletePnrField', array_column($flatCmds, 'type'))) { should provide completion and Ctrl+B (this time we need completion in needle, not haystack). in_array('', $remarkTypes) cb9a445

  • Add an option in config (disabled by default) to remove unused use-s on save without changing order of other use-s. 9462838

  • Same applies for keys assigned like that: $pnrFields[$name] = $result - Go To key should lead to the string literal, not assignment expression. 03f8027

  • Ctrl+B should work on $type === 'ITINERARY_SEGMENT'. And Ctrl+B on keys created in array_combine should lead to the string literal, not the array_combine() expression.

  • Should make a page in Options page where following will be configurable:

    • Allow Type Provider in background. Default false, since it causes problems for Laravel users.
      • If allowed, how big should maximal depth be. I would set something like 5 by default and play with it later in RBS.
    • Max depth for explicit assoc array key completion.
    • Max depth for implicit assoc array key completion (the pop-up when you type code).
    • Maybe something else...
  • ~~It would be good if type of what you pass to the constructor could preserved in the object:~
    image
    Following code should provide completion:

    Result::makeOk(['a' => 5, 'b' => 4])->unwrap()[''];

    326466b

  • Infer type when associative arrays are merged with +:
    image
    08d17d1

  • Completion should work with iterator functions: key(), current(), next(): b5a460c
    image
    image

  • IDEA often suggests handy Go To Definition on function references like this [static::class, 'makeDocsCmd']. Sadly they are suggested only when array is passed directly somewhere with callable type hint. So I'd like to add a Go To Definition provider that would suggest the Go To on any array having form similar to: [static::class, 'makeDocsCmd']. cf0cd42

  • It would be nice when you press Ctrl + Alt + Q on an argument in function declaration that you would get the keys that are used on that var (the keys used in the KeysFromUsagePvdr.java). 83bf1cb

  • Provide completion inside [], not just ['']. Now this will be usefull since I can now put mine options to the top of the list - hundreds of expressions suggested by phpstorm is not problem anymore. 4605a47

    • It would be very convenient if private function arguments were infered from usage just like lambda in a var currently does. Maybe should do that only when this private function is used in just one place... and of course only if caret is inside this function (don't peek outside if we know exactly what arguments were passed probably). 90a7977
  • It would be useful if I could have completion from SQL SELECT-s:

    • Just a simple regex match: explode text between SELECT and FROM by ,, use text after AS or last \w part as key name. cbaa432
'SELECT',
'    s.id,',
'    s.is_active,',
'    s.gds,',
'FROM terminal_sessions s',
    • Btw, using upgrade_sql.php on SELECT * could be done, but not sure, since it's usually huge... May also look at the IDEA's feature to plug your DB for schema...
      Now, that i think about it, maybe there is no need for project-specific configurations. I got Fp:: resolved automatically thanks to return type based on passed args, maybe something similar could be done for the PDO? Like $stmt = PDO::$connection->query($sql) or $stmt = PDO::$connection->prepare($sql)->execute($params) followed by $stmt->fetch(\PDO::FETCH_ASSOC) returns rows from $sql...

      1569db3
  • Completion in array_merge($default, ['']), array_replace($default, ['']) and others if any. 1d89088

  • It would be good to make completion appear on it's own (with a 0.05s timeout) when user puts caret in quotes, but should be very careful to not cause freezing, cuz i personally hate it. 266edef

  • Show array keys in the short completion type preview. We already know them, so this should not cause additional load. e213e6e

  • Irrelevant built-in suggestions are pissing me off. I already know that i can't set priority of my suggestions higher using Lookup. Maybe i can interact with the completion window itself by moving pointer to my suggestions or (ideally) remove duplicating built-in suggestions. Ability to increase the length of this window would be nice too (only 4.5 lines at once fit).
    e2c2a0b
    b815e87

  • Completion inside a lambda assigned to a variable based on usage like in the assoc array initialisation. Vary please! semi-done: c8f96bc

    • Should also add Fp functions: map, filter, groupBy, etc...
    • Should respect the argument order: both of lambda in a function and arg in the lambda to provide completion from functions like array_reduce and not provide completion if user mismatched array and func in array_filter arguments. b404df5
  • Completion from @dataProvider providePricingToWrongDestinationTests in phpunit tests cb4a2f3

  • Currently i provide object class info in such expressions: $dumpData['itinerary']->segments, $dumpData['itinerary']->getCabinClass(). Class info should also be provided in assignments to a var $itin = $dumpData['itinerary'] 450c6a4

  • Autocomplete inside array_map and array_filter.
    870d669 - array_map
    f1226f7 - Fp::map

  • When suggesting completion in the doc for an interface class - include abstract methods as well (currently i return only getOwnMethods, which apparently does not inclide them).
    Example:
    a9ae5eb

@param $pricingStoreInfo = IGdsPnrFieldsProvider::

doh, there is more to it, apparently completion of interface methods from docs does not work at all unless you specify the full namespace to the interface.

  • Completion of function name when you are making a reference using array would be nice: [ApolloReservationItineraryParser::class, '']. 2eb6552
    arr_meth_ref_completion
  • Completion/Go To Definition in array_column
    dcd1b97 - completion
    26e1d63 - go to definition
    screenshot_2017-08-30_16-16-48

@klesun klesun closed this as completed Dec 8, 2017
@klesun klesun mentioned this issue Oct 18, 2018
@klesun klesun changed the title Nice feature list Nice feature TODO list Jan 4, 2019
@klesun klesun reopened this Jan 4, 2019
@klesun klesun self-assigned this Jan 11, 2019
@Jurigag
Copy link

Jurigag commented Apr 11, 2019

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

@klesun
Copy link
Owner Author

klesun commented Apr 11, 2019

@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 pushed a commit that referenced this issue Apr 11, 2019
@klesun
Copy link
Owner Author

klesun commented Apr 11, 2019

Added support for debug_backtrace() in 2019.04.11.001
image

@Jurigag
Copy link

Jurigag commented Apr 15, 2019

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
Copy link
Owner Author

klesun commented Apr 15, 2019

@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
Copy link

Jurigag commented Apr 15, 2019

Oh, thanks for this.

@GDXbsv
Copy link

GDXbsv commented May 7, 2019

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
Copy link
Owner Author

klesun commented May 7, 2019

Filed a separate issue - #77

@mialex
Copy link

mialex commented May 28, 2019

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
Copy link
Owner Author

klesun commented May 29, 2019

@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
Copy link

Jurigag commented Aug 20, 2019

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

@klesun
Copy link
Owner Author

klesun commented Aug 20, 2019

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

@Jurigag
Copy link

Jurigag commented Aug 20, 2019

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

image

@klesun
Copy link
Owner Author

klesun commented Aug 20, 2019

#110
I'll look into that. If there will be a usable xdebug API in the phpstorm I'll add it.

@klesun
Copy link
Owner Author

klesun commented Jan 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants