Disabled parameter name completion where it makes no sense

This commit is contained in:
Valentin Kipyatkov
2015-06-17 20:08:01 +03:00
parent 0e045b9478
commit e2991b1412
9 changed files with 129 additions and 5 deletions
@@ -44,10 +44,7 @@ import org.jetbrains.kotlin.idea.util.makeNotNullable
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
@@ -289,7 +286,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
null
}
private val parameterNameAndTypeCompletion = if (completionKind == CompletionKind.PARAMETER_NAME || completionKind == CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME)
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
else
null
@@ -332,6 +329,25 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
return CompletionKind.ALL
}
private fun shouldCompleteParameterNameAndType(): Boolean {
when (completionKind) {
CompletionKind.PARAMETER_NAME, CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME -> {
val parameter = position.getNonStrictParentOfType<JetParameter>()!!
val owner = parameter.getParent().getParent()
return parameter != (owner as? JetCatchClause)?.getCatchParameter() && parameter != (owner as? JetPropertyAccessor)?.getParameter()
}
else -> return false
}
}
public fun disableAutoPopup(): Boolean {
return when (completionKind) {
CompletionKind.PARAMETER_NAME, CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME -> !shouldCompleteParameterNameAndType()
else -> false
}
}
override fun doComplete() {
assert(parameters.getCompletionType() == CompletionType.BASIC)
@@ -225,6 +225,11 @@ public class KotlinCompletionContributor : CompletionContributor() {
if (parameters.getCompletionType() == CompletionType.BASIC) {
val session = BasicCompletionSession(configuration, parameters, result)
if (parameters.isAutoPopup() && session.disableAutoPopup()) {
result.stopHere()
return
}
val somethingAdded = session.complete()
if (!somethingAdded && parameters.getInvocationCount() < 2) {
// Rerun completion if nothing was found
@@ -0,0 +1,11 @@
fun f() {
try {
}
catch(e<caret>) {
}
}
// INVOCATION_COUNT: 0
// NUMBER: 0
@@ -0,0 +1,6 @@
var v: Int
get(){}
set(v<caret>)
// INVOCATION_COUNT: 0
// NUMBER: 0
@@ -0,0 +1,10 @@
fun f() {
try {
}
catch(e<caret>) {
}
}
// ABSENT: "exception"
@@ -0,0 +1,9 @@
package pack
class Boo
fun f() {
val handler = { b<caret> }
}
// ABSENT: boo
@@ -0,0 +1,7 @@
class Voo
var v: Int
get(){}
set(v<caret>)
// ABSENT: voo
@@ -1053,6 +1053,18 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("NoCatchParameterAutopopup.kt")
public void testNoCatchParameterAutopopup() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/NoCatchParameterAutopopup.kt");
doTest(fileName);
}
@TestMetadata("NoSetterParameterAutopopup.kt")
public void testNoSetterParameterAutopopup() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/NoSetterParameterAutopopup.kt");
doTest(fileName);
}
@TestMetadata("ParameterAnnotation1.kt")
public void testParameterAnnotation1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt");
@@ -1410,6 +1422,24 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("NotForCatchParameter.kt")
public void testNotForCatchParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForCatchParameter.kt");
doTest(fileName);
}
@TestMetadata("NotForLambdaParameter.kt")
public void testNotForLambdaParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForLambdaParameter.kt");
doTest(fileName);
}
@TestMetadata("NotForSetterParameter.kt")
public void testNotForSetterParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForSetterParameter.kt");
doTest(fileName);
}
@TestMetadata("NotImported.kt")
public void testNotImported() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotImported.kt");
@@ -1053,6 +1053,18 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("NoCatchParameterAutopopup.kt")
public void testNoCatchParameterAutopopup() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/NoCatchParameterAutopopup.kt");
doTest(fileName);
}
@TestMetadata("NoSetterParameterAutopopup.kt")
public void testNoSetterParameterAutopopup() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/NoSetterParameterAutopopup.kt");
doTest(fileName);
}
@TestMetadata("ParameterAnnotation1.kt")
public void testParameterAnnotation1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt");
@@ -1410,6 +1422,24 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("NotForCatchParameter.kt")
public void testNotForCatchParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForCatchParameter.kt");
doTest(fileName);
}
@TestMetadata("NotForLambdaParameter.kt")
public void testNotForLambdaParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForLambdaParameter.kt");
doTest(fileName);
}
@TestMetadata("NotForSetterParameter.kt")
public void testNotForSetterParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotForSetterParameter.kt");
doTest(fileName);
}
@TestMetadata("NotImported.kt")
public void testNotImported() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/parameterNameAndType/NotImported.kt");