From 280426428940b56050bee6ada2914e95e2c95e58 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 17 Mar 2017 20:20:40 +0300 Subject: [PATCH] Fix regression of completion inside string templates CompletionContributor should not store offsets inside replacement zone(part of file which are replaced with dummy identifier) in offsetMap #KT-16848 fixed --- .../idea/completion/KotlinCompletionContributor.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 43abc6f88ee..fc935bd5ed2 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -50,8 +50,6 @@ class KotlinCompletionContributor : CompletionContributor() { companion object { val DEFAULT_DUMMY_IDENTIFIER: String = CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "$" // add '$' to ignore context after the caret - - private val STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET = OffsetKey.create("STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET") } init { @@ -82,7 +80,6 @@ class KotlinCompletionContributor : CompletionContributor() { val prefix = tokenBefore.text.substring(0, offset - tokenBefore.startOffset) context.dummyIdentifier = "{" + expression.text + prefix + CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "}" context.offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, expression.startOffset) - context.offsetMap.addOffset(STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET, offset + 1) return } } @@ -241,8 +238,13 @@ class KotlinCompletionContributor : CompletionContributor() { val expression = (position.parent as KtBlockStringTemplateEntry).expression if (expression is KtDotQualifiedExpression) { val correctedPosition = (expression.selectorExpression as KtNameReferenceExpression).firstChild - val context = position.getUserData(CompletionContext.COMPLETION_CONTEXT_KEY)!! - val correctedOffset = context.offsetMap.getOffset(STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET) + // Workaround for KT-16848 + // ex: + // expression: some.IntellijIdeaRulezzz + // correctedOffset: ^ + // expression: some.funcIntellijIdeaRulezzz + // correctedOffset ^ + val correctedOffset = correctedPosition.endOffset - CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED.length val correctedParameters = parameters.withPosition(correctedPosition, correctedOffset) doComplete(correctedParameters, toFromOriginalFileMapper, result, lookupElementPostProcessor = { wrapLookupElementForStringTemplateAfterDotCompletion(it) })