3
3
import com .intellij .codeInsight .lookup .LookupElement ;
4
4
import com .intellij .patterns .PlatformPatterns ;
5
5
import com .intellij .psi .PsiElement ;
6
+ import com .intellij .psi .PsiElementResolveResult ;
7
+ import com .intellij .psi .ResolveResult ;
6
8
import com .intellij .psi .util .PsiTreeUtil ;
7
9
import com .jetbrains .php .lang .psi .elements .PhpAttribute ;
8
10
import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
16
18
import fr .adrienbrault .idea .symfony2plugin .stubs .ContainerCollectionResolver ;
17
19
import fr .adrienbrault .idea .symfony2plugin .util .MethodMatcher ;
18
20
import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
21
+ import fr .adrienbrault .idea .symfony2plugin .util .completion .TagNameCompletionProvider ;
19
22
import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
20
23
import org .jetbrains .annotations .NotNull ;
21
24
@@ -82,10 +85,27 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
82
85
83
86
PhpAttribute phpAttribute = PsiTreeUtil .getParentOfType (context , PhpAttribute .class );
84
87
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 );
89
109
}
90
110
91
111
return null ;
@@ -104,7 +124,7 @@ public ParameterContributor(StringLiteralExpression element) {
104
124
public Collection <LookupElement > getLookupElements () {
105
125
Collection <LookupElement > results = new ArrayList <>();
106
126
107
- for (Map .Entry <String , ContainerParameter > entry : ContainerCollectionResolver .getParameters (getElement ().getProject ()).entrySet ()) {
127
+ for (Map .Entry <String , ContainerParameter > entry : ContainerCollectionResolver .getParameters (getElement ().getProject ()).entrySet ()) {
108
128
results .add (new ParameterLookupElement (entry .getValue ()));
109
129
}
110
130
@@ -115,11 +135,34 @@ public Collection<LookupElement> getLookupElements() {
115
135
@ Override
116
136
public Collection <PsiElement > getPsiTargets (PsiElement element ) {
117
137
String contents = GotoCompletionUtil .getStringLiteralValue (element );
118
- if (contents == null ) {
138
+ if (contents == null ) {
119
139
return Collections .emptyList ();
120
140
}
121
141
122
142
return ServiceUtil .getParameterDefinition (element .getProject (), contents );
123
143
}
124
144
}
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
+ }
125
168
}
0 commit comments