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:
committed by
Dmitry Jemerov
parent
cf18c2243f
commit
2804264289
+7
-5
@@ -50,8 +50,6 @@ class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT_DUMMY_IDENTIFIER: String = CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "$" // add '$' to ignore context after the caret
|
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 {
|
init {
|
||||||
@@ -82,7 +80,6 @@ class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
val prefix = tokenBefore.text.substring(0, offset - tokenBefore.startOffset)
|
val prefix = tokenBefore.text.substring(0, offset - tokenBefore.startOffset)
|
||||||
context.dummyIdentifier = "{" + expression.text + prefix + CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "}"
|
context.dummyIdentifier = "{" + expression.text + prefix + CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "}"
|
||||||
context.offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, expression.startOffset)
|
context.offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, expression.startOffset)
|
||||||
context.offsetMap.addOffset(STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET, offset + 1)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,8 +238,13 @@ class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
val expression = (position.parent as KtBlockStringTemplateEntry).expression
|
val expression = (position.parent as KtBlockStringTemplateEntry).expression
|
||||||
if (expression is KtDotQualifiedExpression) {
|
if (expression is KtDotQualifiedExpression) {
|
||||||
val correctedPosition = (expression.selectorExpression as KtNameReferenceExpression).firstChild
|
val correctedPosition = (expression.selectorExpression as KtNameReferenceExpression).firstChild
|
||||||
val context = position.getUserData(CompletionContext.COMPLETION_CONTEXT_KEY)!!
|
// Workaround for KT-16848
|
||||||
val correctedOffset = context.offsetMap.getOffset(STRING_TEMPLATE_AFTER_DOT_REAL_START_OFFSET)
|
// ex:
|
||||||
|
// expression: some.IntellijIdeaRulezzz
|
||||||
|
// correctedOffset: ^
|
||||||
|
// expression: some.funcIntellijIdeaRulezzz
|
||||||
|
// correctedOffset ^
|
||||||
|
val correctedOffset = correctedPosition.endOffset - CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED.length
|
||||||
val correctedParameters = parameters.withPosition(correctedPosition, correctedOffset)
|
val correctedParameters = parameters.withPosition(correctedPosition, correctedOffset)
|
||||||
doComplete(correctedParameters, toFromOriginalFileMapper, result,
|
doComplete(correctedParameters, toFromOriginalFileMapper, result,
|
||||||
lookupElementPostProcessor = { wrapLookupElementForStringTemplateAfterDotCompletion(it) })
|
lookupElementPostProcessor = { wrapLookupElementForStringTemplateAfterDotCompletion(it) })
|
||||||
|
|||||||
Reference in New Issue
Block a user