Completion for "file" keyword in annotations

This commit is contained in:
Valentin Kipyatkov
2015-01-12 16:26:11 +03:00
parent fde1890de9
commit 9e526fca58
8 changed files with 28 additions and 2 deletions
@@ -45,7 +45,10 @@ object KeywordCompletion {
.filter { it !in NON_ACTUAL_KEYWORDS }
.map { it as JetKeywordToken }
private val KEYWORD_TO_DUMMY_POSTFIX = mapOf(OUT_KEYWORD to " X")
private val KEYWORD_TO_DUMMY_POSTFIX = mapOf(
OUT_KEYWORD to " X",
FILE_KEYWORD to ":"
)
public fun complete(position: PsiElement, prefix: String, consumer: (LookupElement) -> Unit) {
if (!GENERAL_FILTER.isAcceptable(position, position)) return
@@ -42,7 +42,11 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
DYNAMIC_KEYWORD).map { it.getValue() }
override fun handleInsert(context: InsertionContext, item: LookupElement) {
if (item.getLookupString() !in NO_SPACE_AFTER) {
val keyword = item.getLookupString()
if (keyword == FILE_KEYWORD.getValue()) {
WithTailInsertHandler.colonTail().postHandleInsert(context, item)
}
else if (keyword !in NO_SPACE_AFTER) {
WithTailInsertHandler.spaceTail().postHandleInsert(context, item)
}
}
@@ -91,5 +91,6 @@ class WithTailInsertHandler(val tailText: String,
fun elseTail() = WithTailInsertHandler("else", spaceBefore = true, spaceAfter = true)
fun eqTail() = WithTailInsertHandler("=", spaceBefore = true, spaceAfter = true) /*TODO: use code style options*/
fun spaceTail() = WithTailInsertHandler(" ", spaceBefore = false, spaceAfter = false, overwriteText = false)
fun colonTail() = WithTailInsertHandler(":", spaceBefore = false, spaceAfter = true)
}
}
@@ -0,0 +1 @@
[fi<caret>]
@@ -0,0 +1 @@
[file: <caret>]
@@ -0,0 +1,4 @@
[<caret>]
// EXIST: file
// NUMBER: 1
@@ -102,6 +102,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
doTest(fileName);
}
@TestMetadata("FileKeyword.kt")
public void testFileKeyword() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/FileKeyword.kt");
doTest(fileName);
}
@TestMetadata("GlobalPropertyAccessors.kt")
public void testGlobalPropertyAccessors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/GlobalPropertyAccessors.kt");
@@ -42,6 +42,12 @@ public class KeywordCompletionHandlerTestGenerated extends AbstractKeywordComple
doTest(fileName);
}
@TestMetadata("FileKeyword.kt")
public void testFileKeyword() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/keywords/FileKeyword.kt");
doTest(fileName);
}
@TestMetadata("NoSpaceAfterNull.kt")
public void testNoSpaceAfterNull() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/keywords/NoSpaceAfterNull.kt");