33import com .intellij .codeInsight .lookup .LookupElement ;
44import com .intellij .patterns .PlatformPatterns ;
55import com .intellij .psi .PsiElement ;
6+ import com .intellij .psi .PsiElementResolveResult ;
7+ import com .intellij .psi .ResolveResult ;
68import com .intellij .psi .util .PsiTreeUtil ;
79import com .jetbrains .php .lang .psi .elements .PhpAttribute ;
810import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
1618import fr .adrienbrault .idea .symfony2plugin .stubs .ContainerCollectionResolver ;
1719import fr .adrienbrault .idea .symfony2plugin .util .MethodMatcher ;
1820import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
21+ import fr .adrienbrault .idea .symfony2plugin .util .completion .TagNameCompletionProvider ;
1922import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
2023import org .jetbrains .annotations .NotNull ;
2124
@@ -82,10 +85,27 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
8285
8386 PhpAttribute phpAttribute = PsiTreeUtil .getParentOfType (context , PhpAttribute .class );
8487 if (phpAttribute != null ) {
85- String fqn = phpAttribute .getFQN ();
86- if (fqn != null && PhpElementsUtil .isInstanceOf (psiElement .getProject (), fqn , ServiceContainerUtil .AUTOWIRE_ATTRIBUTE_CLASS )) {
87- return new ParameterContributor ((StringLiteralExpression ) context );
88- }
88+ return new ParameterContributor ((StringLiteralExpression ) context );
89+ }
90+
91+ return null ;
92+ }
93+ );
94+
95+ // #[TaggedIterator('app.handler')] iterable $handlers
96+ registrar .register (
97+ PlatformPatterns .or (
98+ PhpElementsUtil .getFirstAttributeStringPattern (ServiceContainerUtil .TAGGET_ITERATOR_ATTRIBUTE_CLASS ),
99+ PhpElementsUtil .getAttributeNamedArgumentStringPattern (ServiceContainerUtil .TAGGET_ITERATOR_ATTRIBUTE_CLASS , "tag" )
100+ ), psiElement -> {
101+ PsiElement context = psiElement .getContext ();
102+ if (!(context instanceof StringLiteralExpression )) {
103+ return null ;
104+ }
105+
106+ PhpAttribute phpAttribute = PsiTreeUtil .getParentOfType (context , PhpAttribute .class );
107+ if (phpAttribute != null ) {
108+ return new TaggedIteratorContributor ((StringLiteralExpression ) context );
89109 }
90110
91111 return null ;
@@ -104,7 +124,7 @@ public ParameterContributor(StringLiteralExpression element) {
104124 public Collection <LookupElement > getLookupElements () {
105125 Collection <LookupElement > results = new ArrayList <>();
106126
107- for (Map .Entry <String , ContainerParameter > entry : ContainerCollectionResolver .getParameters (getElement ().getProject ()).entrySet ()) {
127+ for (Map .Entry <String , ContainerParameter > entry : ContainerCollectionResolver .getParameters (getElement ().getProject ()).entrySet ()) {
108128 results .add (new ParameterLookupElement (entry .getValue ()));
109129 }
110130
@@ -115,11 +135,34 @@ public Collection<LookupElement> getLookupElements() {
115135 @ Override
116136 public Collection <PsiElement > getPsiTargets (PsiElement element ) {
117137 String contents = GotoCompletionUtil .getStringLiteralValue (element );
118- if (contents == null ) {
138+ if (contents == null ) {
119139 return Collections .emptyList ();
120140 }
121141
122142 return ServiceUtil .getParameterDefinition (element .getProject (), contents );
123143 }
124144 }
145+
146+ private static class TaggedIteratorContributor extends GotoCompletionProvider {
147+ public TaggedIteratorContributor (StringLiteralExpression element ) {
148+ super (element );
149+ }
150+
151+ @ NotNull
152+ @ Override
153+ public Collection <LookupElement > getLookupElements () {
154+ return TagNameCompletionProvider .getTagLookupElements (getElement ().getProject ());
155+ }
156+
157+ @ NotNull
158+ @ Override
159+ public Collection <PsiElement > getPsiTargets (PsiElement element ) {
160+ String contents = GotoCompletionUtil .getStringLiteralValue (element );
161+ if (contents == null ) {
162+ return Collections .emptyList ();
163+ }
164+
165+ return new ArrayList <>(ServiceUtil .getTaggedClasses (getElement ().getProject (), contents ));
166+ }
167+ }
125168}
0 commit comments