Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#30: Completion. Remove PHP completions from all not appropriate places in XML files #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import com.intellij.util.indexing.FileBasedIndex;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.stubs.indexes.ModuleNameIndex;
import org.jetbrains.annotations.NotNull;

Expand All @@ -38,7 +39,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
result.addElement(
LookupElementBuilder
.create(moduleName)
.withIcon(AllIcons.Modules.ModulesNode)
.withIcon(MagentoIcons.MODULE)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.psi.xml.XmlTokenType;
import com.magento.idea.magento2plugin.completion.provider.*;
import com.magento.idea.magento2plugin.completion.provider.mftf.*;
import com.magento.idea.magento2plugin.magento.files.*;

import static com.intellij.patterns.PlatformPatterns.psiElement;
import static com.intellij.patterns.StandardPatterns.string;
Expand All @@ -18,22 +19,62 @@
public class XmlCompletionContributor extends CompletionContributor {

public XmlCompletionContributor() {
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN),
new CompositeCompletionProvider(
new PhpClassCompletionProvider(),
new PhpClassMemberCompletionProvider(),
new ModuleNameCompletionProvider(),
new FilePathCompletionProvider()
)

/* PHP class member completion provider */
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
.withParent(XmlPatterns.xmlText().withParent(XmlPatterns.xmlTag().withChild(
XmlPatterns.xmlAttribute().withName(CommonXml.SCHEMA_VALIDATE_ATTRIBUTE)
.withValue(string().oneOf(CommonXml.INIT_PARAMETER))))
),
new PhpClassMemberCompletionProvider()
);

/* Module Completion provider */
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(ModuleAclXml.XML_ATTR_ID))
.inFile(xmlFile().withName(string().endsWith(ModuleAclXml.FILE_NAME))),
new ModuleNameCompletionProvider()
);

extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS),
new CompositeCompletionProvider(
new PhpClassCompletionProvider(),
new PhpClassMemberCompletionProvider(),
new ModuleNameCompletionProvider(),
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(ModuleXml.MODULE_ATTR_NAME))
.inFile(xmlFile().withName(string().endsWith(ModuleXml.FILE_NAME))),
new ModuleNameCompletionProvider()
);

/* PHP Class completion provider */

// <randomTag xsi:type="completion">
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
.withParent(XmlPatterns.xmlText().withParent(XmlPatterns.xmlTag().withChild(
XmlPatterns.xmlAttribute().withName(CommonXml.SCHEMA_VALIDATE_ATTRIBUTE).withValue(string().oneOf(CommonXml.OBJECT))))
),
new PhpClassCompletionProvider()
);

// <randomTag class="completion">
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(CommonXml.ATTR_CLASS)),
new PhpClassCompletionProvider()
);

// <preference for="completion">
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(ModuleDiXml.PREFERENCE_ATTR_FOR)),
new PhpClassCompletionProvider()
);

// <type name="completion">
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(ModuleDiXml.PLUGIN_TYPE_ATTR_NAME)
.withParent(XmlPatterns.xmlTag().withName(ModuleDiXml.PLUGIN_TYPE_TAG))),
new PhpClassCompletionProvider()
);

/* File Path Completion provider */
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(LayoutXml.XML_ATTRIBUTE_TEMPLATE)),
new FilePathCompletionProvider()
)
);

extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
Expand Down
12 changes: 12 additions & 0 deletions src/com/magento/idea/magento2plugin/magento/files/CommonXml.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.magento.files;

public class CommonXml {
public static String SCHEMA_VALIDATE_ATTRIBUTE = "xsi:type";
public static String INIT_PARAMETER = "init_parameter";
public static String OBJECT = "object";
public static String ATTR_CLASS = "class";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class LayoutXml {
public static String CacheableAttributeFalseValue = "false";
public static String BlockAttributeTagName = "block";
public static String ReferenceBlockAttributeTagName = "referenceBlock";
public static String XML_ATTRIBUTE_TEMPLATE = "template";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.magento.files;

public class ModuleAclXml {
public static String XML_ATTR_ID = "id";
public static String FILE_NAME = "acl.xml";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class ModuleXml implements ModuleFileInterface {
public static String FILE_NAME = "module.xml";
public static String MODULE_ATTR_NAME = "name";
public static String TEMPLATE = "Magento Module Xml";
private static ModuleXml INSTANCE = null;

Expand Down