No completion auto-popup after dot in float literal (but one test start to fail!)
This commit is contained in:
committed by
valentin
parent
3fcf0f7340
commit
93d8791df1
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
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_DUMMY_IDENTIFIER = "KotlinExtensionDummy.fake() {}" // A way to add reference into file at completion place
|
||||
private val EXTENSION_RECEIVER_TYPE_ACTIVATION_PATTERN = psiElement().afterLeaf(JetTokens.FUN_KEYWORD.toString(), JetTokens.VAL_KEYWORD.toString(), JetTokens.VAR_KEYWORD.toString())
|
||||
@@ -131,13 +132,7 @@ public class JetCompletionContributor : CompletionContributor() {
|
||||
val position = parameters.getPosition()
|
||||
if (position.getContainingFile() !is JetFile) return
|
||||
|
||||
if (AFTER_NUMBER_LITERAL.accepts(parameters.getPosition())) {
|
||||
// First Kotlin completion contributors - stop here will stop all completion
|
||||
result.stopHere()
|
||||
return
|
||||
}
|
||||
|
||||
if (EXTENSION_RECEIVER_TYPE_ACTIVATION_PATTERN.accepts(position) && parameters.getInvocationCount() == 0) { // no auto-popup on typing after "val", "var" and "fun"
|
||||
if (shouldSuppressCompletion(parameters, result.getPrefixMatcher())) {
|
||||
result.stopHere()
|
||||
return
|
||||
}
|
||||
@@ -169,6 +164,22 @@ public class JetCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldSuppressCompletion(parameters: CompletionParameters, prefixMatcher: PrefixMatcher): Boolean {
|
||||
val position = parameters.getPosition()
|
||||
val invocationCount = parameters.getInvocationCount()
|
||||
|
||||
// no completion inside number literals
|
||||
if (AFTER_NUMBER_LITERAL.accepts(position)) return true
|
||||
|
||||
// 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 (EXTENSION_RECEIVER_TYPE_ACTIVATION_PATTERN.accepts(position) && invocationCount == 0) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun isAtEndOfLine(offset: Int, document: Document): Boolean {
|
||||
var i = offset
|
||||
val chars = document.getCharsSequence()
|
||||
|
||||
@@ -2,4 +2,5 @@ val Int.f: Float get() = this.toFloat()
|
||||
|
||||
val test = 1.<caret>
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: f
|
||||
@@ -0,0 +1,4 @@
|
||||
val v = 1.<caret>
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NUMBER: 0
|
||||
@@ -1,5 +1,6 @@
|
||||
fun test() {
|
||||
for (i in 12.<caret>) {
|
||||
val v = 1
|
||||
for (i in v.<caret>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
fun test() {
|
||||
for (i in 12..) {
|
||||
val v = 1
|
||||
for (i in v..) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -417,6 +417,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutoPopupAfterNumberLiteral.kt")
|
||||
public void testNoAutoPopupAfterNumberLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutoPopupAfterNumberLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoClassNameDuplication.kt")
|
||||
public void testNoClassNameDuplication() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoClassNameDuplication.kt");
|
||||
|
||||
@@ -417,6 +417,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutoPopupAfterNumberLiteral.kt")
|
||||
public void testNoAutoPopupAfterNumberLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutoPopupAfterNumberLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoClassNameDuplication.kt")
|
||||
public void testNoClassNameDuplication() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoClassNameDuplication.kt");
|
||||
|
||||
Reference in New Issue
Block a user