1616import com .jetbrains .php .lang .psi .elements .PhpClass ;
1717import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
1818import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
19+ import fr .adrienbrault .idea .symfony2plugin .intentions .php .AddRouteAttributeIntention ;
1920import fr .adrienbrault .idea .symfony2plugin .util .CodeUtil ;
2021import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
2122import org .apache .commons .lang3 .StringUtils ;
2223import org .jetbrains .annotations .NotNull ;
2324
25+ import java .util .ArrayList ;
26+ import java .util .Collection ;
27+
2428/**
2529 * Provides completion for Symfony PHP attributes like #[Route()]
2630 *
@@ -65,6 +69,23 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
6569 return ;
6670 }
6771
72+ Collection <LookupElement > lookupElements = new ArrayList <>();
73+
74+ PhpClass containingClass = method .getContainingClass ();
75+ if (containingClass != null && AddRouteAttributeIntention .isControllerClass (containingClass )) {
76+ lookupElements .addAll (getControllerCompletions (project ));
77+ }
78+
79+ // Stop here - don't show other completions when typing "#" for attributes
80+ if (!lookupElements .isEmpty ()) {
81+ result .addAllElements (lookupElements );
82+ result .stopHere ();
83+ }
84+ }
85+
86+ private Collection <LookupElement > getControllerCompletions (@ NotNull Project project ) {
87+ Collection <LookupElement > lookupElements = new ArrayList <>();
88+
6889 // Add Route attribute completion
6990 if (PhpElementsUtil .getClassInterface (project , ROUTE_ATTRIBUTE_FQN ) != null ) {
7091 LookupElement routeLookupElement = LookupElementBuilder
@@ -74,7 +95,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
7495 .withInsertHandler (new PhpAttributeInsertHandler (ROUTE_ATTRIBUTE_FQN , CursorPosition .INSIDE_QUOTES ))
7596 .bold ();
7697
77- result . addElement (routeLookupElement );
98+ lookupElements . add (routeLookupElement );
7899 }
79100
80101 // Add IsGranted attribute completion
@@ -86,7 +107,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
86107 .withInsertHandler (new PhpAttributeInsertHandler (IS_GRANTED_ATTRIBUTE_FQN , CursorPosition .INSIDE_QUOTES ))
87108 .bold ();
88109
89- result . addElement (isGrantedLookupElement );
110+ lookupElements . add (isGrantedLookupElement );
90111 }
91112
92113 // Add Cache attribute completion
@@ -98,11 +119,10 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
98119 .withInsertHandler (new PhpAttributeInsertHandler (CACHE_ATTRIBUTE_FQN , CursorPosition .INSIDE_PARENTHESES ))
99120 .bold ();
100121
101- result . addElement (cacheLookupElement );
122+ lookupElements . add (cacheLookupElement );
102123 }
103124
104- // Stop here - don't show other completions when typing "#" for attributes
105- result .stopHere ();
125+ return lookupElements ;
106126 }
107127
108128 /**
0 commit comments