IDEA-45809 XML editing: Required attributes should be preferred in completion

This commit is contained in:
Dmitry Avdeev
2013-05-24 10:54:24 +04:00
parent b93f27670e
commit b4045bf7ce
5 changed files with 22 additions and 8 deletions
@@ -85,4 +85,9 @@ public class HtmlAttributeDescriptorImpl implements XmlAttributeDescriptor {
public Object[] getDependences() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
@Override
public String toString() {
return delegate.toString();
}
}
@@ -416,8 +416,6 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute {
return setName(newName);
}
// TODO[ik]: namespace support
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (element instanceof PsiMetaOwner) {
final PsiMetaOwner owner = (PsiMetaOwner)element;
@@ -475,7 +473,8 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute {
if (separator > 0) {
element = element.withLookupString(name.substring(separator + 1));
}
variants.add(element.withCaseSensitivity(caseSensitive).withInsertHandler(XmlAttributeInsertHandler.INSTANCE));
element = element.withCaseSensitivity(caseSensitive).withInsertHandler(XmlAttributeInsertHandler.INSTANCE);
variants.add(descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : element);
}
}
}
@@ -73,4 +73,9 @@ public abstract class BasicXmlAttributeDescriptor implements XmlAttributeDescrip
public boolean isEnumerated(@Nullable XmlElement context) {
return isEnumerated();
}
@Override
public String toString() {
return getName();
}
}
@@ -243,9 +243,4 @@ public class XmlAttributeDescriptorImpl extends BasicXmlAttributeDescriptor impl
public void setName(String name) throws IncorrectOperationException {
NamedObjectDescriptor.setName(myTag, name);
}
@Override
public String toString() {
return getName();
}
}
@@ -636,5 +636,15 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase {
"xsi:noNamespaceSchemaLocation",
"xsi:type");
}
public void testRequiredAttributesOnTop() throws Exception {
myFixture.configureByText("foo.html", "<img <caret>");
myFixture.completeBasic();
List<String> strings = myFixture.getLookupElementStrings();
assertNotNull(strings);
assertEquals("alt", strings.get(0));
assertEquals("src", strings.get(1));
assertEquals("align", strings.get(2));
}
}