Skip to content

Commit e74f630

Browse files
dkvashninbaylenaorobei
authored andcommitted
Improved argument name completion in di configuration
Added reference/completion supprot for arguments with string type as a possible object type Fixed Already disposed issue with dumb project (cherry picked from commit 8858bab)
1 parent ce71c46 commit e74f630

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin version="2">
22
<id>com.magento.idea.magento2plugin</id>
33
<name>Magento2</name>
4-
<version>0.2.1</version>
4+
<version>0.2.2</version>
55
<vendor email="[email protected]" url="https://github.com/dkvashninbay/magento2plugin">Dmytro Kvashnin</vendor>
66

77
<description><![CDATA[

magento2plugin.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<exclude-output />
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
89
</content>
910
<orderEntry type="inheritedJdk" />
1011
<orderEntry type="sourceFolder" forTests="false" />

src/com/magento/idea/magento2plugin/php/module/MagentoComponentManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public <T extends MagentoComponent> Collection<T> getAllComponentsOfType(@NotNul
5858
}
5959

6060
synchronized private Map<String, MagentoComponent> getComponents() {
61-
if (DumbService.getInstance(project).isDumb()) {
61+
if (DumbService.getInstance(project).isDumb() || project.isDisposed()) {
6262
return new HashMap<>();
6363
}
6464

src/com/magento/idea/magento2plugin/xml/di/XmlHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public class XmlHelper extends XmlHelperUtility {
1616
public static final String VIRTUAL_TYPE_TAG = "virtualType";
1717
public static final String PREFERENCE_TAG = "preference";
1818
public static final String ARGUMENT_TAG = "argument";
19+
public static final String ARGUMENTS_TAG = "arguments";
1920

2021
public static final String NAME_ATTRIBUTE = "name";
2122
public static final String TYPE_ATTRIBUTE = "type";
2223
public static final String FOR_ATTRIBUTE = "for";
2324

2425
public static final String OBJECT_TYPE = "object";
26+
public static final String STRING_TYPE = "string";
2527
public static final String CONST_TYPE = "const";
2628
public static final String INIT_TYPE = "init_parameter";
2729

src/com/magento/idea/magento2plugin/xml/di/completion/DiCompletionContributor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public DiCompletionContributor() {
3737
extend(CompletionType.BASIC,
3838
XmlPatterns.or(
3939
XmlHelper.getItemValuePatternForType(XmlHelper.OBJECT_TYPE),
40+
XmlHelper.getItemValuePatternForType(XmlHelper.STRING_TYPE),
4041
XmlHelper.getTagAttributePattern(XmlHelper.TYPE_TAG, XmlHelper.NAME_ATTRIBUTE),
4142
XmlHelper.getTagAttributePattern(XmlHelper.VIRTUAL_TYPE_TAG, XmlHelper.TYPE_ATTRIBUTE),
4243
XmlHelper.getTagAttributePattern(XmlHelper.PLUGIN_TAG, XmlHelper.TYPE_ATTRIBUTE)

src/com/magento/idea/magento2plugin/xml/di/reference/ArgumentNameReference.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import com.intellij.psi.PsiElementResolveResult;
88
import com.intellij.psi.PsiPolyVariantReferenceBase;
99
import com.intellij.psi.ResolveResult;
10+
import com.intellij.psi.xml.XmlTag;
1011
import com.jetbrains.php.PhpIcons;
1112
import com.jetbrains.php.PhpIndex;
1213
import com.jetbrains.php.lang.psi.elements.Method;
1314
import com.jetbrains.php.lang.psi.elements.Parameter;
1415
import com.jetbrains.php.lang.psi.elements.PhpClass;
16+
import com.magento.idea.magento2plugin.xml.di.XmlHelper;
1517
import org.jetbrains.annotations.NotNull;
1618

1719
import java.util.ArrayList;
@@ -23,11 +25,13 @@
2325
* Created by dkvashnin on 10/18/15.
2426
*/
2527
public class ArgumentNameReference extends PsiPolyVariantReferenceBase<PsiElement> {
28+
private XmlTag typeTag;
2629
private String typeName;
2730

28-
public ArgumentNameReference(@NotNull PsiElement psiElement, @NotNull String typeName) {
31+
public ArgumentNameReference(@NotNull PsiElement psiElement, @NotNull XmlTag typeTag, @NotNull String typeName) {
2932
super(psiElement);
3033

34+
this.typeTag = typeTag;
3135
this.typeName = typeName;
3236
}
3337

@@ -50,10 +54,17 @@ public ResolveResult[] multiResolve(boolean b) {
5054
@Override
5155
public Object[] getVariants() {
5256
List<LookupElement> variants = new ArrayList<LookupElement>();
57+
List<String> definedArguments = getAlreadyConfiguredArguments();
58+
5359
for (Parameter parameter: getParameters()) {
60+
String argumentName = parameter.getName();
61+
if (definedArguments.contains(argumentName)) {
62+
continue;
63+
}
64+
5465
variants.add(
5566
LookupElementBuilder
56-
.create(parameter.getName())
67+
.create(argumentName)
5768
.withIcon(PhpIcons.PARAMETER)
5869
.withTypeText(parameter.getDeclaredType().toStringResolved())
5970
);
@@ -80,4 +91,22 @@ private List<Parameter> getParameters() {
8091

8192
return parameterList;
8293
}
94+
95+
private List<String> getAlreadyConfiguredArguments()
96+
{
97+
List<String> result = new ArrayList<>();
98+
99+
XmlTag argumentsTag = typeTag.findFirstSubTag(XmlHelper.ARGUMENTS_TAG);
100+
if (argumentsTag == null) {
101+
return result;
102+
}
103+
104+
for (XmlTag argumentTag: argumentsTag.findSubTags(XmlHelper.ARGUMENT_TAG)) {
105+
result.add(
106+
argumentTag.getAttributeValue(XmlHelper.NAME_ATTRIBUTE)
107+
);
108+
}
109+
110+
return result;
111+
}
83112
}

src/com/magento/idea/magento2plugin/xml/di/reference/provider/ArgumentNameReferenceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No
4040
continue;
4141
}
4242

43-
return new PsiReference[]{new ArgumentNameReference(psiElement, typeName)};
43+
return new PsiReference[]{new ArgumentNameReference(psiElement, typeTag, typeName)};
4444
}
4545

4646
return new PsiReference[0];

0 commit comments

Comments
 (0)