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(
|
public fun createLookupElement(
|
||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
qualifyNestedClasses: Boolean = false,
|
qualifyNestedClasses: Boolean = false,
|
||||||
includeClassTypeArguments: Boolean = true
|
includeClassTypeArguments: Boolean = true,
|
||||||
|
parametersAndTypeGrayed: Boolean = false
|
||||||
): LookupElement {
|
): LookupElement {
|
||||||
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
||||||
DescriptorUtils.unwrapFakeOverride(descriptor)
|
DescriptorUtils.unwrapFakeOverride(descriptor)
|
||||||
else
|
else
|
||||||
descriptor
|
descriptor
|
||||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, _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 {
|
public fun createLookupElementForJavaClass(psiClass: PsiClass, qualifyNestedClasses: Boolean = false, includeClassTypeArguments: Boolean = true): LookupElement {
|
||||||
@@ -107,7 +108,8 @@ class BasicLookupElementFactory(
|
|||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
declaration: PsiElement?,
|
declaration: PsiElement?,
|
||||||
qualifyNestedClasses: Boolean,
|
qualifyNestedClasses: Boolean,
|
||||||
includeClassTypeArguments: Boolean
|
includeClassTypeArguments: Boolean,
|
||||||
|
parametersAndTypeGrayed: Boolean
|
||||||
): LookupElement {
|
): LookupElement {
|
||||||
if (descriptor is ClassifierDescriptor &&
|
if (descriptor is ClassifierDescriptor &&
|
||||||
declaration is PsiClass &&
|
declaration is PsiClass &&
|
||||||
@@ -149,18 +151,18 @@ class BasicLookupElementFactory(
|
|||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is FunctionDescriptor -> {
|
is FunctionDescriptor -> {
|
||||||
val returnType = descriptor.getReturnType()
|
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
|
val insertsLambda = (insertHandler as? KotlinFunctionInsertHandler.Normal)?.lambdaInfo != null
|
||||||
if (insertsLambda) {
|
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 -> {
|
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 -> {
|
is ClassDescriptor -> {
|
||||||
@@ -189,7 +191,7 @@ class BasicLookupElementFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
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 }
|
.filter { it.getName().asString() !in documentedParameters }
|
||||||
|
|
||||||
descriptors.forEach {
|
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 {
|
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) {
|
collector.addElement(object: LookupElementDecorator<LookupElement>(element) {
|
||||||
override fun handleInsert(context: InsertionContext?) {
|
override fun handleInsert(context: InsertionContext?) {
|
||||||
// insert only plain name here, no qualifier/parentheses/etc.
|
// 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> {
|
public fun createStandardLookupElementsForDescriptor(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean): Collection<LookupElement> {
|
||||||
val result = SmartList<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)) {
|
if (isInStringTemplateAfterDollar && (descriptor is FunctionDescriptor || descriptor is ClassifierDescriptor)) {
|
||||||
lookupElement = lookupElement.withBracesSurrounding()
|
lookupElement = lookupElement.withBracesSurrounding()
|
||||||
}
|
}
|
||||||
result.add(lookupElement)
|
result.add(lookupElement)
|
||||||
|
|
||||||
// add special item for function with one argument of function type with more than one parameter
|
// 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)
|
result.addSpecialFunctionCallElements(descriptor, useReceiverTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +185,10 @@ class LookupElementFactory(
|
|||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
useReceiverTypes: Boolean,
|
useReceiverTypes: Boolean,
|
||||||
qualifyNestedClasses: Boolean = false,
|
qualifyNestedClasses: Boolean = false,
|
||||||
includeClassTypeArguments: Boolean = true
|
includeClassTypeArguments: Boolean = true,
|
||||||
|
parametersAndTypeGrayed: Boolean = false
|
||||||
): LookupElement {
|
): LookupElement {
|
||||||
var element = basicFactory.createLookupElement(descriptor, qualifyNestedClasses, includeClassTypeArguments)
|
var element = basicFactory.createLookupElement(descriptor, qualifyNestedClasses, includeClassTypeArguments, parametersAndTypeGrayed)
|
||||||
|
|
||||||
if (useReceiverTypes) {
|
if (useReceiverTypes) {
|
||||||
val weight = callableWeight(descriptor)
|
val weight = callableWeight(descriptor)
|
||||||
|
|||||||
+1
-1
@@ -323,7 +323,7 @@ class SmartCompletion(
|
|||||||
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(functionType) != null }
|
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(functionType) != null }
|
||||||
if (matchedExpectedInfos.isEmpty()) return 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())
|
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
|
||||||
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||||
override fun getLookupString() = text
|
override fun getLookupString() = text
|
||||||
|
|||||||
Reference in New Issue
Block a user