Skip to content

Commit 7b8eaf0

Browse files
author
Vitaliy
authored
Merge pull request #219 from eduard13/action-group-extends-completion-same-name
Excluding current ActionGroup for completion when extending it
2 parents 67a169f + 69aeda6 commit 7b8eaf0

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/com/magento/idea/magento2plugin/completion/provider/mftf/ActionGroupCompletionProvider.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
import com.intellij.codeInsight.completion.CompletionResultSet;
1010
import com.intellij.codeInsight.lookup.LookupElementBuilder;
1111
import com.intellij.psi.PsiElement;
12+
import com.intellij.psi.util.PsiTreeUtil;
13+
import com.intellij.psi.xml.XmlAttribute;
14+
import com.intellij.psi.xml.XmlAttributeValue;
15+
import com.intellij.psi.xml.XmlTag;
1216
import com.intellij.util.ProcessingContext;
1317
import com.intellij.util.indexing.FileBasedIndex;
18+
import com.magento.idea.magento2plugin.magento.files.MftfActionGroup;
1419
import com.magento.idea.magento2plugin.stubs.indexes.mftf.ActionGroupIndex;
1520
import org.jetbrains.annotations.NotNull;
1621

@@ -31,9 +36,37 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
3136

3237
Collection<String> selectorNames
3338
= FileBasedIndex.getInstance().getAllKeys(ActionGroupIndex.KEY, position.getProject());
39+
String currentActionGroup = getCurrentActionGroupName((XmlAttributeValue) parameters.getPosition().getParent());
3440

3541
for (String selectorName: selectorNames) {
42+
if (selectorName.equals(currentActionGroup)) {
43+
continue;
44+
}
45+
3646
result.addElement(LookupElementBuilder.create(selectorName));
3747
}
3848
}
49+
50+
private String getCurrentActionGroupName(XmlAttributeValue xmlAttributeValue) {
51+
PsiElement xmlAttribute = xmlAttributeValue.getParent();
52+
XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlAttribute, XmlTag.class);
53+
54+
if (xmlTag == null) {
55+
return null;
56+
}
57+
58+
XmlAttribute nameAttribute = xmlTag.getAttribute(MftfActionGroup.NAME_ATTRIBUTE);
59+
60+
if (nameAttribute == null) {
61+
return null;
62+
}
63+
64+
String value = nameAttribute.getValue();
65+
66+
if (value == null || value.isEmpty()) {
67+
return null;
68+
}
69+
70+
return value;
71+
}
3972
}

src/com/magento/idea/magento2plugin/magento/files/MftfActionGroup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public class MftfActionGroup {
1313
public static String USER_INPUT_TAG = "userInput";
1414
public static String ROOT_TAG = "actionGroup";
1515
public static String URL_ATTRIBUTE = "url";
16+
public static String NAME_ATTRIBUTE = "name";
1617
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="MyActionGroup" extends="MyActionGr<caret>">
11+
</actionGroup>
12+
</actionGroups>

tests/com/magento/idea/magento2plugin/completion/xml/MftfNameCompletionRegistrarTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@ public void testExtendsSameNameMustBeEmpty() {
3131

3232
assertCompletionNotShowing(filePath);
3333
}
34+
35+
public void testExtendsSameNameMustBeEmptyForActionGroup() {
36+
String filePath = this.getFixturePath("TestActionGroup.xml");
37+
myFixture.copyFileToProject(filePath);
38+
39+
assertCompletionNotShowing(filePath);
40+
}
3441
}

0 commit comments

Comments
 (0)