The completion cannot be triggered at the end of XmlAttributeValue.
Answered
When I use CompletionContributor to implement an XML attribute completion similar to the HTML class attribute, the consecutive completions are triggered normally after I trigger one completion.
However, when I return to the end of this attribute from elsewhere and input characters, the completions cannot be popped up normally.
The following is the code
private val INSTANCE = AddSpaceInsertHandler(true)
class XmlTagAttributeCompletionContributor: CompletionContributor() {
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
if(parameters.completionType != CompletionType.BASIC) {
return
}
// attribute value
val position = parameters.originalPosition ?: return
val context = position.context
if(context == null || context !is XmlAttributeValue){
return
}
// attribute
val attribute = context.parentOfType<XmlAttribute>() ?: return
val attributeName = attribute.name
// tag
val tag = attribute.parentOfType<XmlTag>() ?: return
val tagName = tag.name
if(shouldAddElement(tagName,attributeName)){
val offset = parameters.offset
val map = getPresetAttributeValues(tagName, attributeName,context,offset) ?: return
result.addAllElements(
map.map{
PrioritizedLookupElement.withPriority(
LookupElementBuilder.create(it.key)
.withCaseSensitivity(false)
.withInsertHandler(INSTANCE)
.withTypeText(it.value),
Double.MAX_VALUE
)
}
)
}
}
}
Please sign in to leave a comment.
Hi,
Did you try to debug it? Where does it stop executing?
Thank you for your reply.
However, I solved this problem through
result.withPrefixMatcher(prefix)andresult.restartCompletionOnAnyPrefixChange()