Fix in keyword completion

This commit is contained in:
Valentin Kipyatkov
2014-10-15 12:59:59 +04:00
parent 8e1a89230e
commit 96a5e573c3
2 changed files with 13 additions and 7 deletions
@@ -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<PsiErrorElement>(), 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
@@ -2,10 +2,5 @@ class Test {
class <caret>
}
/*TODO: should be only 'object'*/
// EXIST: class
// EXIST: fun
// EXIST: object
// EXIST: trait
// EXIST: val
// NUMBER: 5
// NUMBER: 1