Keyword completion uses simple prefix matching only

This commit is contained in:
Valentin Kipyatkov
2014-10-15 14:27:35 +04:00
parent 1e5ea703b5
commit 6b163bca8a
5 changed files with 21 additions and 5 deletions
@@ -139,7 +139,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
}
}
KeywordCompletion.complete(parameters, prefixMatcher, collector)
KeywordCompletion.complete(parameters, prefixMatcher.getPrefix(), collector)
if (completeReference && !shouldRunOnlyTypeCompletion()) {
flushToResultSet()
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.PsiComment
import org.jetbrains.jet.lexer.JetTokens.*
import com.intellij.openapi.util.text.StringUtil
class KeywordLookupObject(val keyword: String)
@@ -48,7 +49,7 @@ object KeywordCompletion {
private val KEYWORD_TO_DUMMY_POSTFIX = mapOf(OUT_KEYWORD to " X")
public fun complete(parameters: CompletionParameters, prefixMatcher: PrefixMatcher, collector: LookupElementsCollector) {
public fun complete(parameters: CompletionParameters, prefix: String, collector: LookupElementsCollector) {
val position = parameters.getPosition()
if (!GENERAL_FILTER.isAcceptable(position, position)) return
@@ -56,7 +57,7 @@ object KeywordCompletion {
val parserFilter = buildFilter(position)
for (keywordToken in ALL_KEYWORDS) {
val keyword = keywordToken.getValue()
if (prefixMatcher.prefixMatches(keyword) && parserFilter(keywordToken)) {
if (keyword.startsWith(prefix)/* use simple matching by prefix, not prefix matcher from completion*/ && parserFilter(keywordToken)) {
val element = LookupElementBuilder.create(KeywordLookupObject(keyword), keyword)
.bold()
.withInsertHandler(if (keywordToken !in FUNCTION_KEYWORDS)
@@ -3,5 +3,5 @@ open class Foo {
p<caret> val foo = 1
}
// EXIST: private, public, protected, open
// NUMBER: 4
// EXIST: private, public, protected
// NUMBER: 3
@@ -0,0 +1,9 @@
// test that sinple prefix matching is used for keywords
p<caret>
// EXIST: package
// EXIST: private
// EXIST: protected
// EXIST: public
// NUMBER: 4
@@ -244,6 +244,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
doTest(fileName);
}
@TestMetadata("PrefixMatcher.kt")
public void testPrefixMatcher() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PrefixMatcher.kt");
doTest(fileName);
}
@TestMetadata("PropertyAccessors.kt")
public void testPropertyAccessors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PropertyAccessors.kt");