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

Resolve Sub-Containers #10

Closed Sorien closed 9 years ago

Sorien commented 9 years ago
$app['foo'] = $app->share(function () { return new \Pimple(); });
$app['foo']['']->; //autocomplete '', ->, 
Sorien commented 9 years ago

Highly experimental preview https://github.com/Sorien/silex-idea-plugin/releases/tag/0.9.7

CarsonF commented 9 years ago
java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.$$YJP$$arraycopy(Native Method)
    at java.lang.System.arraycopy(System.java)
    at org.json.simple.parser.Yylex.zzRefill(Yylex.java:325)
    at org.json.simple.parser.Yylex.yylex(Yylex.java:541)
    at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
    at sk.sorien.silexplugin.pimple.JsonFileContainer.parse(JsonFileContainer.java:90)
    at sk.sorien.silexplugin.pimple.JsonFileContainer.Load(JsonFileContainer.java:48)
    at sk.sorien.silexplugin.pimple.JsonFileContainer.getServices(JsonFileContainer.java:30)
    at sk.sorien.silexplugin.pimple.ServiceReferenceProvider.getReferencesByElement(ServiceReferenceProvider.java:40)
    at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.doGetReferencesFromProviders(ReferenceProvidersRegistryImpl.java:124)
    at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:70)
    at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:61)
    at com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl.getReferences(StringLiteralExpressionImpl.java:283)
    at com.intellij.psi.PsiReferenceServiceImpl.getReferences(PsiReferenceServiceImpl.java:35)
    at com.intellij.psi.search.SingleTargetRequestResultProcessor.processTextOccurrence(SingleTargetRequestResultProcessor.java:46)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$17.execute(PsiSearchHelperImpl.java:765)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.a(LowLevelSearchUtil.java:126)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.processElementsContainingWordInElement(LowLevelSearchUtil.java:200)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$3$1.compute(PsiSearchHelperImpl.java:214)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$3$1.compute(PsiSearchHelperImpl.java:211)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:884)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$3.process(PsiSearchHelperImpl.java:211)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$3.process(PsiSearchHelperImpl.java:208)
    at com.intellij.concurrency.JobLauncherImpl$2$1.run(JobLauncherImpl.java:105)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:452)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:449)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:449)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.concurrency.JobLauncherImpl$2.run(JobLauncherImpl.java:99)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1098)
    at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:115)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processElementsWithWord(PsiSearchHelperImpl.java:196)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.b(PsiSearchHelperImpl.java:956)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processRequests(PsiSearchHelperImpl.java:618)
    at com.intellij.psi.search.SearchRequestQuery.processResults(SearchRequestQuery.java:45)
    at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:75)
    at com.intellij.util.MergeQuery.processSubQuery(MergeQuery.java:84)
    at com.intellij.util.MergeQuery.forEach(MergeQuery.java:56)
    at com.intellij.util.UniqueResultsQuery.process(UniqueResultsQuery.java:66)
    at com.intellij.util.UniqueResultsQuery.forEach(UniqueResultsQuery.java:56)
    at com.jetbrains.php.lang.psi.PhpPsiUtil.hasReferencesInSearchScope(PhpPsiUtil.java:428)
    at com.jetbrains.php.codeInsight.PhpCodeInsightUtil.isUnused(PhpCodeInsightUtil.java:777)
    at com.jetbrains.php.lang.inspections.PhpUnusedAliasInspection$1.visitPhpUse(PhpUnusedAliasInspection.java:32)
    at com.jetbrains.php.lang.psi.elements.impl.PhpUseImpl.accept(PhpUseImpl.java:47)
    at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:80)
    at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:69)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:285)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.access$200(LocalInspectionsPass.java:75)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:254)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:251)
    at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:122)
    at com.intellij.concurrency.ApplierCompleter.access$000(ApplierCompleter.java:44)
    at com.intellij.concurrency.ApplierCompleter$1.run(ApplierCompleter.java:85)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1098)
    at com.intellij.concurrency.ApplierCompleter$2.run(ApplierCompleter.java:94)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:452)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:449)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:106)
    at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:82)
    at jsr166e.CountedCompleter.exec(CountedCompleter.java:684)
    at jsr166e.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at jsr166e.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:858)
    at jsr166e.ForkJoinPool.scan(ForkJoinPool.java:1687)
    at jsr166e.ForkJoinPool.runWorker(ForkJoinPool.java:1642)
    at jsr166e.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:109)
CarsonF commented 9 years ago
$app['dbs']['foo']->executeQuery();

^ Works beautifully! :+1:


I can't help but bring up the other use case though:

$dbs = $app['dbs'];
$db = $dbs['foo'];

I know this implies keeping track of multiple containers instead of one main one with sub-containers. It may not be possible.

Sorien commented 9 years ago
$dbs = $app['dbs'];
$db = $dbs['foo'];

^ will work out of box i just need to dump subcontainer class type to json file

CarsonF commented 9 years ago

Are you saying that needs to be done on the plugin or I need to redump my pimple.json file? Because I have done that.

Sorien commented 9 years ago

it need to be done on provider and plugin. but its just just few lines of code.

CarsonF commented 9 years ago

Oh just some identifier I gotcha

Sorien commented 9 years ago

yep something like

{
        "name": "dbs",
        "type": "container",
"fqn": "\Pimple" // <-
        "value": [
            {
                "name": "default",
                "type": "class",
                "value": "Doctrine\\DBAL\\Connection"
            }
        ]
    },
CarsonF commented 9 years ago

But how are the sub-containers distinguished then? I don't see how having the FQN helps... doesn't "type": "container" assume FQN is \Pimple?

Sorien commented 9 years ago

hmm, it will just help to resolve proper $dbs type (my bad, just too tired)

$dbs = $app['dbs']; $dbs type is something like $(#S#C\silex\Application[dbs]) that should be resolved by plugin as \Pimple or another type that inherits from \Pimple (not working just now) 
$db = $dbs['foo']; and $db will get signature #S#S#C\Silex\Application[dbs][foo] internaly resolved as base pimple class -> subcontainer dbs -> service/param foo (it should be working just now)

image

so basically they are keeping signature chain from declaration of $app

there is just one problem $b = new \Pimple(); $b[''] // will get autocomplete from pimple.json :) ... but that cant be solved without some advanced code analysis

CarsonF commented 9 years ago

Ah I see what you mean with the signatures. That makes sense.

Yeah I've thought about that too...Like when you are creating the sub-Pimple instance it completes from the main one. Whatevs, that's such a minor caveat for huge help the plugin gives.

Sorien commented 9 years ago

i have released another 0.9.7 version https://github.com/Sorien/silex-idea-plugin/releases/tag/0.9.7

should cover your case :)

class Test {
    const DBS = "dbs";
}

$app = new \Silex\Application();
$a = $app[Test::DBS]; // a resolved as \Pimple 
$b = $a['default']; // working autocomplete inside ['']
$c = $a['default']-> // working autocomplete after ->

and

$app[Test::DBS]->extend('default', function ($c, $d) {
});
CarsonF commented 9 years ago

Awesome! Fixes all the subcontainer resolutions!

Sorien commented 9 years ago

nice! now :beers: :)

CarsonF commented 9 years ago

:beers: Cheers!

Sorien commented 9 years ago

i'll close this thread if you find some bug just open another one