|
20 | 20 | import fr.adrienbrault.idea.symfony2plugin.form.FormUnderscoreMethodReference;
|
21 | 21 | import fr.adrienbrault.idea.symfony2plugin.form.util.FormOptionsUtil;
|
22 | 22 | import fr.adrienbrault.idea.symfony2plugin.form.util.FormUtil;
|
| 23 | +import fr.adrienbrault.idea.symfony2plugin.templating.variable.resolver.FormFieldResolver; |
23 | 24 | import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
|
24 | 25 | import kotlin.Pair;
|
25 | 26 | import org.apache.commons.lang3.StringUtils;
|
@@ -60,9 +61,24 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
|
60 | 61 | return;
|
61 | 62 | }
|
62 | 63 |
|
| 64 | + Set<String> alreadyKnownFields = new HashSet<>(); |
| 65 | + String formTypeClassFromScope = FormUtil.getFormTypeClassFromScope(parent); |
| 66 | + if (formTypeClassFromScope != null) { |
| 67 | + PhpClass clazz = PhpElementsUtil.getClassInterface(project, formTypeClassFromScope); |
| 68 | + if (clazz != null) { |
| 69 | + FormFieldResolver.visitFormReferencesFields(clazz, twigTypeContainer -> alreadyKnownFields.add(twigTypeContainer.getStringElement())); |
| 70 | + } |
| 71 | + } |
| 72 | + |
63 | 73 | FormUnderscoreMethodReference.visitPropertyPath(
|
64 | 74 | phpClass,
|
65 |
| - pair -> completionResultSet.addElement(new MyLookupElement(pair.getFirst(), "add", pair.getSecond(), phpClass.getName())) |
| 75 | + pair -> completionResultSet.addElement(new MyLookupElement( |
| 76 | + pair.getFirst(), |
| 77 | + "add", |
| 78 | + pair.getSecond(), |
| 79 | + phpClass.getName(), |
| 80 | + alreadyKnownFields.contains(pair.getFirst()) |
| 81 | + )) |
66 | 82 | );
|
67 | 83 | }
|
68 | 84 | }
|
@@ -140,19 +156,28 @@ private class MyLookupElement extends com.intellij.codeInsight.lookup.LookupElem
|
140 | 156 |
|
141 | 157 | private final PhpNamedElement phpNamedElement;
|
142 | 158 | private final String typeText;
|
| 159 | + private final @NotNull boolean exists; |
143 | 160 |
|
144 |
| - public MyLookupElement(@NotNull String key, @NotNull String lookupElement, @NotNull PhpNamedElement phpNamedElement, @NotNull String typeText) { |
| 161 | + public MyLookupElement(@NotNull String key, @NotNull String lookupElement, @NotNull PhpNamedElement phpNamedElement, @NotNull String typeText, boolean exists) { |
145 | 162 | this.key = key;
|
146 | 163 | this.lookupElement = lookupElement;
|
147 | 164 | this.phpNamedElement = phpNamedElement;
|
148 | 165 | this.typeText = typeText;
|
| 166 | + this.exists = exists; |
149 | 167 | }
|
150 | 168 |
|
151 | 169 | @Override
|
152 | 170 | public void renderElement(@NotNull LookupElementPresentation presentation) {
|
153 | 171 | super.renderElement(presentation);
|
| 172 | + |
| 173 | + if (this.exists) { |
| 174 | + presentation.setTypeText(typeText, Symfony2Icons.SYMFONY_AI_OPACITY); |
| 175 | + presentation.setTypeGrayed(true); |
| 176 | + } else { |
| 177 | + presentation.setTypeText(typeText, Symfony2Icons.SYMFONY_AI); |
| 178 | + } |
| 179 | + |
154 | 180 | presentation.setIcon(phpNamedElement.getIcon());
|
155 |
| - presentation.setTypeText(typeText, Symfony2Icons.SYMFONY); |
156 | 181 | presentation.setTypeIconRightAligned(true);
|
157 | 182 | }
|
158 | 183 |
|
|
0 commit comments