23
23
import org .jetbrains .annotations .NotNull ;
24
24
import org .jetbrains .annotations .Nullable ;
25
25
26
- import java .util .ArrayList ;
27
- import java .util .Collection ;
28
- import java .util .Collections ;
26
+ import java .util .*;
29
27
30
28
/**
31
29
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -81,36 +79,35 @@ public GotoCompletionProvider getProvider(@NotNull PsiElement psiElement) {
81
79
return null ;
82
80
}
83
81
84
- @ Nullable
85
82
private GotoCompletionProvider getMatchingOption (ParameterList parameterList , @ NotNull PsiElement psiElement ) {
86
-
87
83
// form name can be a string alias; also resolve on constants, properties, ...
88
84
PsiElement psiElementAt = PsiElementUtils .getMethodParameterPsiElementAt (parameterList , 1 );
89
85
90
- String formTypeName = null ;
86
+ Set < String > formTypeNames = new HashSet <>() ;
91
87
if (psiElementAt != null ) {
92
88
PhpClass phpClass = FormUtil .getFormTypeClassOnParameter (psiElementAt );
93
89
if (phpClass != null ) {
94
- formTypeName = phpClass .getFQN ();
90
+ formTypeNames . add ( phpClass .getFQN () );
95
91
}
96
92
}
97
93
98
94
// fallback to form
99
- if (formTypeName == null ) {
100
- formTypeName = "form" ;
95
+ if (formTypeNames .size () == 0 ) {
96
+ formTypeNames .add ("form" ); // old Symfony systems
97
+ formTypeNames .add ("Symfony\\ Component\\ Form\\ Extension\\ Core\\ Type\\ FormType" );
101
98
}
102
99
103
- return new FormReferenceCompletionProvider (psiElement , formTypeName );
100
+ return new FormReferenceCompletionProvider (psiElement , formTypeNames );
104
101
}
105
102
}
106
103
107
104
private static class FormReferenceCompletionProvider extends GotoCompletionProvider {
105
+ @ NotNull
106
+ private final Collection <String > formTypes ;
108
107
109
- private final String formType ;
110
-
111
- FormReferenceCompletionProvider (@ NotNull PsiElement element , @ NotNull String formType ) {
108
+ FormReferenceCompletionProvider (@ NotNull PsiElement element , @ NotNull Collection <String > formTypes ) {
112
109
super (element );
113
- this .formType = formType ;
110
+ this .formTypes = formTypes ;
114
111
}
115
112
116
113
@ NotNull
@@ -127,14 +124,21 @@ public Collection<PsiElement> getPsiTargets(PsiElement psiElement) {
127
124
}
128
125
129
126
final Collection <PsiElement > psiElements = new ArrayList <>();
130
- FormOptionsUtil .visitFormOptions (getProject (), formType , new FormOptionTargetVisitor (value , psiElements ));
127
+ for (String formType : formTypes ) {
128
+ FormOptionsUtil .visitFormOptions (getProject (), formType , new FormOptionTargetVisitor (value , psiElements ));
129
+ }
130
+
131
131
return psiElements ;
132
132
}
133
133
134
134
@ NotNull
135
135
public Collection <LookupElement > getLookupElements () {
136
136
Collection <LookupElement > lookupElements = new ArrayList <>();
137
- FormOptionsUtil .visitFormOptions (getProject (), formType , new FormOptionLookupVisitor (lookupElements ));
137
+
138
+ for (String formType : formTypes ) {
139
+ FormOptionsUtil .visitFormOptions (getProject (), formType , new FormOptionLookupVisitor (lookupElements ));
140
+ }
141
+
138
142
return lookupElements ;
139
143
}
140
144
}
0 commit comments