Skip to content

Commit 56f9353

Browse files
committed
missing service argument inspection should only visit the working context for yaml
1 parent 9f0218e commit 56f9353

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceArgumentInspection.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import com.intellij.openapi.project.Project;
55
import com.intellij.psi.PsiElement;
66
import com.intellij.psi.PsiElementVisitor;
7-
import com.intellij.psi.PsiFile;
87
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
98
import fr.adrienbrault.idea.symfony2plugin.action.ServiceActionUtil;
109
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
1110
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
1211
import org.jetbrains.annotations.NotNull;
13-
import org.jetbrains.yaml.psi.YAMLFile;
1412
import org.jetbrains.yaml.psi.YAMLKeyValue;
1513
import org.jetbrains.yaml.psi.YAMLMapping;
1614

@@ -49,30 +47,30 @@ private static class MyPsiElementVisitor extends PsiElementVisitor {
4947
}
5048

5149
@Override
52-
public void visitFile(PsiFile file) {
53-
if(!(file instanceof YAMLFile)) {
54-
return;
55-
}
56-
57-
for (ServiceActionUtil.ServiceYamlContainer serviceYamlContainer : ServiceActionUtil.getYamlContainerServiceArguments((YAMLFile) file)) {
58-
59-
// we dont support parent services for now
60-
if("_defaults".equalsIgnoreCase(serviceYamlContainer.getServiceKey().getKeyText()) || !isValidService(serviceYamlContainer)) {
61-
continue;
62-
}
63-
64-
List<String> yamlMissingArgumentTypes = ServiceActionUtil.getYamlMissingArgumentTypes(problemsHolder.getProject(), serviceYamlContainer, false, getLazyServiceCollector(problemsHolder.getProject()));
65-
if(yamlMissingArgumentTypes.size() > 0) {
66-
problemsHolder.registerProblem(serviceYamlContainer.getServiceKey().getFirstChild(), "Missing argument", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new YamlArgumentQuickfix());
50+
public void visitElement(@NotNull PsiElement element) {
51+
if (element instanceof YAMLKeyValue yamlKeyValue && yamlKeyValue.getParent() instanceof YAMLMapping yamlMapping && yamlMapping.getParent() instanceof YAMLKeyValue yamlKeyValue1 && "services".equals(yamlKeyValue1.getKeyText())) {
52+
// we don't support parent services for now
53+
if (!"_defaults".equalsIgnoreCase(yamlKeyValue.getKeyText()) && isValidService(yamlKeyValue)) {
54+
ServiceActionUtil.ServiceYamlContainer container = ServiceActionUtil.ServiceYamlContainer.create(yamlKeyValue);
55+
if (container != null) {
56+
List<String> yamlMissingArgumentTypes = ServiceActionUtil.getYamlMissingArgumentTypes(
57+
problemsHolder.getProject(),
58+
container,
59+
false,
60+
getLazyServiceCollector(problemsHolder.getProject())
61+
);
62+
63+
if (yamlMissingArgumentTypes.size() > 0) {
64+
problemsHolder.registerProblem(yamlKeyValue.getFirstChild(), "Missing argument", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new YamlArgumentQuickfix());
65+
}
66+
}
6767
}
6868
}
6969

70-
this.lazyServiceCollector = null;
70+
super.visitElement(element);
7171
}
7272

73-
private boolean isValidService(ServiceActionUtil.ServiceYamlContainer serviceYamlContainer) {
74-
YAMLKeyValue serviceKey = serviceYamlContainer.getServiceKey();
75-
73+
private boolean isValidService(@NotNull YAMLKeyValue serviceKey) {
7674
Set<String> keySet = YamlHelper.getKeySet(serviceKey);
7775
if(keySet == null) {
7876
return true;
@@ -88,9 +86,7 @@ private boolean isValidService(ServiceActionUtil.ServiceYamlContainer serviceYam
8886
Boolean serviceAutowire = YamlHelper.getYamlKeyValueAsBoolean(serviceKey, "autowire");
8987
if(serviceAutowire != null) {
9088
// use service scope for autowire
91-
if(serviceAutowire) {
92-
return false;
93-
}
89+
return !serviceAutowire;
9490
} else {
9591
// find file scope defaults
9692
// defaults: [autowire: true]
@@ -99,9 +95,7 @@ private boolean isValidService(ServiceActionUtil.ServiceYamlContainer serviceYam
9995
YAMLKeyValue defaults = YamlHelper.getYamlKeyValue(key, "_defaults");
10096
if(defaults != null) {
10197
Boolean autowire = YamlHelper.getYamlKeyValueAsBoolean(defaults, "autowire");
102-
if(autowire != null && autowire) {
103-
return false;
104-
}
98+
return autowire == null || !autowire;
10599
}
106100
}
107101
}

0 commit comments

Comments
 (0)