Completion: assign highest priority to dsl members in dsl context

Use the same style as for dsl for lookup items that belong to dsl
This commit is contained in:
Pavel V. Talanov
2018-02-09 16:22:37 +01:00
parent 8f8cbfcfa5
commit 1796d40118
13 changed files with 191 additions and 17 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.highlighter.dsl
import com.intellij.ide.highlighter.custom.CustomHighlighterColors.*
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.highlighter.HighlighterExtension
@@ -23,12 +24,7 @@ class DslHighlighterExtension : HighlighterExtension() {
}
override fun highlightCall(elementToHighlight: PsiElement, resolvedCall: ResolvedCall<*>): TextAttributesKey? {
val markerAnnotation = resolvedCall.resultingDescriptor.annotations.find { annotation ->
annotation.annotationClass?.isDslHighlightingMarker() ?: false
}?.annotationClass ?: return null
val styleId = styleIdByMarkerAnnotation(markerAnnotation) ?: return null
return styles[styleId - 1]
return dslCustomTextStyle(resolvedCall.resultingDescriptor)
}
companion object {
@@ -57,6 +53,15 @@ class DslHighlighterExtension : HighlighterExtension() {
val markerAnnotationFqName = markerAnnotation.fqNameSafe
return (markerAnnotationFqName.asString().hashCode() % numStyles).absoluteValue + 1
}
fun dslCustomTextStyle(callableDescriptor: CallableDescriptor): TextAttributesKey? {
val markerAnnotation = callableDescriptor.annotations.find { annotation ->
annotation.annotationClass?.isDslHighlightingMarker() ?: false
}?.annotationClass ?: return null
val styleId = styleIdByMarkerAnnotation(markerAnnotation) ?: return null
return styles[styleId - 1]
}
}
}