From b41f2dcda3746e3b3c49bff57c75adae5f0f51ec Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 13 Jan 2016 22:14:43 +0300 Subject: [PATCH] KT-10655 No "in" in code completion popup after "!" #KT-10655 Fixed --- .../idea/completion/KeywordCompletion.kt | 18 +++++++++++++++++- .../testData/keywords/NotInNotIs2.kt | 7 +++++++ .../test/KeywordCompletionTestGenerated.java | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 idea/idea-completion/testData/keywords/NotInNotIs2.kt diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt index 4c199335028..88797e8d072 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.resolve.ModifierCheckerCore +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull open class KeywordLookupObject @@ -139,7 +140,22 @@ object KeywordCompletion { while (parent != null) { when (parent) { is KtBlockExpression -> { - return buildFilterWithContext("fun foo() { ", prevParent, position) + val prefixText = "fun foo() { " + if (prevParent is KtExpression) { + return buildFilterWithContext(prefixText, prevParent, position) + } + else { + val lastExpression = prevParent + .siblings(forward = false, withItself = false) + .firstIsInstanceOrNull() + if (lastExpression != null) { + val contextAfterExpression = lastExpression + .siblings(forward = true, withItself = false) + .takeWhile { it != prevParent } + .joinToString { it.text } + return buildFilterWithContext(prefixText + "x" + contextAfterExpression, prevParent, position) + } + } } is KtWithExpressionInitializer -> { diff --git a/idea/idea-completion/testData/keywords/NotInNotIs2.kt b/idea/idea-completion/testData/keywords/NotInNotIs2.kt new file mode 100644 index 00000000000..95077733cc9 --- /dev/null +++ b/idea/idea-completion/testData/keywords/NotInNotIs2.kt @@ -0,0 +1,7 @@ +fun foo() { + list.filter { it !i } +} + +// EXIST: in +// EXIST: is +// NOTHING_ELSE diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java index ef173461203..fc31a9e4b92 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KeywordCompletionTestGenerated.java @@ -353,6 +353,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes doTest(fileName); } + @TestMetadata("NotInNotIs2.kt") + public void testNotInNotIs2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/NotInNotIs2.kt"); + doTest(fileName); + } + @TestMetadata("PrefixMatcher.kt") public void testPrefixMatcher() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/PrefixMatcher.kt");