11package fr .adrienbrault .idea .symfony2plugin .dic .registrar ;
22
33import com .intellij .codeInsight .lookup .LookupElement ;
4+ import com .intellij .codeInsight .lookup .LookupElementBuilder ;
45import com .intellij .patterns .PlatformPatterns ;
56import com .intellij .psi .PsiElement ;
67import com .intellij .psi .util .PsiTreeUtil ;
78import com .jetbrains .php .lang .psi .elements .PhpAttribute ;
89import com .jetbrains .php .lang .psi .elements .PhpClass ;
910import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
11+ import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
1012import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionProvider ;
1113import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrar ;
1214import fr .adrienbrault .idea .symfony2plugin .codeInsight .GotoCompletionRegistrarParameter ;
2325import org .jetbrains .annotations .NotNull ;
2426
2527import java .util .*;
28+ import java .util .function .Function ;
29+ import java .util .stream .Collectors ;
2630
2731/**
2832 * @author Daniel Espendiller <daniel@espendiller.net>
@@ -120,26 +124,6 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
120124 }
121125 );
122126
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-
143127 // #[Autowire(service: 'some_service')]
144128 // #[AsDecorator(decorates: 'some_service')]
145129 registrar .register (
@@ -162,6 +146,20 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
162146 return null ;
163147 }
164148 );
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+ );
165163 }
166164
167165 private static class ParameterContributor extends GotoCompletionProvider {
0 commit comments