Skip to content

Commit aea6433

Browse files
author
Vitaliy
authored
Merge pull request #148 from magento/105-fixed-page-url-autocomplete
MFTF. Fixed page URL reference and completion, added test coverage
2 parents dc0d014 + 603c6b6 commit aea6433

File tree

35 files changed

+547
-11
lines changed

35 files changed

+547
-11
lines changed

src/com/magento/idea/magento2plugin/actions/generation/CreateAPluginAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public void update(AnActionEvent event) {
4444
Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
4545
PsiFile psiFile = pair.getFirst();
4646
PhpClass phpClass = pair.getSecond();
47+
if (phpClass == null || psiFile == null) {
48+
return;
49+
}
4750
targetClass = phpClass;
4851
if (!(psiFile instanceof PhpFile) || phpClass.isFinal() || this.targetMethod == null) {
4952
this.setStatus(event, false);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.completion.provider.mftf;
26

37
import com.intellij.codeInsight.completion.CompletionParameters;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.completion.provider.mftf;
26

37
import com.intellij.codeInsight.completion.CompletionParameters;
@@ -9,7 +13,6 @@
913
import com.intellij.util.indexing.FileBasedIndex;
1014
import com.magento.idea.magento2plugin.stubs.indexes.mftf.DataIndex;
1115
import org.jetbrains.annotations.NotNull;
12-
1316
import java.util.Collection;
1417

1518
public class DataCompletionProvider extends CompletionProvider<CompletionParameters> {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.completion.provider.mftf;
6+
7+
import com.intellij.codeInsight.completion.CompletionParameters;
8+
import com.intellij.codeInsight.completion.CompletionProvider;
9+
import com.intellij.codeInsight.completion.CompletionResultSet;
10+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
11+
import com.intellij.psi.PsiElement;
12+
import com.intellij.util.ProcessingContext;
13+
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;
16+
import org.jetbrains.annotations.NotNull;
17+
import java.util.Collection;
18+
19+
public class PageCompletionProvider extends CompletionProvider<CompletionParameters> {
20+
21+
@Override
22+
protected void addCompletions(
23+
@NotNull CompletionParameters parameters,
24+
ProcessingContext context,
25+
@NotNull CompletionResultSet result) {
26+
PsiElement position = parameters.getPosition().getOriginalElement();
27+
28+
if (position == null) {
29+
return;
30+
}
31+
32+
Collection<String> allKeys
33+
= FileBasedIndex.getInstance().getAllKeys(PageIndex.KEY, position.getProject());
34+
35+
for (String pageName: allKeys) {
36+
result.addElement(LookupElementBuilder.create(
37+
pageName
38+
+ MftfPage.REFERENCE_SEPARATOR
39+
+ MftfPage.URL_ATTRIBUTE
40+
));
41+
}
42+
}
43+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.completion.provider.mftf;
26

37
import com.intellij.codeInsight.completion.CompletionParameters;
@@ -9,7 +13,6 @@
913
import com.intellij.util.indexing.FileBasedIndex;
1014
import com.magento.idea.magento2plugin.stubs.indexes.mftf.SectionIndex;
1115
import org.jetbrains.annotations.NotNull;
12-
1316
import java.util.Collection;
1417

1518
public class SelectorCompletionProvider extends CompletionProvider<CompletionParameters> {

src/com/magento/idea/magento2plugin/completion/xml/XmlCompletionContributor.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,37 @@ public XmlCompletionContributor() {
227227
new ActionGroupCompletionProvider()
228228
);
229229

230+
// mftf page url completion contributor
231+
extend(
232+
CompletionType.BASIC,
233+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
234+
.inside(
235+
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
236+
.withParent(XmlPatterns.xmlTag().withParent(
237+
XmlPatterns.xmlTag().withName(
238+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
239+
)))
240+
),
241+
new PageCompletionProvider()
242+
);
243+
extend(
244+
CompletionType.BASIC,
245+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
246+
.inside(
247+
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
248+
.withParent(XmlPatterns.xmlTag().withParent(
249+
XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(
250+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
251+
))))
252+
),
253+
new PageCompletionProvider()
254+
);
255+
230256
// mftf data entity completion contributor
231257
extend(
232258
CompletionType.BASIC,
233259
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
234-
.inside(XmlPatterns.xmlAttribute().withName(string().oneOf("entity", "value", "userInput", "url"))
260+
.inside(XmlPatterns.xmlAttribute().withName(string().oneOf("entity", "value", "userInput"))
235261
),
236262
new DataCompletionProvider()
237263
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public class MftfActionGroup {
1111
public static String CREATE_DATA_TAG = "createData";
1212
public static String UPDATE_DATA_TAG = "updateData";
1313
public static String USER_INPUT_TAG = "userInput";
14+
public static String ROOT_TAG = "actionGroup";
15+
public static String URL_ATTRIBUTE = "url";
1416
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.magento.files;
6+
7+
public class MftfPage {
8+
9+
public static String ROOT_TAG = "pages";
10+
public static String PAGE_TAG = "page";
11+
public static String NAME_ATTRIBUTE = "name";
12+
public static String REFERENCE_SEPARATOR = ".";
13+
public static String URL_ATTRIBUTE = "url";
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.magento.files;
6+
7+
public class MftfTest {
8+
9+
public static String ROOT_TAG = "test";
10+
}

src/com/magento/idea/magento2plugin/reference/xml/XmlReferenceContributor.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import com.intellij.psi.PsiReferenceRegistrar;
1010
import com.intellij.psi.xml.XmlTokenType;
1111
import com.magento.idea.magento2plugin.magento.files.MftfActionGroup;
12+
import com.magento.idea.magento2plugin.magento.files.MftfTest;
1213
import com.magento.idea.magento2plugin.php.util.PhpRegex;
1314
import com.magento.idea.magento2plugin.reference.provider.*;
1415
import com.magento.idea.magento2plugin.reference.provider.mftf.*;
16+
import com.magento.idea.magento2plugin.util.Regex;
1517
import org.jetbrains.annotations.NotNull;
1618

1719
import static com.intellij.patterns.XmlPatterns.*;
@@ -161,15 +163,43 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
161163
// <someXmlTag userInput="{{someValue}}" />
162164
registrar.registerReferenceProvider(
163165
XmlPatterns.xmlAttributeValue().withValue(
164-
string().matches(".*\\{\\{[^\\}]+\\}\\}.*")
166+
string().matches(Regex.MFTF_CURLY_BRACES)
165167
).withParent(XmlPatterns.xmlAttribute().withName(
166-
MftfActionGroup.USER_INPUT_TAG
168+
MftfActionGroup.USER_INPUT_TAG
167169
)),
168170
new CompositeReferenceProvider(
169171
new DataReferenceProvider()
170172
)
171173
);
172174

175+
// <someXmlTag url="{{someValue}}" /> in MFTF Tests and ActionGroups
176+
registrar.registerReferenceProvider(
177+
XmlPatterns.xmlAttributeValue().withValue(
178+
string().matches(Regex.MFTF_CURLY_BRACES)
179+
).withParent(XmlPatterns.xmlAttribute().withName(
180+
MftfActionGroup.URL_ATTRIBUTE
181+
).withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withName(
182+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
183+
)))),
184+
new CompositeReferenceProvider(
185+
new PageReferenceProvider()
186+
)
187+
);
188+
registrar.registerReferenceProvider(
189+
XmlPatterns.xmlAttributeValue().withValue(
190+
string().matches(Regex.MFTF_CURLY_BRACES)
191+
).withParent(XmlPatterns.xmlAttribute().withName(
192+
MftfActionGroup.URL_ATTRIBUTE
193+
).withParent(XmlPatterns.xmlTag().withParent(XmlPatterns.xmlTag().withParent(
194+
XmlPatterns.xmlTag().withName(
195+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
196+
)
197+
)))),
198+
new CompositeReferenceProvider(
199+
new PageReferenceProvider()
200+
)
201+
);
202+
173203
// <createData entity="SimpleProduct" />
174204
// <updateData entity="SimpleProduct" />
175205
registrar.registerReferenceProvider(

0 commit comments

Comments
 (0)