pbyrne84 / DynamicReturnTypePlugin

135 stars 7 forks source link

Plugin not supported in IntelliJ 2021.2 #81

Closed stimothy closed 2 years ago

stimothy commented 3 years ago

I can find and click the install button for this plugin and then it prompts me to restart IntelliJ. After restart I check my plugins and this plugin still states that it needs to be installed. I think it might be a compatibility issue with the new release of intellij.

smichaelsen commented 3 years ago

+1

I downgraded to 2021.1 (PhpStorm in my case) to mitigate the problem. https://www.jetbrains.com/phpstorm/download/other.html

pbyrne84 commented 3 years ago

I can look at it next week as I need to setup all my php again etc. I stopped doing php a while back and the phpopenapi within phpstorm etc changes quite a lot as new concepts are brought into PHP. Good concepts I may add as I used to watch all the discussions and work put in to do it.

I think a lot of the functionality of this plugin can now be done by intellij but the documentation on doing this is a bit lacking. I'll see if I can find it and document it in a more friendly fashion to allow people to become less dependant where possible.

If you are relying on the javascript stuff then this is going to be an eventual adventure https://golb.hplar.ch/2020/04/java-javascript-engine.html

Jetbrains does not use graalvm and I am not sure they ever will. org.graalvm.js maybe compatible with non graaljvm but it is such an unknown.

thamrx commented 3 years ago

+1

sirdiego commented 3 years ago

What's strange is that the installation seems to not work but there is no error at all. I'd like to provide more information or help with fixing this, but it just keeps restarting and being uninstalled afterwards. I'd love to be able to use this plugin again :)

sbuerk commented 3 years ago

+1 .. got so used to it, missing is a pain. and repopulate a lot of annotations and intermediate vars is such a pain over all projects :(

I'm no java guy - so having a look is not doable for me :( :( :(

rulatir commented 3 years ago

Huge +1 on this, and we should probably insist that JetBrains simply build this functionality in.

pbyrne84 commented 3 years ago

I have a build on a branch I can upload to this repo later. I believe Jetbrains did do a lot of stuff in this area as Alexey Gopachenko did mention a lot of things this plugin covered. Originally the PHP Openapi was very basic but I remember it getting to the point of being able to do masks etc via configuration in the project.

sbuerk commented 3 years ago

@pbyrne84 My last post should be a "complaint" - it was more to honor your work from the past with that plugin (because it got so mantantory for a lot of peopels).

Normally I would try to help ... but java is something I never ever got used to ;)

So if you need some to test it before release or something just let us know.

thamrx commented 3 years ago

We switched to using .phpstorm.meta.php, see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html.

sirdiego commented 3 years ago

We switched to using .phpstorm.meta.php, see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html.

This does exactly what we used this plugin for! Thank you so much. For the other TYPO3 users in this thread, here is our dynamicReturnTypeMeta.json before and our .phpstorm.meta.php after. Works exactly like before.

dynamicReturnTypeMeta.json (old)

{
  // configuration file for PHPStorm Plugin: http://plugins.jetbrains.com/plugin/7251
  "methodCalls": [
    // Do not add the methods getMock or getAccessibleMock to this configuration
    // because additive type information gets lost. Use comments to define object types.
    {
      "class": "\\TYPO3\\CMS\\Core\\Utility\\GeneralUtility",
      "method": "makeInstance",
      "position": 0
    },
    {
      "class": "\\TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface",
      "method": "get",
      "position": 0
    }
  ],
  "functionCalls": [
  ]
}

.phpstorm.meta.php (new):

<?php declare(strict_types=1);

namespace PHPSTORM_META;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;

override(ObjectManagerInterface::get(0), type(0));
override(GeneralUtility::makeInstance(0), type(0));
sgrossberndt commented 3 years ago

Also see https://github.com/alexanderschnitzler/phpstorm.meta.php-typo3

pbyrne84 commented 3 years ago

@sbuerk So there is a jar now in https://github.com/pbyrne84/DynamicReturnTypePlugin/tree/master/deploy .. this is for 2021.2.1. In plugins you can choose to install from disk to test it out. I tested running from disk and it worked for me but I am using Intellij though this should not make a difference.

It seems to be a lot more picky with versions as I had a 2021.1 build and it complained 2021.2.1 was to new. Annoying as I have not limited it to not be compatible with new versions.

@sgrossberndt, @sirdiego and @thamrx thanks for the references. Really I think Jetbrains should make a bigger point of it on the sales page etc as it is a good feature that I think is possibly too hidden.

sbuerk commented 3 years ago

@pbyrne84 Thanks a lot for your quick work on it.

I have installed it from disk, and started some project and done some minor work, and so far it worked again for now and I can tell.

Anyway what the others mentioned is also nice. Will test that too. I mean - if you wanna more let die this plugin a migration through projects may be a task then - if not -- for customer projects there are other priorities.

Will test it tommorror on a real workday and eventually report back - but for for now it seems to work.

rulatir commented 3 years ago

We switched to using .phpstorm.meta.php, see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html.

This does exactly what we used this plugin for!

No, it doesn't. .phpstorm.meta.php functionality is deficient and fragmentary compared to what this plugin offered. It doesn't support instance methods (static methods ONLY!), and it doesn't support the class name argument at any position other than first.

sirdiego commented 3 years ago

Hey @rulatir,

We switched to using .phpstorm.meta.php, see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html.

This does exactly what we used this plugin for!

No, it doesn't. .phpstorm.meta.php functionality is deficient and fragmentary compared to what this plugin offered. It doesn't support instance methods (static methods IONLY!), and it doesn't support the class name argument at any position other than first.

I'm not quite sure about what you are getting at here. You can't just say "No, it doesn't." when in fact "This does exactly what we used this plugin for!".

It doesn't support instance methods (static methods ONLY!)

Do you mean an instance method of a container for example? Why would you think it can't do it? I just tried and it can.

it doesn't support the class name argument at any position other than first

Well, I think it does, I just tried this as well. Here is the code:

.phpstorm.meta.php

<?php declare(strict_types=1);

namespace PHPSTORM_META;

use App\Container;

override(Container::get(0, 1), type(1));

app.php

<?php declare(strict_types=1);

namespace App;

class Container
{
    protected $registry = [];

    public function get(string $argument1, string $argument2): object
    {
        if ($this->registry[$argument2]) {
            return $this->registry[$argument2];
        }

        $this->registry[$argument2] = new $argument2();
        return $this->registry[$argument2];
    }
}

class Greeter
{
    public function world(string $name = 'world'): string
    {
        return "Hello, ${name}!";
    }
}

$container = new Container();
$greeter = $container->get('unused', Greeter::class);

The $greeter variable is now picked up as type App\Greeter|object, the auto completion and analysis works just as I would expect. When I remove the .phpstorm.meta.php file it stops working because it only knows about the object return type. Maybe have a deeper look into the documentation.

rulatir commented 3 years ago

Which "the documentation"? A dozen versions of documentation seem to exist in a dozen places, disagreeing about what is supported and what isn't. What I found was what any non-stupid programmer with a focused intention to find the answer to the question "what can .phpstorm.meta.php do" would find. If the official documentation is a mess, the features cannot be trusted to be available, and are therefore not there for all intents and purposes. An obscure developer blog post does not count as official documentation.

As I understand "the documentation" (the one that I found), the type() directive can be used to specify that the function returns a value of the same type as the value passed as nth argument, as starkly opposed to a value of the type whose name is passed as a string in the nth argument. If what the documentation says is supposed to mean the former as opposed to the latter, then the documentation is so badly written as to be practically useless.

Also the whole syntax of .phpstorm.meta.php is basically nonsense, it's some weird PHP-that-isn't-actually-php where instead of specifying your intention in an established format like JSON, you encode it in some ad-hoc format that is syntactically PHP, and then it is parsed by IDE's PHP parser and your intention is decoded from there. It's just silly beyond words.

pbyrne84 commented 2 years ago

I made some notes here https://github.com/pbyrne84/phpstorm-metadata-example

The .phpstorm.meta.php files are how jetbrains manage some things internally which I have documented with examples that can be checked out and played with without doing any dependency dance.

Examples of Instance/Class/Mask as parameter are given with examples given for static method calls and instance method calls. In reality it doesn't make any distinction between the two. Also over-ridden methods as well.

stimothy commented 2 years ago

Hey thanks, that phpstorm-meta-example worked for me!. For reference on anyone else that is using MAMP. I didn't have access to the php's .phpstorm.meta.php file since it is stored in the MAMP directory. But creating that file at the root of my project seem to do the trick.