Smart completion: no "::xxx" items for members and fixed bug with constructors not appearing there
This commit is contained in:
+20
-13
@@ -164,7 +164,7 @@ class SmartCompletion(
|
||||
}
|
||||
|
||||
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||
toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) }
|
||||
toCallableReferenceLookupElement(descriptor)?.let { result.add(it) }
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -315,14 +315,13 @@ class SmartCompletion(
|
||||
return null
|
||||
}
|
||||
|
||||
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor,
|
||||
functionExpectedInfos: Collection<ExpectedInfo>): LookupElement? {
|
||||
if (functionExpectedInfos.isEmpty()) return null
|
||||
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor): LookupElement? {
|
||||
if (callableTypeExpectedInfo.isEmpty()) return null
|
||||
|
||||
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
||||
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
||||
|
||||
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null }
|
||||
val matchedExpectedInfos = callableTypeExpectedInfo.filter { it.matchingSubstitutor(callableReferenceType) != null }
|
||||
if (matchedExpectedInfos.isEmpty()) return null
|
||||
|
||||
var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false, parametersAndTypeGrayed = true)
|
||||
@@ -344,14 +343,22 @@ class SmartCompletion(
|
||||
.addTailAndNameSimilarity(matchedExpectedInfos)
|
||||
}
|
||||
|
||||
if (descriptor is CallableDescriptor) {
|
||||
return toLookupElement(descriptor)
|
||||
}
|
||||
else if (descriptor is ClassDescriptor && descriptor.modality != Modality.ABSTRACT) {
|
||||
val constructors = descriptor.getConstructors().filter(visibilityFilter)
|
||||
if (constructors.size() == 1) {
|
||||
//TODO: this code is to be changed if overloads to start work after ::
|
||||
return toLookupElement(constructors.single())
|
||||
when (descriptor) {
|
||||
is CallableDescriptor -> {
|
||||
if (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null) {
|
||||
return null // members and extensions are not supported after "::" currently
|
||||
}
|
||||
return toLookupElement(descriptor)
|
||||
}
|
||||
|
||||
is ClassDescriptor -> {
|
||||
if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) {
|
||||
val constructors = descriptor.getConstructors().filter(visibilityFilter)
|
||||
if (constructors.size() == 1) {
|
||||
//TODO: this code is to be changed if overloads to start work after ::
|
||||
return toLookupElement(constructors.single())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -35,7 +35,15 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
: CompletionSession(configuration, parameters, resultSet) {
|
||||
|
||||
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
|
||||
override val descriptorKindFilter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
||||
override val descriptorKindFilter: DescriptorKindFilter
|
||||
get() {
|
||||
var filter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
||||
if (smartCompletion?.expectedInfos?.filterFunctionExpected()?.isNotEmpty() ?: false) {
|
||||
// if function type is expected we need classes to obtain their constructors
|
||||
filter = filter.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)
|
||||
}
|
||||
return filter
|
||||
}
|
||||
|
||||
private val smartCompletion by lazy(LazyThreadSafetyMode.NONE) {
|
||||
expression?.let {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class C {
|
||||
fun foo(p: C.() -> Unit){}
|
||||
fun foo(p: C.() -> Any){}
|
||||
fun foo(p: () -> Any){}
|
||||
|
||||
fun bar() {
|
||||
foo(<caret>)
|
||||
@@ -7,7 +8,15 @@ class C {
|
||||
|
||||
fun f1(){}
|
||||
fun C.f2(){}
|
||||
|
||||
inner class Inner
|
||||
class Nested
|
||||
}
|
||||
|
||||
// EXIST: ::f1
|
||||
class Outer
|
||||
|
||||
// ABSENT: ::f1
|
||||
// ABSENT: ::f2
|
||||
// ABSENT: ::Inner
|
||||
// EXIST: ::Nested
|
||||
// EXIST: ::Outer
|
||||
|
||||
Reference in New Issue
Block a user