Sorien / silex-idea-plugin

Idea plugin for Silex Framework - plugin is not compatible with PHPStorm 2016.2
MIT License
26 stars 8 forks source link

Support Pimple 3 #38

Closed vladcosorg closed 8 years ago

vladcosorg commented 8 years ago

I'm using this plugin inside a project with standalone Pimple 3, i adapted the dumper in order to get valid pimple.json and so far the plugin works great, the only issue is that the service definition has changed in Pimple 3 from

        $this['controllers'] = $this->share(function () use ($app) {
            return $app['controllers_factory'];
        });
        $this['controllers'] = function () use ($app) {
            return $app['controllers_factory'];
        };

and the $app['controllers_factory']; inside the closure does not get autocompletion and gets marked as error.

Would be great if it supported this use-case!

CarsonF commented 8 years ago

Really the classes need to be broken apart. I've been trying to find some time to work on this.

I'm a derp. I thought this was for the php service provider. Ignore me :)

Sorien commented 8 years ago

hmm I thought pimple 3 is fully supported, can you recheck it with this version http://silex.sorien.sk/download/master ...

vladcosorg commented 8 years ago

Nope, with this version still no autocompletion inside closures, besides in cases where the plugin in repo worked fine (autocompletion outside closures) this one performs much slower and requires explicit Ctrl+Space to show the popup.

Sorien commented 8 years ago

can you show me whole unit/fully working sample couse I can't reproduce it image

btw there should be no performance difference between versions, it contains just few bug fixes, maybe you should try to invalidate caches (File -> Invalidate caches) and wait until all background tasks are finished (like index rebuild)

Sorien commented 8 years ago

i don't understand your sample why are you mixin' $app and $this, according test case https://github.com/Sorien/silex-idea-plugin/blob/master/tests/sk/sorien/silexplugin/tests/pimple/PimplePhpTypeProviderTest.java#L146

plugin should provide correct type for first function parameter when you use this Pimple3 construct (http://pimple.sensiolabs.org/#modifying-services-after-definition)

// $this is pimple container or extends Pimple
  $this['controllers'] = function ($app) { // plugin will provide type for $app var 
            return $app['controllers_factory'];
        };
vladcosorg commented 8 years ago

Sorry, it should be $app, not $this. I will provide more details and a better example soon. Thanks for looking into that!

vladcosorg commented 8 years ago

Here's a better example

<?php

namespace myapp\plugin\service\module\event;

use myapp\plugin\service\Application;
use myapp\plugin\service\ServiceProviderInterface;

class Init implements  ServiceProviderInterface
{

    public function register(Application $app)
    {
        $app['event.post_config'] = function ($app){
            $event = new EventPostConfig($app['param.theme_prefix'], $app['acf_manager'], $app['wpml.manager']);
            return $event;
        };
        $app['event.repo'] = function ($app) {
            return new Repository(Entity::FQCN, 'post');
        };
    }

    public function boot(Application $app)
    {

    }

}

Custom service provider interface

<?php
namespace myapp\plugin\service;

interface ServiceProviderInterface
{
    public function register(Application $app);

    public function boot(Application $app);
}

The Application container extends Pimple\Container

Outside the function scope, the completion works fine selection_005

However inside that's what happens selection_006 and the services are marked as errors $app may not support offset operations

Sorien commented 8 years ago

i can't reproduce it with pimple 1.x will try with 3.x tomorrow ... do you have any other PHP provider plugin installed? are you using PhpStorm or IntelliJ, which version?

image

vladcosorg commented 8 years ago

I've got Symfony plugin if that's what you mean by "Php Provider" and Php Inspections (EA extended). I disabled all non-standart phpstorm plugins, the services marked as errors went away (it was from Php Inspections) but still, the services inside the function are not autocompleted...

Still the plugin is a great time-saver for me even with half of the features! )

Sorien commented 8 years ago

I still can't reproduce it, pls install PsiViewer extension and check Variable signature

it should be something like #Š#C\Application

image

vladcosorg commented 8 years ago

There you go selection_007

Sorien commented 8 years ago

pls try this one http://sorien.sk/silex-plugin.zip

vladcosorg commented 8 years ago

It works! Thanks a lot mate!

I've autoupdated from phpstorm plugin manager, i guess this link contains the same version.

Sorien commented 8 years ago

I am glad to hear that, they're almost same, there is no functional change, just one recursion limiter is set to not so strict value ...