deep-assoc-completion icon indicating copy to clipboard operation
deep-assoc-completion copied to clipboard

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

Open klesun opened this issue 5 years ago • 6 comments

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

klesun avatar Jan 16 '20 17:01 klesun

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 avatar Jun 19 '20 15:06 tminich

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[''];
}

tminich avatar Jun 19 '20 15:06 tminich

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

klesun avatar Jun 24 '20 07:06 klesun

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

tminich avatar Jun 24 '20 08:06 tminich

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

klesun avatar Jun 24 '20 10:06 klesun

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

tminich avatar Jun 24 '20 13:06 tminich