KT-9388 Code completion inserts use-site annotation target with superfluous chars
#KT-9388 Fixed
This commit is contained in:
@@ -32,8 +32,10 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinKeywordInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.UseSiteAnnotationTargetInsertHandler
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
@@ -83,12 +85,16 @@ object KeywordCompletion {
|
||||
|
||||
if (!parserFilter(keywordToken)) continue
|
||||
|
||||
val insertHandler = if (position.prevLeaf()?.node?.elementType == KtTokens.AT)
|
||||
UseSiteAnnotationTargetInsertHandler
|
||||
else if (keywordToken !in FUNCTION_KEYWORDS)
|
||||
KotlinKeywordInsertHandler
|
||||
else
|
||||
KotlinFunctionInsertHandler.Normal(inputTypeArguments = false, inputValueArguments = false)
|
||||
|
||||
val element = LookupElementBuilder.create(KeywordLookupObject(), keyword)
|
||||
.bold()
|
||||
.withInsertHandler(if (keywordToken !in FUNCTION_KEYWORDS)
|
||||
KotlinKeywordInsertHandler
|
||||
else
|
||||
KotlinFunctionInsertHandler.Normal(inputTypeArguments = false, inputValueArguments = false))
|
||||
.withInsertHandler(insertHandler)
|
||||
consumer(element)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-5
@@ -42,12 +42,15 @@ object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
DYNAMIC_KEYWORD).map { it.getValue() } + "companion object"
|
||||
|
||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
val keyword = item.getLookupString()
|
||||
if (keyword == FILE_KEYWORD.getValue()) {
|
||||
WithTailInsertHandler.colonTail().postHandleInsert(context, item)
|
||||
}
|
||||
else if (keyword !in NO_SPACE_AFTER) {
|
||||
val keyword = item.lookupString
|
||||
if (keyword !in NO_SPACE_AFTER) {
|
||||
WithTailInsertHandler.spaceTail().postHandleInsert(context, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object UseSiteAnnotationTargetInsertHandler : InsertHandler<LookupElement> {
|
||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
WithTailInsertHandler(":", spaceBefore = false, spaceAfter = false).postHandleInsert(context, item)
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -93,6 +93,5 @@ 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,3 @@
|
||||
class C(@<caret> val p: String)
|
||||
|
||||
// ELEMENT: get
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class C(@get:<caret> val p: String)
|
||||
|
||||
// ELEMENT: get
|
||||
@@ -0,0 +1,3 @@
|
||||
class C(@<caret>Ann var p: String)
|
||||
|
||||
// ELEMENT: set
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class C(@set:<caret>Ann var p: String)
|
||||
|
||||
// ELEMENT: set
|
||||
@@ -0,0 +1,4 @@
|
||||
class C(@<caret>get:Ann var p: String)
|
||||
|
||||
// ELEMENT: set
|
||||
// CHAR: '\t'
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
class C(@set:<caret>Ann var p: String)
|
||||
|
||||
// ELEMENT: set
|
||||
// CHAR: '\t'
|
||||
+18
@@ -124,4 +124,22 @@ public class KeywordCompletionHandlerTestGenerated extends AbstractKeywordComple
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/keywords/SpaceAfterImport.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseSiteAnnotationTarget1.kt")
|
||||
public void testUseSiteAnnotationTarget1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/keywords/UseSiteAnnotationTarget1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseSiteAnnotationTarget2.kt")
|
||||
public void testUseSiteAnnotationTarget2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/keywords/UseSiteAnnotationTarget2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseSiteAnnotationTarget3.kt")
|
||||
public void testUseSiteAnnotationTarget3() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/keywords/UseSiteAnnotationTarget3.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user