Completion: bold members from immediate class
This commit is contained in:
@@ -80,7 +80,7 @@ public object TipsManager{
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
val mask = kindFilter.withoutKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK).exclude(DescriptorKindExclude.Extensions)
|
||||
for (variant in SmartCastUtils.getSmartCastVariants(receiverValue, context, dataFlowInfo)) {
|
||||
for (variant in SmartCastUtils.getSmartCastVariantsWithLessSpecificExcluded(receiverValue, context, dataFlowInfo)) {
|
||||
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,19 +35,25 @@ import org.jetbrains.jet.lang.resolve.java.JavaResolverUtils
|
||||
import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement
|
||||
|
||||
public object KotlinLookupElementFactory {
|
||||
public fun createLookupElement(analyzer: KotlinCodeAnalyzer, descriptor: DeclarationDescriptor): LookupElement {
|
||||
public fun createLookupElement(analyzer: KotlinCodeAnalyzer, descriptor: DeclarationDescriptor, boldImmediateMembers: Boolean): LookupElement {
|
||||
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
||||
DescriptorUtils.unwrapFakeOverride(descriptor)
|
||||
else
|
||||
descriptor
|
||||
return createLookupElement(analyzer, _descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor))
|
||||
val bold = boldImmediateMembers && descriptor is CallableMemberDescriptor && descriptor.getKind() == CallableMemberDescriptor.Kind.DECLARATION
|
||||
return createLookupElement(analyzer, _descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor), bold)
|
||||
}
|
||||
|
||||
public fun createLookupElementForJavaClass(psiClass: PsiClass): LookupElement {
|
||||
return JavaPsiClassReferenceElement(psiClass).setInsertHandler(KotlinClassInsertHandler)
|
||||
}
|
||||
|
||||
private fun createLookupElement(analyzer: KotlinCodeAnalyzer, descriptor: DeclarationDescriptor, declaration: PsiElement?): LookupElement {
|
||||
private fun createLookupElement(
|
||||
analyzer: KotlinCodeAnalyzer,
|
||||
descriptor: DeclarationDescriptor,
|
||||
declaration: PsiElement?,
|
||||
bold: Boolean
|
||||
): LookupElement {
|
||||
if (descriptor is ClassifierDescriptor &&
|
||||
declaration is PsiClass &&
|
||||
declaration !is KotlinLightClass &&
|
||||
@@ -92,6 +98,10 @@ public object KotlinLookupElementFactory {
|
||||
element = element.withStrikeoutness(true)
|
||||
}
|
||||
|
||||
if (bold) {
|
||||
element = element.withBoldness(true)
|
||||
}
|
||||
|
||||
val insertHandler = getDefaultInsertHandler(descriptor)
|
||||
element = element.withInsertHandler(insertHandler)
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class LookupElementsCollector(
|
||||
|
||||
public fun addDescriptorElements(descriptor: DeclarationDescriptor, suppressAutoInsertion: Boolean) {
|
||||
run {
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor)
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor, true)
|
||||
if (suppressAutoInsertion) {
|
||||
addElementWithAutoInsertionSuppressed(lookupElement)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class LookupElementsCollector(
|
||||
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(parameterType)) {
|
||||
val parameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(parameterType).size()
|
||||
if (parameterCount > 1) {
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor)
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor, true)
|
||||
addElement(object : LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
override fun renderElement(presentation: LookupElementPresentation) {
|
||||
super.renderElement(presentation)
|
||||
|
||||
@@ -55,7 +55,7 @@ object PackageDirectiveCompletion {
|
||||
|
||||
val variants = TipsManager.getPackageReferenceVariants(ref.expression, bindingContext, prefixMatcher.asNameFilter())
|
||||
for (variant in variants) {
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant)
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant, false)
|
||||
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||
result.addElement(lookupElement)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
else -> ExpectedInfoClassification.NOT_MATCHES
|
||||
}
|
||||
}
|
||||
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession, bindingContext) })
|
||||
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession, bindingContext, true) })
|
||||
|
||||
if (receiver == null) {
|
||||
toFunctionReferenceLookupElement(descriptor, functionExpectedInfos)?.let { result.add(it) }
|
||||
@@ -237,7 +237,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
val matchedExpectedInfos = functionExpectedInfos.filter { functionType.isSubtypeOf(it.type) }
|
||||
if (matchedExpectedInfos.isEmpty()) return null
|
||||
|
||||
var lookupElement = createLookupElement(descriptor, resolveSession, bindingContext)
|
||||
var lookupElement = createLookupElement(descriptor, resolveSession, bindingContext, true)
|
||||
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
|
||||
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
override fun getLookupString() = text
|
||||
@@ -296,7 +296,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
if (jetType.isError()) return null
|
||||
val classifier = jetType.getConstructor().getDeclarationDescriptor() ?: return null
|
||||
|
||||
val lookupElement = createLookupElement(classifier, resolveSession, bindingContext)
|
||||
val lookupElement = createLookupElement(classifier, resolveSession, bindingContext, false)
|
||||
val lookupString = lookupElement.getLookupString()
|
||||
|
||||
val typeArgs = jetType.getArguments()
|
||||
|
||||
@@ -105,7 +105,7 @@ class StaticMembers(val bindingContext: BindingContext, val resolveSession: Reso
|
||||
}
|
||||
|
||||
private fun createLookupElement(memberDescriptor: DeclarationDescriptor, classDescriptor: ClassDescriptor): LookupElement {
|
||||
val lookupElement = createLookupElement(memberDescriptor, resolveSession, bindingContext)
|
||||
val lookupElement = createLookupElement(memberDescriptor, resolveSession, bindingContext, false)
|
||||
val qualifierPresentation = classDescriptor.getName().asString()
|
||||
val qualifierText = qualifiedNameForSourceCode(classDescriptor)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi
|
||||
}
|
||||
if (allConstructors.isNotEmpty() && visibleConstructors.isEmpty()) return
|
||||
|
||||
var lookupElement = createLookupElement(classifier, resolveSession, bindingContext)
|
||||
var lookupElement = createLookupElement(classifier, resolveSession, bindingContext, false)
|
||||
|
||||
var lookupString = lookupElement.getLookupString()
|
||||
var allLookupStrings = setOf(lookupString)
|
||||
@@ -164,7 +164,7 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi
|
||||
val samConstructor = scope.getFunctions(`class`.getName())
|
||||
.filterIsInstance(javaClass<SamConstructorDescriptor>())
|
||||
.singleOrNull() ?: return
|
||||
val lookupElement = createLookupElement(samConstructor, resolveSession, bindingContext)
|
||||
val lookupElement = createLookupElement(samConstructor, resolveSession, bindingContext, false)
|
||||
.assignSmartCompletionPriority(SmartCompletionItemPriority.INSTANTIATION)
|
||||
.addTail(tail)
|
||||
collection.add(lookupElement)
|
||||
|
||||
@@ -186,8 +186,13 @@ fun functionType(function: FunctionDescriptor): JetType? {
|
||||
function.getReturnType() ?: return null)
|
||||
}
|
||||
|
||||
fun createLookupElement(descriptor: DeclarationDescriptor, resolveSession: ResolveSessionForBodies, bindingContext: BindingContext): LookupElement {
|
||||
var element = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor)
|
||||
fun createLookupElement(
|
||||
descriptor: DeclarationDescriptor,
|
||||
resolveSession: ResolveSessionForBodies,
|
||||
bindingContext: BindingContext,
|
||||
boldImmediateMembers: Boolean
|
||||
): LookupElement {
|
||||
var element = KotlinLookupElementFactory.createLookupElement(resolveSession, descriptor, boldImmediateMembers)
|
||||
|
||||
if (descriptor is FunctionDescriptor && descriptor.getValueParameters().isNotEmpty()) {
|
||||
element = element.keepOldArgumentListOnTab()
|
||||
|
||||
Reference in New Issue
Block a user