Do not autopopup completion in name of generic function or property too
This commit is contained in:
committed by
valentin
parent
e6ea0537c8
commit
19fb090f28
@@ -47,7 +47,6 @@ public class JetCompletionContributor : CompletionContributor() {
|
||||
|
||||
private val AFTER_NUMBER_LITERAL = psiElement().afterLeafSkipping(psiElement().withText(""), psiElement().withElementType(elementType().oneOf(JetTokens.FLOAT_LITERAL, JetTokens.INTEGER_LITERAL)))
|
||||
private val AFTER_INTEGER_LITERAL_AND_DOT = psiElement().afterLeafSkipping(psiElement().withText("."), psiElement().withElementType(elementType().oneOf(JetTokens.INTEGER_LITERAL)))
|
||||
private val EXTENSION_RECEIVER_TYPE_PATTERN = psiElement().afterLeaf(JetTokens.FUN_KEYWORD.toString(), JetTokens.VAL_KEYWORD.toString(), JetTokens.VAR_KEYWORD.toString())
|
||||
|
||||
private val DEFAULT_DUMMY_IDENTIFIER = CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "$" // add '$' to ignore context after the caret
|
||||
|
||||
@@ -199,12 +198,25 @@ public class JetCompletionContributor : CompletionContributor() {
|
||||
// no completion auto-popup after integer and dot
|
||||
if (invocationCount == 0 && prefixMatcher.getPrefix().isEmpty() && AFTER_INTEGER_LITERAL_AND_DOT.accepts(position)) return true
|
||||
|
||||
// no auto-popup on typing after "val", "var" and "fun"
|
||||
if (invocationCount == 0 && EXTENSION_RECEIVER_TYPE_PATTERN.accepts(position)) return true
|
||||
// no auto-popup on typing after "val", "var" and "fun" because it's likely the name of the declaration which is being typed by user
|
||||
if (invocationCount == 0 && isInExtensionReceiver(position)) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun isInExtensionReceiver(position: PsiElement): Boolean {
|
||||
val nameRef = position.getParent() as? JetNameReferenceExpression ?: return false
|
||||
val userType = nameRef.getParent() as? JetUserType ?: return false
|
||||
val typeRef = userType.getParent() as? JetTypeReference ?: return false
|
||||
if (userType != typeRef.getTypeElement()) return false
|
||||
val parent = typeRef.getParent()
|
||||
return when (parent) {
|
||||
is JetNamedFunction -> typeRef == parent.getReceiverTypeRef()
|
||||
is JetProperty -> typeRef == parent.getReceiverTypeRef()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun isAtEndOfLine(offset: Int, document: Document): Boolean {
|
||||
var i = offset
|
||||
val chars = document.getCharsSequence()
|
||||
|
||||
@@ -2,7 +2,7 @@ fun Strange(){}
|
||||
|
||||
fun Annotations<S<caret>
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// INVOCATION_COUNT: 0
|
||||
// EXIST: String
|
||||
// EXIST: Set
|
||||
// ABSENT: Strange
|
||||
|
||||
@@ -5,4 +5,5 @@ class Test {
|
||||
fun Test.<caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: Nested
|
||||
|
||||
@@ -5,4 +5,5 @@ class Test {
|
||||
fun Test.N<caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: Nested
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Outer {
|
||||
class Nested
|
||||
}
|
||||
|
||||
fun Outer.<caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
class Outer {
|
||||
class Nested
|
||||
}
|
||||
|
||||
fun <T> Outer.<caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -0,0 +1,4 @@
|
||||
fun <T> <caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -0,0 +1,4 @@
|
||||
val <T> <caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -0,0 +1,4 @@
|
||||
var <T> a<caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -17,10 +17,13 @@
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -453,12 +456,42 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInExtFunName.kt")
|
||||
public void testNoAutopopupInExtFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInExtFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInFunName.kt")
|
||||
public void testNoAutopopupInFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericExtFunName.kt")
|
||||
public void testNoAutopopupInGenericExtFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericExtFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericFunName.kt")
|
||||
public void testNoAutopopupInGenericFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericValName.kt")
|
||||
public void testNoAutopopupInGenericValName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericValName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericVarName.kt")
|
||||
public void testNoAutopopupInGenericVarName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericVarName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInVarName.kt")
|
||||
public void testNoAutopopupInVarName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInVarName.kt");
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -456,12 +453,42 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInExtFunName.kt")
|
||||
public void testNoAutopopupInExtFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInExtFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInFunName.kt")
|
||||
public void testNoAutopopupInFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericExtFunName.kt")
|
||||
public void testNoAutopopupInGenericExtFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericExtFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericFunName.kt")
|
||||
public void testNoAutopopupInGenericFunName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericFunName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericValName.kt")
|
||||
public void testNoAutopopupInGenericValName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericValName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInGenericVarName.kt")
|
||||
public void testNoAutopopupInGenericVarName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInGenericVarName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutopopupInVarName.kt")
|
||||
public void testNoAutopopupInVarName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInVarName.kt");
|
||||
|
||||
Reference in New Issue
Block a user