void (final CompletionResultSet result, final XmlAttribute[] attributes, final XmlAttributeDescriptor[] descriptors, XmlAttribute attribute, @Nullable InsertHandler<LookupElement> replacementInsertHandler) { final XmlTag tag = attribute.getParent(); final PsiFile file = tag.getContainingFile(); final XmlExtension extension = XmlExtension.getExtension(file); final String prefix = attribute.getName().contains(":") && XmlAttributeImpl.getRealName(attribute).length() > 0 ? attribute.getNamespacePrefix() + ":" : null; for (XmlAttributeDescriptor descriptor : descriptors) { if (isValidVariant(attribute, descriptor, attributes, extension)) { String name = descriptor.getName(tag); InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE; if (tag instanceof HtmlTag && HtmlUtil.isShortNotationOfBooleanAttributePreferred() && HtmlUtil.isBooleanAttribute(descriptor, tag)) { insertHandler = null; } if (replacementInsertHandler != null) { insertHandler = replacementInsertHandler; } else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) { final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag); if (file instanceof XmlFile && namespace != null && namespace.length() > 0 && !name.contains(":") && tag.getPrefixByNamespace(namespace) == null) { insertHandler = new XmlAttributeInsertHandler(namespace); } } if (prefix == null || name.startsWith(prefix)) { if (prefix != null && name.length() > prefix.length()) { name = descriptor.getName(tag).substring(prefix.length()); } LookupElementBuilder element = LookupElementBuilder.create(name); if (descriptor instanceof PsiPresentableMetaData presentableMetaData) { element = element.withIcon(presentableMetaData.getIcon()); String typeName = presentableMetaData.getTypeName(); if (!StringUtil.isEmpty(typeName)) { element = element.withTypeText(typeName); } } final int separator = name.indexOf(':'); if (separator > 0) { element = element.withLookupString(name.substring(separator + 1)); } element = element .withCaseSensitivity(!(descriptor instanceof HtmlAttributeDescriptorImpl) || ((HtmlAttributeDescriptorImpl)descriptor).isCaseSensitive()) .withInsertHandler(insertHandler); result.addElement( descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element); } } } }