From 80a1d945157ca1ea2f7d970589f6854b3e71062d Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 6 Nov 2015 15:47:43 +0300 Subject: [PATCH] Non-imported top-level functions completion does not require second press --- .../kotlin/idea/completion/BasicCompletionSession.kt | 10 ++++++---- .../kotlin/idea/completion/CompletionSession.kt | 8 ++++---- .../idea/completion/KotlinCompletionContributor.kt | 2 +- .../CallableReferenceNotImported.dependency.kt | 6 +++--- .../CallableReferenceNotImported.kt | 9 ++++----- .../multifile/ExtensionFunction/ExtensionFunction.kt | 1 - .../multifile/HiddenDeclarations/HiddenDeclarations.kt | 1 - .../NotImportedInfixExtension.kt | 1 - .../PreferMemberToGlobal/PreferMemberToGlobal.kt | 1 - .../testData/handlers/smart/JavaStaticMethod.kt | 4 ++-- .../testData/handlers/smart/JavaStaticMethod.kt.after | 4 ++-- .../CallableReferenceNotImported.kt | 1 - 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index 160953e5ae7..88f0b4420b1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -108,9 +108,11 @@ class BasicCompletionSession( return ALL } - public fun shouldDisableAutoPopup(): Boolean { - return completionKind.shouldDisableAutoPopup() - } + fun shouldDisableAutoPopup(): Boolean + = completionKind.shouldDisableAutoPopup() + + override fun shouldCompleteTopLevelCallablesFromIndex() + = super.shouldCompleteTopLevelCallablesFromIndex() && prefix.isNotEmpty() override fun doComplete() { assert(parameters.completionType == CompletionType.BASIC) @@ -255,7 +257,7 @@ class BasicCompletionSession( else -> classKindFilter = null } if (classKindFilter != null) { - if (configuration.completeNonImportedDeclarations) { + if (configuration.completeNonImportedClasses) { addClassesFromIndex(classKindFilter) } else { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index 3bf8ba67377..9a52ba3ae02 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -54,7 +54,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import java.util.* class CompletionSessionConfiguration( - val completeNonImportedDeclarations: Boolean, + val completeNonImportedClasses: Boolean, val completeNonAccessibleDeclarations: Boolean, val filterOutJavaGettersAndSetters: Boolean, val completeJavaClassesNotToBeUsed: Boolean, @@ -62,7 +62,7 @@ class CompletionSessionConfiguration( ) fun CompletionSessionConfiguration(parameters: CompletionParameters) = CompletionSessionConfiguration( - completeNonImportedDeclarations = parameters.invocationCount >= 2, + completeNonImportedClasses = parameters.invocationCount >= 2, completeNonAccessibleDeclarations = parameters.invocationCount >= 2, filterOutJavaGettersAndSetters = parameters.invocationCount < 2, completeJavaClassesNotToBeUsed = parameters.invocationCount >= 2, @@ -389,8 +389,8 @@ abstract class CompletionSession( return result } - protected fun shouldCompleteTopLevelCallablesFromIndex(): Boolean { - if (!configuration.completeNonImportedDeclarations) return false + protected open fun shouldCompleteTopLevelCallablesFromIndex(): Boolean { + if (nameExpression == null) return false if ((descriptorKindFilter?.kindMask ?: 0).and(DescriptorKindFilter.CALLABLES_MASK) == 0) return false if (callTypeAndReceiver is CallTypeAndReceiver.IMPORT_DIRECTIVE) return false return callTypeAndReceiver.receiver == null diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 1be1b1c965b..0b7189f59aa 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -260,7 +260,7 @@ public class KotlinCompletionContributor : CompletionContributor() { if (!somethingAdded && parameters.invocationCount < 2) { // Rerun completion if nothing was found val newConfiguration = CompletionSessionConfiguration( - completeNonImportedDeclarations = true, + completeNonImportedClasses = true, completeNonAccessibleDeclarations = false, filterOutJavaGettersAndSetters = false, completeJavaClassesNotToBeUsed = false, diff --git a/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.dependency.kt b/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.dependency.kt index 4892804af8d..c38956c0b09 100644 --- a/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.dependency.kt +++ b/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.dependency.kt @@ -1,7 +1,7 @@ package dependency -fun topLevelFun(){} +fun xxx_topLevelFun(){} -val topLevelVal: Int = 1 +val xxx_topLevelVal: Int = 1 -fun CharSequence.extFun(){} +fun CharSequence.xxx_extFun(){} diff --git a/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.kt b/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.kt index 2d58e6f45ae..b1507f8026f 100644 --- a/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.kt +++ b/idea/idea-completion/testData/basic/multifile/CallableReferenceNotImported/CallableReferenceNotImported.kt @@ -1,8 +1,7 @@ fun String.foo() { - val v = :: + val v = ::xxx_ } -// INVOCATION_COUNT: 2 -// EXIST: topLevelFun -// EXIST: topLevelVal -// ABSENT: extFun +// EXIST: xxx_topLevelFun +// EXIST: xxx_topLevelVal +// ABSENT: xxx_extFun diff --git a/idea/idea-completion/testData/basic/multifile/ExtensionFunction/ExtensionFunction.kt b/idea/idea-completion/testData/basic/multifile/ExtensionFunction/ExtensionFunction.kt index 512205b1fda..b4a0c10b1e3 100644 --- a/idea/idea-completion/testData/basic/multifile/ExtensionFunction/ExtensionFunction.kt +++ b/idea/idea-completion/testData/basic/multifile/ExtensionFunction/ExtensionFunction.kt @@ -8,5 +8,4 @@ fun firstFun() { a. } -// INVOCATION_COUNT: 2 // EXIST: secondExtension \ No newline at end of file diff --git a/idea/idea-completion/testData/basic/multifile/HiddenDeclarations/HiddenDeclarations.kt b/idea/idea-completion/testData/basic/multifile/HiddenDeclarations/HiddenDeclarations.kt index 559d7137d95..7988424e79c 100644 --- a/idea/idea-completion/testData/basic/multifile/HiddenDeclarations/HiddenDeclarations.kt +++ b/idea/idea-completion/testData/basic/multifile/HiddenDeclarations/HiddenDeclarations.kt @@ -7,7 +7,6 @@ fun String.foo() { hid } -// INVOCATION_COUNT: 2 // ABSENT: hiddenFun // ABSENT: hiddenProperty // ABSENT: hiddenFunFromSameFile diff --git a/idea/idea-completion/testData/basic/multifile/NotImportedInfixExtension/NotImportedInfixExtension.kt b/idea/idea-completion/testData/basic/multifile/NotImportedInfixExtension/NotImportedInfixExtension.kt index f6a73da9693..6523cca40da 100644 --- a/idea/idea-completion/testData/basic/multifile/NotImportedInfixExtension/NotImportedInfixExtension.kt +++ b/idea/idea-completion/testData/basic/multifile/NotImportedInfixExtension/NotImportedInfixExtension.kt @@ -6,7 +6,6 @@ fun f() { C() } -// INVOCATION_COUNT: 2 // ABSENT: "xxx" // EXIST: { lookupString: "yyy", attributes: "bold" } // ABSENT: "zzz" diff --git a/idea/idea-completion/testData/basic/multifile/PreferMemberToGlobal/PreferMemberToGlobal.kt b/idea/idea-completion/testData/basic/multifile/PreferMemberToGlobal/PreferMemberToGlobal.kt index c578d7a26b4..6c8e1d57be1 100644 --- a/idea/idea-completion/testData/basic/multifile/PreferMemberToGlobal/PreferMemberToGlobal.kt +++ b/idea/idea-completion/testData/basic/multifile/PreferMemberToGlobal/PreferMemberToGlobal.kt @@ -10,7 +10,6 @@ class C { } } -// INVOCATION_COUNT: 2 // EXIST: { lookupString: "xxx", itemText: "xxx", tailText: "()", typeText: "Unit" } // EXIST: { lookupString: "xxy", itemText: "xxy", tailText: "()", typeText: "Unit" } // EXIST: { lookupString: "xxz", itemText: "xxz", tailText: "(p: Int)", typeText: "Unit" } diff --git a/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt b/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt index 2775b0ad2f1..de4798f6f0e 100644 --- a/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt +++ b/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt @@ -1,5 +1,5 @@ fun foo(){ - val l : java.lang.Thread = + val l: java.lang.Thread = } -// ELEMENT: currentThread +// ELEMENT_TEXT: Thread.currentThread diff --git a/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt.after b/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt.after index fc03644486c..58f9cb9201c 100644 --- a/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt.after +++ b/idea/idea-completion/testData/handlers/smart/JavaStaticMethod.kt.after @@ -1,5 +1,5 @@ fun foo(){ - val l : java.lang.Thread = Thread.currentThread() + val l: java.lang.Thread = Thread.currentThread() } -// ELEMENT: currentThread +// ELEMENT_TEXT: Thread.currentThread diff --git a/idea/idea-completion/testData/smartMultiFile/CallableReferenceNotImported/CallableReferenceNotImported.kt b/idea/idea-completion/testData/smartMultiFile/CallableReferenceNotImported/CallableReferenceNotImported.kt index 41f084f0710..6edf66502fc 100644 --- a/idea/idea-completion/testData/smartMultiFile/CallableReferenceNotImported/CallableReferenceNotImported.kt +++ b/idea/idea-completion/testData/smartMultiFile/CallableReferenceNotImported/CallableReferenceNotImported.kt @@ -6,6 +6,5 @@ fun bar(p: () -> Unit) { } fun bar(p: String.() -> Unit) { } -// INVOCATION_COUNT: 2 // EXIST: topLevelFun // ABSENT: extFun