9
9
import com .intellij .codeInsight .completion .CompletionResultSet ;
10
10
import com .intellij .codeInsight .lookup .LookupElementBuilder ;
11
11
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 ;
12
16
import com .intellij .util .ProcessingContext ;
13
17
import 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 ;
16
19
import com .magento .idea .magento2plugin .stubs .indexes .mftf .TestNameIndex ;
17
20
import org .jetbrains .annotations .NotNull ;
18
21
import java .util .Collection ;
@@ -30,11 +33,32 @@ protected void addCompletions(
30
33
return ;
31
34
}
32
35
33
- Collection <String > allKeys
34
- = FileBasedIndex .getInstance ().getAllKeys (TestNameIndex .KEY , position .getProject ());
36
+ Collection <String > allKeys = FileBasedIndex .getInstance ().getAllKeys (TestNameIndex .KEY , position .getProject ());
35
37
38
+ String currentTestName = getCurrentTestName ((XmlAttributeValue ) parameters .getPosition ().getParent ());
36
39
for (String testName : allKeys ) {
40
+ if (testName .equals (currentTestName )) {
41
+ continue ;
42
+ }
37
43
result .addElement (LookupElementBuilder .create (testName ));
38
44
}
39
45
}
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
+ }
40
64
}
0 commit comments