Skip to content

Commit

Permalink
Fix regression of completion inside string templates
Browse files Browse the repository at this point in the history
CompletionContributor should not store offsets inside
replacement zone(part of file which are replaced with
dummy identifier) in offsetMap
 #KT-16848 fixed
  • Loading branch information
semoro authored and yole committed Mar 20, 2017
1 parent cf18c22 commit 2804264
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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) })
Expand Down

0 comments on commit 2804264

Please sign in to comment.