1
1
package fr .adrienbrault .idea .symfony2plugin .dic .registrar ;
2
2
3
3
import com .intellij .codeInsight .lookup .LookupElement ;
4
+ import com .intellij .codeInsight .lookup .LookupElementBuilder ;
4
5
import com .intellij .patterns .PlatformPatterns ;
5
6
import com .intellij .psi .PsiElement ;
6
7
import com .intellij .psi .util .PsiTreeUtil ;
7
8
import com .jetbrains .php .lang .psi .elements .PhpAttribute ;
8
9
import com .jetbrains .php .lang .psi .elements .PhpClass ;
9
10
import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
11
+ import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
10
12
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionProvider ;
11
13
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrar ;
12
14
import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrarParameter ;
23
25
import org .jetbrains .annotations .NotNull ;
24
26
25
27
import java .util .*;
28
+ import java .util .function .Function ;
29
+ import java .util .stream .Collectors ;
26
30
27
31
/**
28
32
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -120,26 +124,6 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
120
124
}
121
125
);
122
126
123
- // #[Autoconfigure(tags: ['app.some_tag'])]
124
- // #[Autoconfigure(['app.some_tag'])]
125
- registrar .register (
126
- PlatformPatterns .or (
127
-
128
- ), psiElement -> {
129
- PsiElement context = psiElement .getContext ();
130
- if (!(context instanceof StringLiteralExpression )) {
131
- return null ;
132
- }
133
-
134
- PhpAttribute phpAttribute = PsiTreeUtil .getParentOfType (context , PhpAttribute .class );
135
- if (phpAttribute != null ) {
136
- return new TaggedIteratorContributor ((StringLiteralExpression ) context );
137
- }
138
-
139
- return null ;
140
- }
141
- );
142
-
143
127
// #[Autowire(service: 'some_service')]
144
128
// #[AsDecorator(decorates: 'some_service')]
145
129
registrar .register (
@@ -162,6 +146,20 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
162
146
return null ;
163
147
}
164
148
);
149
+
150
+ // #[When('dev')]
151
+ registrar .register (
152
+ PlatformPatterns .or (
153
+ PhpElementsUtil .getFirstAttributeStringPattern ("\\ Symfony\\ Component\\ DependencyInjection\\ Attribute\\ When" )
154
+ ), psiElement -> new GotoCompletionProvider (psiElement ) {
155
+ @ Override
156
+ public @ NotNull Collection <LookupElement > getLookupElements () {
157
+ return Arrays .stream ((new String []{"prod" , "dev" , "test" }))
158
+ .map ((Function <String , LookupElement >) s -> LookupElementBuilder .create (s ).withIcon (Symfony2Icons .SYMFONY ))
159
+ .collect (Collectors .toList ());
160
+ }
161
+ }
162
+ );
165
163
}
166
164
167
165
private static class ParameterContributor extends GotoCompletionProvider {
0 commit comments