99import com .intellij .codeInsight .completion .CompletionResultSet ;
1010import com .intellij .codeInsight .lookup .LookupElementBuilder ;
1111import 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 ;
1216import com .intellij .util .ProcessingContext ;
1317import com .intellij .util .indexing .FileBasedIndex ;
14- import com .magento .idea .magento2plugin .magento .files .MftfPage ;
15- import com .magento .idea .magento2plugin .stubs .indexes .mftf .PageIndex ;
18+ import com .magento .idea .magento2plugin .magento .files .MftfTest ;
1619import com .magento .idea .magento2plugin .stubs .indexes .mftf .TestNameIndex ;
1720import org .jetbrains .annotations .NotNull ;
1821import java .util .Collection ;
@@ -30,11 +33,32 @@ protected void addCompletions(
3033 return ;
3134 }
3235
33- Collection <String > allKeys
34- = FileBasedIndex .getInstance ().getAllKeys (TestNameIndex .KEY , position .getProject ());
36+ Collection <String > allKeys = FileBasedIndex .getInstance ().getAllKeys (TestNameIndex .KEY , position .getProject ());
3537
38+ String currentTestName = getCurrentTestName ((XmlAttributeValue ) parameters .getPosition ().getParent ());
3639 for (String testName : allKeys ) {
40+ if (testName .equals (currentTestName )) {
41+ continue ;
42+ }
3743 result .addElement (LookupElementBuilder .create (testName ));
3844 }
3945 }
46+
47+ private String getCurrentTestName (XmlAttributeValue xmlAttributeValue ) {
48+ PsiElement xmlAttribute = xmlAttributeValue .getParent ();
49+ XmlTag xmlTag = PsiTreeUtil .getParentOfType (xmlAttribute , XmlTag .class );
50+ if (xmlTag == null ) {
51+ return null ;
52+ }
53+ XmlAttribute nameAttribute = xmlTag .getAttribute (MftfTest .NAME_ATTRIBUTE );
54+ if (nameAttribute == null ) {
55+ return null ;
56+ }
57+ String value = nameAttribute .getValue ();
58+ if (value == null || value .isEmpty ()) {
59+ return null ;
60+ }
61+
62+ return value ;
63+ }
4064}
0 commit comments