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

Support @template/generic phpdoc syntax #1144

Closed
bmewburn opened this issue May 16, 2020 · 26 comments
Closed

Support @template/generic phpdoc syntax #1144

bmewburn opened this issue May 16, 2020 · 26 comments
Labels
Milestone

Comments

@bmewburn
Copy link
Owner

bmewburn commented May 16, 2020

Syntax for generic iterable and ArrayAccess types is supported (ie array<int, Foo> and Collection<int, Foo>) but there is not currently support for user created generic classes and functions using @template which has gained popularity in phan, phpstan, psalm etc.

@huchim
Copy link

huchim commented Aug 8, 2020

I don't know if this is what you will add support, but it would very great if you can recognize @template.

namespace Omega\Configuration;

interface ConfigurationReaderInterface
{
    /**
     * Returns a configuration value.
     *
     * @template T
     * @param string $key
     * @param T $default
     * @return T
     */
    public function getValue(string $key, $default = null);
}

image

@jeferrier
Copy link

This may be noisy on an issue thread. If so apologies. My organization is considering switching from VSCode to PHPStorm over support for this. We'd like to stay on VSCode, so this is something we're really ready to use.

@qbasic16
Copy link

This feature would be great!

I just found a detailed description on PHPStan, Generics in PHP usin PHPDocs.

Cheers 🍻

@marwan38
Copy link

marwan38 commented Sep 1, 2021

Any updates on this?

@MohammadMD1383
Copy link

we really need this!

@KapitanOczywisty
Copy link
Contributor

@bmewburn PHPStorm started using generics in their definitions: https://github.com/JetBrains/phpstorm-stubs/blob/60371693469c5c191f5f31780300629d4fddce12/standard/_types.php#L151-L163

/** @return Generator */
function gen(){ yield 3; }

$gen = gen();
foreach($gen as $item){
	$item; // => @var \TYield $item
}

@boan-jfm
Copy link

boan-jfm commented Jan 18, 2022

Just a link to PHPStorms release documentation :-) https://blog.jetbrains.com/phpstorm/2021/07/phpstorm-2021-2-release/#generics

@tm1000
Copy link

tm1000 commented Feb 7, 2022

Laravel 9.x now supports Generics in Collections (as seen in the PHPStorm blog)

laravel/framework#38538

This will cause errors to be displayed from Intelephense until it is resolved. because Intelephense does not understand generics at all.

Also: https://phpstan.org/blog/generics-in-php-using-phpdocs

@ghost
Copy link

ghost commented Mar 2, 2022

Can we start a financial goal for this / would there be interest in this? I've already paid for the plugin and I'd put at least $250-500 bucks 😆 of my own money in for generics & @see which is what I think most people are missing with intelephense at the moment.

I appreciate the price I've already paid for premium is low but I'm feeling pretty upset that I'm stuck with what I feel is three options for more intricate PHP Development:

  1. Use jetbrains gateway: Which is absolutely appalling, a complete reskin of code with me and to top it off there will very likely be no further development efforts on gateway because of fleet.
  2. Shell out 2k+ for a new macbook to run PHPStorm despite the 48 vcores.. on my current local/remote workstation machine (linux box @ home)
  3. Wait for intelephense to support template generics. (is there a goal/eta for https://github.com/bmewburn/vscode-intelephense/milestone/36?)

If anyone has any other suggestions for things to try that would be greatly appreciated (I'm fairly proficient with vim bindings so I'd be willing to use vim but I'm not if any open source or paid LSP supports template generics etc.)

I feel ridiculous suggesting this but I can't really think of any other way I can make this happen short of writing my own LSP or switching and contributing to another open source one (nothing else compares: https://langserver.org/).

I've used phpactor in the past and its seems viable for small projects but from what I gather it is not at the phpdoc stage much.

@bmewburn I appreciate you might be inundated with work/life already so feel free to say otherwise but would a financial goal / extra tier to premium for a template generics implementation sooner rather than later work for you?

@ghost
Copy link

ghost commented Mar 2, 2022

I should probably note my preferred method of support would be a subscription like PHPStorm so you can continue to work on improving the LSP :)

@tm1000
Copy link

tm1000 commented Mar 3, 2022

Ben marked this for the 1.9 release so I assume he's in the middle of getting it done

@ddanielou
Copy link

I should probably note my preferred method of support would be a subscription like PHPStorm so you can continue to work on improving the LSP :)

As much as I hate mindless thread bumps, count me in. The 10$ perpetual license is a steal. Many of us shell out way more for way less essential tools, and on a subscription basis at that.

(I realize generics might be right around the corner, but the subscription idea would still stand.)

(Also, I hope this doesn't come across as super pushy or anything. Just want to express my support and appreciation for your work.)

@rosmanov
Copy link

Due to this issue PHPUnit's createMock()->method() and createMock()->expects are not recognized as existing methods.

PHPUnit uses psalm templates so I thought I'd propose to add some more generic templates there. However, this is pointless as long as Intelephense doesn't support generics.

@innocenzi
Copy link

CleanShot 2022-11-30 at 11 27 48

Really looking forward to this being implemented. This is becoming counter-productive to keep using VSC, but I really want to avoid making the switch to PHPStorm.

@TheLevti
Copy link

A lot of generics type hinting is added in all sorts of packages, but can't make use of it with vscode. I am a long time vscode supporter, but starting to checking out phpstorm, because of this. Anyhow this can be pushed/supported?

Repository owner deleted a comment from genius257 Dec 12, 2022
@jorismak
Copy link

Just tried PHPTools (DevSense) because of the generics support...

.. it does what I want regarding generics.

But either I'm set in my ways, or it has very annoying quirks that make me want to get back to Intelephense very quickly.
So I have to choose between all the good of Intelephense, or generics support. I'll keep using Intelephense for now, but it's a bit hard breaking that I'm looking elsewhere for this feature.

I paid 100,- once... I'd happily pay it every year or so to keep support going, but if I'm the only one saying that, it will not change things I reckon :).

@Logifire
Copy link

@jorismak As long you can choose to upgrade by a 100,- or keep the existing, I think it is fine. But not a required subscription.

@tm1000
Copy link

tm1000 commented Dec 28, 2022

Just tried PHPTools (DevSense) because of the generics support...

What i find disingenuous about this project now is that @genius257 recommended DevSense because Intelephense is essentially dead/stalled and the repo owner of Intelephense removed the comment.

image

Some of us are just trying to find something that actually works. Thanks to @genius257 for pointing this out and thanks to github email or I would have never found it. This project will be my first goto but there's literally no communication from the one developer. So developer to developer let us talk about other software unless you want to make an announcement yourself about development or give us a roadmap.

But either I'm set in my ways, or it has very annoying quirks

@jorismak I've found the following settings to disable everything but the code completetions and hover:

    "php.validate.enable": false,
    "php.problems.excludeGitIgnore": true,
    "php.format.codeStyle": "Off",
    "php.format.rules.forStatementWrap": "off",
    "php.format.rules.whileStatementNewLineAfterLeftParen": false,
    "php.problems.exclude": {
        "/": true
    },
    "php.problems.scope": "none",

@bmewburn
Copy link
Owner Author

@tm1000 it's not disingenuous. This issue board is for discussing issues in this extension. The internet is a big place, I'm sure there are many forums where you can discuss such things. Would you be OK with me going to your repos and commenting on alternatives that I perceive as better?

This project hasn't progressed as quickly as I'd like it to, but a release with templates is just around the corner.

@tm1000
Copy link

tm1000 commented Dec 28, 2022

This project hasn't progressed as quickly as I'd like it to, but a release with templates is just around the corner.

You've said this many times before. But you have over 500 open issues here and not much communication from your standpoint. Which is why this thread (and others) continue to spiral and people start recommending alternatives. It's your project obviously you are free to do what you want but perhaps a blog or some announcements would be nice. See: #2245

Would you be OK with me going to your repos and commenting on alternatives that I perceive as better?

If the project appears dead/stalled then people will comment alternatives. It's already happening. The fact that you removed the comment without even a word/comment from yourself is the issue. Everyone runs projects differently but if you expect people to not comment alternatives when you aren't giving anyone updates or roadmaps I think that's an unrealistic expectation. You've also left @jorismak comment intact which mentions the same thing? Why?

@Logifire
Copy link

@bmewburn I think it is fair if you make a new version to get paid for it - Like EA FIFA games each year get released with an upgraded version - or Adobe Photoshop Elements…

@jorismak
Copy link

jorismak commented Dec 28, 2022 via email

@jorismak
Copy link

jorismak commented Dec 28, 2022 via email

@aetonsi
Copy link

aetonsi commented Dec 30, 2022

I don't know if the following is related at all to this thread, but i see that @KapitanOczywisty quoted TYield (i don't even know what it is).

I'm having an error Expected type 'string'. Found 'TYield'. with the following (working) code:

function gen() { yield 'aaa'; }

echo (
    fn (): string =>
        gen()
        ->current()
)();

strangely the error goes away if i use an arrow function as generator (the code has the same result though):

echo (
    fn (): string =>
        (fn()=>yield 'aaa')()
        ->current()
)();

Could anyone tell me, is this even related to the thread?

Thanks

@bmewburn
Copy link
Owner Author

bmewburn commented Jan 1, 2023

@aetonsi , yes your issue will be resolved by this.

@bmewburn
Copy link
Owner Author

bmewburn commented Jan 1, 2023

First iteration of templates will be in the 1.9 release. Laravel 9 was used as a base test case. Please open new tickets for bugs/features.

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

No branches or pull requests