Keyword completion uses simple prefix matching only
This commit is contained in:
@@ -139,7 +139,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeywordCompletion.complete(parameters, prefixMatcher, collector)
|
KeywordCompletion.complete(parameters, prefixMatcher.getPrefix(), collector)
|
||||||
|
|
||||||
if (completeReference && !shouldRunOnlyTypeCompletion()) {
|
if (completeReference && !shouldRunOnlyTypeCompletion()) {
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiWhiteSpace
|
|||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens.*
|
import org.jetbrains.jet.lexer.JetTokens.*
|
||||||
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
|
||||||
class KeywordLookupObject(val keyword: String)
|
class KeywordLookupObject(val keyword: String)
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ object KeywordCompletion {
|
|||||||
|
|
||||||
private val KEYWORD_TO_DUMMY_POSTFIX = mapOf(OUT_KEYWORD to " X")
|
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()
|
val position = parameters.getPosition()
|
||||||
|
|
||||||
if (!GENERAL_FILTER.isAcceptable(position, position)) return
|
if (!GENERAL_FILTER.isAcceptable(position, position)) return
|
||||||
@@ -56,7 +57,7 @@ object KeywordCompletion {
|
|||||||
val parserFilter = buildFilter(position)
|
val parserFilter = buildFilter(position)
|
||||||
for (keywordToken in ALL_KEYWORDS) {
|
for (keywordToken in ALL_KEYWORDS) {
|
||||||
val keyword = keywordToken.getValue()
|
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)
|
val element = LookupElementBuilder.create(KeywordLookupObject(keyword), keyword)
|
||||||
.bold()
|
.bold()
|
||||||
.withInsertHandler(if (keywordToken !in FUNCTION_KEYWORDS)
|
.withInsertHandler(if (keywordToken !in FUNCTION_KEYWORDS)
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ open class Foo {
|
|||||||
p<caret> val foo = 1
|
p<caret> val foo = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXIST: private, public, protected, open
|
// EXIST: private, public, protected
|
||||||
// NUMBER: 4
|
// 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);
|
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")
|
@TestMetadata("PropertyAccessors.kt")
|
||||||
public void testPropertyAccessors() throws Exception {
|
public void testPropertyAccessors() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PropertyAccessors.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/PropertyAccessors.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user