klesun / deep-assoc-completion

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

PSALM `key-of`/`value-of` support #137

Open klesun opened 4 years ago

klesun commented 4 years ago

https://github.com/vimeo/psalm/releases/tag/3.3.1

Requested by @andrew-demb Due to me ~being lazy~ trying to make it smart and stuff I never managed to finish implementing this for many months, but I'll try my best. https://github.com/klesun/deep-assoc-completion/issues/77#issuecomment-496803637

tminich commented 4 years ago

I didn't want to put more work on your shoulders over the weekend as you have already been incredibly helpful today, but there are a few things not quit working with the psalm syntax as far as I understand it though, do you want me to add them to this bug or open a new one?

tminich commented 4 years ago

Since I'm about to leave work I'll leave it here for now: This works:

/**
 * @param array  $specs Specifications for parsing.
 *
 * @psalm-param array{
 *     allowed:    list<string>,                  // Array of allowed tags. 'allowed' and 'disallowed' are mutually exclusive
 *     model:      callable,                      // Comment
 * } $specs
 *
 */
function psalm_test(array $specs): void
{
    $specs[''];
}

These all break parsing in some way but, as far as I understand, are valid PSALM syntax:

/**
 * @param array  $specs Specifications for parsing.
 *
 * @psalm-param array{
 *     allowed:    string[],                 // Comment allowed
 *     allowed2:   array<array-key, string>, // Comment allowed2
 *     model:      callable(string, string=, string...):string, // Comment model
 *     model2:     Closure(string, string=, string...):string, // Comment model2
 *     test?: string, // Optional
 * } $specs
 *
 */
function psalm_test2(array $specs): void
{
    $specs[''];
}
klesun commented 4 years ago

Lol, thanks, did not even knows PSALM had a syntax for function types. Will add basic support shortly.

tminich commented 4 years ago

Thanks a lot. PSALM syntax, thanks to being able to use @psalm-X tags, currently seems to be the best way to get deep-assoc-completion hints without PHPStorm showing them weirdly and/or destroying the formatting when you use it's auto-formatting =)

klesun commented 4 years ago

@tminich basic support for callable and rest constructs from your example released in 2020.06.24.001

image

(I did not implement anything smart for the completion of callable arguments when you pass an anonymous function to the annotated method, pls let me know if this would be a much demanded functionality)

tminich commented 4 years ago

Thanks a lot. For me that's enough, I just didn't want deep-assoc-completion's parsing break on valid PSALM syntax.