|
7 | 7 | import com.intellij.psi.ResolveResult;
|
8 | 8 | import com.intellij.psi.util.PsiTreeUtil;
|
9 | 9 | import com.jetbrains.php.lang.psi.elements.PhpAttribute;
|
| 10 | +import com.jetbrains.php.lang.psi.elements.PhpClass; |
10 | 11 | import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
|
11 | 12 | import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
|
12 | 13 | import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar;
|
13 | 14 | import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter;
|
14 | 15 | import fr.adrienbrault.idea.symfony2plugin.codeInsight.utils.GotoCompletionUtil;
|
15 | 16 | import fr.adrienbrault.idea.symfony2plugin.config.component.ParameterLookupElement;
|
16 | 17 | import fr.adrienbrault.idea.symfony2plugin.dic.ContainerParameter;
|
| 18 | +import fr.adrienbrault.idea.symfony2plugin.dic.ServiceCompletionProvider; |
17 | 19 | import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
|
18 | 20 | import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
|
19 | 21 | import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
|
|
22 | 24 | import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
|
23 | 25 | import org.jetbrains.annotations.NotNull;
|
24 | 26 |
|
25 |
| -import java.util.ArrayList; |
26 |
| -import java.util.Collection; |
27 |
| -import java.util.Collections; |
28 |
| -import java.util.Map; |
| 27 | +import java.util.*; |
29 | 28 |
|
30 | 29 | /**
|
31 | 30 | * @author Daniel Espendiller <daniel@espendiller.net>
|
@@ -111,6 +110,24 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
|
111 | 110 | return null;
|
112 | 111 | }
|
113 | 112 | );
|
| 113 | + |
| 114 | + // #[Autowire(service: 'some_service')] |
| 115 | + registrar.register( |
| 116 | + PhpElementsUtil.getAttributeNamedArgumentStringPattern(ServiceContainerUtil.AUTOWIRE_ATTRIBUTE_CLASS, "service"), |
| 117 | + psiElement -> { |
| 118 | + PsiElement context = psiElement.getContext(); |
| 119 | + if (!(context instanceof StringLiteralExpression)) { |
| 120 | + return null; |
| 121 | + } |
| 122 | + |
| 123 | + PhpAttribute phpAttribute = PsiTreeUtil.getParentOfType(context, PhpAttribute.class); |
| 124 | + if (phpAttribute != null) { |
| 125 | + return new ServiceContributor((StringLiteralExpression) context); |
| 126 | + } |
| 127 | + |
| 128 | + return null; |
| 129 | + } |
| 130 | + ); |
114 | 131 | }
|
115 | 132 |
|
116 | 133 | private static class ParameterContributor extends GotoCompletionProvider {
|
@@ -165,4 +182,30 @@ public Collection<PsiElement> getPsiTargets(PsiElement element) {
|
165 | 182 | return new ArrayList<>(ServiceUtil.getTaggedClasses(getElement().getProject(), contents));
|
166 | 183 | }
|
167 | 184 | }
|
| 185 | + |
| 186 | + private static class ServiceContributor extends GotoCompletionProvider { |
| 187 | + public ServiceContributor(@NotNull StringLiteralExpression element) { |
| 188 | + super(element); |
| 189 | + } |
| 190 | + |
| 191 | + @Override |
| 192 | + public @NotNull Collection<LookupElement> getLookupElements() { |
| 193 | + return ServiceCompletionProvider.getLookupElements(this.getElement(), ContainerCollectionResolver.getServices(getProject()).values()).getLookupElements(); |
| 194 | + } |
| 195 | + |
| 196 | + @Override |
| 197 | + public @NotNull Collection<PsiElement> getPsiTargets(PsiElement element) { |
| 198 | + String contents = GotoCompletionUtil.getStringLiteralValue(element); |
| 199 | + if (contents == null) { |
| 200 | + return Collections.emptyList(); |
| 201 | + } |
| 202 | + |
| 203 | + PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(element.getProject(), contents); |
| 204 | + if (phpClass == null) { |
| 205 | + return Collections.emptyList(); |
| 206 | + } |
| 207 | + |
| 208 | + return List.of(phpClass); |
| 209 | + } |
| 210 | + } |
168 | 211 | }
|
0 commit comments