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) {
|
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||||
toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) }
|
toCallableReferenceLookupElement(descriptor)?.let { result.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -315,14 +315,13 @@ class SmartCompletion(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor,
|
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor): LookupElement? {
|
||||||
functionExpectedInfos: Collection<ExpectedInfo>): LookupElement? {
|
if (callableTypeExpectedInfo.isEmpty()) return null
|
||||||
if (functionExpectedInfos.isEmpty()) return null
|
|
||||||
|
|
||||||
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
||||||
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
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
|
if (matchedExpectedInfos.isEmpty()) return null
|
||||||
|
|
||||||
var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false, parametersAndTypeGrayed = true)
|
var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false, parametersAndTypeGrayed = true)
|
||||||
@@ -344,14 +343,22 @@ class SmartCompletion(
|
|||||||
.addTailAndNameSimilarity(matchedExpectedInfos)
|
.addTailAndNameSimilarity(matchedExpectedInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor is CallableDescriptor) {
|
when (descriptor) {
|
||||||
return toLookupElement(descriptor)
|
is CallableDescriptor -> {
|
||||||
}
|
if (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null) {
|
||||||
else if (descriptor is ClassDescriptor && descriptor.modality != Modality.ABSTRACT) {
|
return null // members and extensions are not supported after "::" currently
|
||||||
val constructors = descriptor.getConstructors().filter(visibilityFilter)
|
}
|
||||||
if (constructors.size() == 1) {
|
return toLookupElement(descriptor)
|
||||||
//TODO: this code is to be changed if overloads to start work after ::
|
}
|
||||||
return toLookupElement(constructors.single())
|
|
||||||
|
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) {
|
: CompletionSession(configuration, parameters, resultSet) {
|
||||||
|
|
||||||
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
|
// 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) {
|
private val smartCompletion by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
expression?.let {
|
expression?.let {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class C {
|
class C {
|
||||||
fun foo(p: C.() -> Unit){}
|
fun foo(p: C.() -> Any){}
|
||||||
|
fun foo(p: () -> Any){}
|
||||||
|
|
||||||
fun bar() {
|
fun bar() {
|
||||||
foo(<caret>)
|
foo(<caret>)
|
||||||
@@ -7,7 +8,15 @@ class C {
|
|||||||
|
|
||||||
fun f1(){}
|
fun f1(){}
|
||||||
fun C.f2(){}
|
fun C.f2(){}
|
||||||
|
|
||||||
|
inner class Inner
|
||||||
|
class Nested
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXIST: ::f1
|
class Outer
|
||||||
|
|
||||||
|
// ABSENT: ::f1
|
||||||
// ABSENT: ::f2
|
// ABSENT: ::f2
|
||||||
|
// ABSENT: ::Inner
|
||||||
|
// EXIST: ::Nested
|
||||||
|
// EXIST: ::Outer
|
||||||
|
|||||||
Reference in New Issue
Block a user