Fixed KT-6408 Completion auto-popup prevents smooth typing of "!in"
#KT-6408 Fixed
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.psiUtil.siblings
|
|||||||
import org.jetbrains.jet.lexer.JetTokens.*
|
import org.jetbrains.jet.lexer.JetTokens.*
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.prevLeafSkipWhitespacesAndComments
|
import org.jetbrains.jet.lang.psi.psiUtil.prevLeafSkipWhitespacesAndComments
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||||
|
import com.intellij.psi.tree.IElementType
|
||||||
|
|
||||||
class KeywordLookupObject(val keyword: String)
|
class KeywordLookupObject(val keyword: String)
|
||||||
|
|
||||||
@@ -158,9 +159,9 @@ object KeywordCompletion {
|
|||||||
val postfix = KEYWORD_TO_DUMMY_POSTFIX[keywordTokenType] ?: ""
|
val postfix = KEYWORD_TO_DUMMY_POSTFIX[keywordTokenType] ?: ""
|
||||||
val file = psiFactory.createFile(prefixText + keywordTokenType.getValue() + postfix)
|
val file = psiFactory.createFile(prefixText + keywordTokenType.getValue() + postfix)
|
||||||
val elementAt = file.findElementAt(prefixText.length)!!
|
val elementAt = file.findElementAt(prefixText.length)!!
|
||||||
val nodeType = elementAt.getNode()!!.getElementType()
|
|
||||||
when {
|
when {
|
||||||
nodeType != keywordTokenType -> false
|
!elementAt.getNode()!!.getElementType().matchesKeyword(keywordTokenType) -> false
|
||||||
|
|
||||||
elementAt.getNonStrictParentOfType<PsiErrorElement>() != null -> false
|
elementAt.getNonStrictParentOfType<PsiErrorElement>() != null -> false
|
||||||
|
|
||||||
@@ -171,6 +172,15 @@ object KeywordCompletion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IElementType.matchesKeyword(keywordType: JetKeywordToken): Boolean {
|
||||||
|
return when(this) {
|
||||||
|
keywordType -> true
|
||||||
|
NOT_IN -> keywordType == IN_KEYWORD
|
||||||
|
NOT_IS -> keywordType == IS_KEYWORD
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// builds text within scope (or from the start of the file) before position element excluding almost all declarations
|
// builds text within scope (or from the start of the file) before position element excluding almost all declarations
|
||||||
private fun buildReducedContextBefore(builder: StringBuilder, position: PsiElement, scope: PsiElement?) {
|
private fun buildReducedContextBefore(builder: StringBuilder, position: PsiElement, scope: PsiElement?) {
|
||||||
if (position == scope) return
|
if (position == scope) return
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun foo(v: String) {
|
||||||
|
if (v !<caret>)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: in
|
||||||
|
// EXIST: is
|
||||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.completion;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.test.InnerTestClasses;
|
|
||||||
import org.jetbrains.jet.test.TestMetadata;
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@@ -246,6 +245,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NotInNotIs.kt")
|
||||||
|
public void testNotInNotIs() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/NotInNotIs.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PrefixMatcher.kt")
|
@TestMetadata("PrefixMatcher.kt")
|
||||||
public void testPrefixMatcher() throws Exception {
|
public void testPrefixMatcher() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PrefixMatcher.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PrefixMatcher.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user