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
This commit is contained in:
Simon Ogorodnik
2017-03-17 20:20:40 +03:00
committed by Dmitry Jemerov
parent cf18c2243f
commit 2804264289
@@ -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) })