From 96a5e573c3080ec02bb633bcf7f5c03a81dcd6e6 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 15 Oct 2014 12:59:59 +0400 Subject: [PATCH] Fix in keyword completion --- .../jet/plugin/completion/KeywordCompletion.kt | 13 ++++++++++++- .../completion/keywords/AfterClassKeyword.kt | 7 +------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/completion/KeywordCompletion.kt b/idea/src/org/jetbrains/jet/plugin/completion/KeywordCompletion.kt index 3876157593c..6e3d5cdd5b9 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/KeywordCompletion.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/KeywordCompletion.kt @@ -32,6 +32,8 @@ import org.jetbrains.jet.lang.psi.psiUtil.getParentByType import org.jetbrains.jet.lang.psi.psiUtil.prevLeaf import org.jetbrains.jet.plugin.completion.handlers.KotlinKeywordInsertHandler import org.jetbrains.jet.lang.psi.psiUtil.siblings +import com.intellij.psi.PsiWhiteSpace +import com.intellij.psi.PsiComment class KeywordLookupObject(val keyword: String) @@ -159,13 +161,22 @@ object KeywordCompletion { elementAt.getParentByType(javaClass(), strict = false) != null -> false - elementAt.prevLeaf() is PsiErrorElement -> false + elementAt.prevLeafSkipWhitespacesAndComments() is PsiErrorElement -> false else -> true } } } + private fun PsiElement.prevLeafSkipWhitespacesAndComments(): PsiElement? { + var leaf = prevLeaf() + while (leaf != null) { + if (leaf !is PsiWhiteSpace && leaf !is PsiComment) return leaf + leaf = leaf!!.prevLeaf() + } + return null + } + // 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?) { if (position == scope) return diff --git a/idea/testData/completion/keywords/AfterClassKeyword.kt b/idea/testData/completion/keywords/AfterClassKeyword.kt index 84eb5a77459..dddc26b2e19 100644 --- a/idea/testData/completion/keywords/AfterClassKeyword.kt +++ b/idea/testData/completion/keywords/AfterClassKeyword.kt @@ -2,10 +2,5 @@ class Test { class } -/*TODO: should be only 'object'*/ -// EXIST: class -// EXIST: fun // EXIST: object -// EXIST: trait -// EXIST: val -// NUMBER: 5 \ No newline at end of file +// NUMBER: 1 \ No newline at end of file