Completion: grayed parameters and type in completion of imports and callable references (arguable)
This commit is contained in:
+10
-8
@@ -43,14 +43,15 @@ class BasicLookupElementFactory(
|
||||
public fun createLookupElement(
|
||||
descriptor: DeclarationDescriptor,
|
||||
qualifyNestedClasses: Boolean = false,
|
||||
includeClassTypeArguments: Boolean = true
|
||||
includeClassTypeArguments: Boolean = true,
|
||||
parametersAndTypeGrayed: Boolean = false
|
||||
): LookupElement {
|
||||
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
||||
DescriptorUtils.unwrapFakeOverride(descriptor)
|
||||
else
|
||||
descriptor
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, _descriptor)
|
||||
return createLookupElement(_descriptor, declaration, qualifyNestedClasses, includeClassTypeArguments)
|
||||
return createLookupElement(_descriptor, declaration, qualifyNestedClasses, includeClassTypeArguments, parametersAndTypeGrayed)
|
||||
}
|
||||
|
||||
public fun createLookupElementForJavaClass(psiClass: PsiClass, qualifyNestedClasses: Boolean = false, includeClassTypeArguments: Boolean = true): LookupElement {
|
||||
@@ -107,7 +108,8 @@ class BasicLookupElementFactory(
|
||||
descriptor: DeclarationDescriptor,
|
||||
declaration: PsiElement?,
|
||||
qualifyNestedClasses: Boolean,
|
||||
includeClassTypeArguments: Boolean
|
||||
includeClassTypeArguments: Boolean,
|
||||
parametersAndTypeGrayed: Boolean
|
||||
): LookupElement {
|
||||
if (descriptor is ClassifierDescriptor &&
|
||||
declaration is PsiClass &&
|
||||
@@ -149,18 +151,18 @@ class BasicLookupElementFactory(
|
||||
when (descriptor) {
|
||||
is FunctionDescriptor -> {
|
||||
val returnType = descriptor.getReturnType()
|
||||
element = element.withTypeText(if (returnType != null) DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(returnType) else "")
|
||||
element = element.withTypeText(if (returnType != null) DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(returnType) else "", parametersAndTypeGrayed)
|
||||
|
||||
val insertsLambda = (insertHandler as? KotlinFunctionInsertHandler.Normal)?.lambdaInfo != null
|
||||
if (insertsLambda) {
|
||||
element = element.appendTailText(" {...} ", false)
|
||||
element = element.appendTailText(" {...} ", parametersAndTypeGrayed)
|
||||
}
|
||||
|
||||
element = element.appendTailText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(descriptor), insertsLambda)
|
||||
element = element.appendTailText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(descriptor), parametersAndTypeGrayed || insertsLambda)
|
||||
}
|
||||
|
||||
is VariableDescriptor -> {
|
||||
element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()))
|
||||
element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()), parametersAndTypeGrayed)
|
||||
}
|
||||
|
||||
is ClassDescriptor -> {
|
||||
@@ -189,7 +191,7 @@ class BasicLookupElementFactory(
|
||||
}
|
||||
|
||||
else -> {
|
||||
element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor))
|
||||
element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor), parametersAndTypeGrayed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ class KDocNameCompletionSession(parameters: CompletionParameters,
|
||||
.filter { it.getName().asString() !in documentedParameters }
|
||||
|
||||
descriptors.forEach {
|
||||
collector.addElement(lookupElementFactory.createLookupElement(it, useReceiverTypes = false))
|
||||
collector.addElement(lookupElementFactory.createLookupElement(it, useReceiverTypes = false, parametersAndTypeGrayed = true))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class KDocNameCompletionSession(parameters: CompletionParameters,
|
||||
}
|
||||
|
||||
scope.getDescriptorsFiltered(nameFilter = descriptorNameFilter).filter(::isApplicable).forEach {
|
||||
val element = lookupElementFactory.createLookupElement(it, useReceiverTypes = false)
|
||||
val element = lookupElementFactory.createLookupElement(it, useReceiverTypes = false, parametersAndTypeGrayed = true)
|
||||
collector.addElement(object: LookupElementDecorator<LookupElement>(element) {
|
||||
override fun handleInsert(context: InsertionContext?) {
|
||||
// insert only plain name here, no qualifier/parentheses/etc.
|
||||
|
||||
+7
-4
@@ -59,14 +59,16 @@ class LookupElementFactory(
|
||||
public fun createStandardLookupElementsForDescriptor(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean): Collection<LookupElement> {
|
||||
val result = SmartList<LookupElement>()
|
||||
|
||||
var lookupElement = createLookupElement(descriptor, useReceiverTypes)
|
||||
val isNormalCall = callType == CallType.DEFAULT || callType == CallType.DOT || callType == CallType.SAFE
|
||||
|
||||
var lookupElement = createLookupElement(descriptor, useReceiverTypes, parametersAndTypeGrayed = !isNormalCall && callType != CallType.INFIX)
|
||||
if (isInStringTemplateAfterDollar && (descriptor is FunctionDescriptor || descriptor is ClassifierDescriptor)) {
|
||||
lookupElement = lookupElement.withBracesSurrounding()
|
||||
}
|
||||
result.add(lookupElement)
|
||||
|
||||
// add special item for function with one argument of function type with more than one parameter
|
||||
if (descriptor is FunctionDescriptor && (callType == CallType.DEFAULT || callType == CallType.DOT || callType == CallType.SAFE)) {
|
||||
if (descriptor is FunctionDescriptor && isNormalCall) {
|
||||
result.addSpecialFunctionCallElements(descriptor, useReceiverTypes)
|
||||
}
|
||||
|
||||
@@ -183,9 +185,10 @@ class LookupElementFactory(
|
||||
descriptor: DeclarationDescriptor,
|
||||
useReceiverTypes: Boolean,
|
||||
qualifyNestedClasses: Boolean = false,
|
||||
includeClassTypeArguments: Boolean = true
|
||||
includeClassTypeArguments: Boolean = true,
|
||||
parametersAndTypeGrayed: Boolean = false
|
||||
): LookupElement {
|
||||
var element = basicFactory.createLookupElement(descriptor, qualifyNestedClasses, includeClassTypeArguments)
|
||||
var element = basicFactory.createLookupElement(descriptor, qualifyNestedClasses, includeClassTypeArguments, parametersAndTypeGrayed)
|
||||
|
||||
if (useReceiverTypes) {
|
||||
val weight = callableWeight(descriptor)
|
||||
|
||||
+1
-1
@@ -323,7 +323,7 @@ class SmartCompletion(
|
||||
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(functionType) != null }
|
||||
if (matchedExpectedInfos.isEmpty()) return null
|
||||
|
||||
var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false)
|
||||
var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false, parametersAndTypeGrayed = true)
|
||||
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
|
||||
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
override fun getLookupString() = text
|
||||
|
||||
Reference in New Issue
Block a user