Fix code completion for the injected Kotlin code

Allow completion of physical files as it is the case for injected Kotlin code.
Also, fix function completion for that case as `document.charsSequence` for injected code document is not dynamically updated as for usual document.
So, we should to do it manually

#KT-31117 fixed
This commit is contained in:
Ilya Kirillov
2019-08-01 09:34:51 +03:00
parent 84498513f6
commit 3205b25f80
2 changed files with 4 additions and 5 deletions
@@ -104,8 +104,6 @@ class CompletionBindingContextProvider(project: Project) {
}
private fun _getBindingContext(position: PsiElement, resolutionFacade: ResolutionFacade): BindingContext {
assert(!position.isPhysical) // position is in synthetic file
val inStatement = position.findStatementInBlock()
val block = inStatement?.parent as KtBlockExpression?
val prevStatement = inStatement?.siblings(forward = false, withItself = false)?.firstIsInstanceOrNull<KtExpression>()
@@ -91,7 +91,7 @@ sealed class KotlinFunctionInsertHandler(callType: CallType<*>) : KotlinCallable
val document = context.document
val editor = context.editor
val project = context.project
val chars = document.charsSequence
var chars = document.charsSequence
val isSmartEnterCompletion = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR
val isReplaceCompletion = completionChar == Lookup.REPLACE_SELECT_CHAR
@@ -127,6 +127,7 @@ sealed class KotlinFunctionInsertHandler(callType: CallType<*>) : KotlinCallable
if (insertTypeArguments) {
document.insertString(offset, "<>")
chars = document.charsSequence
editor.caretModel.moveToOffset(offset + 1)
offset += 2
}
@@ -160,8 +161,8 @@ sealed class KotlinFunctionInsertHandler(callType: CallType<*>) : KotlinCallable
}
PsiDocumentManager.getInstance(project).commitDocument(document)
openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)!!
closeBracketOffset = chars.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)
openingBracketOffset = document.charsSequence.indexOfSkippingSpace(openingBracket, offset)!!
closeBracketOffset = document.charsSequence.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)
}
if (insertLambda && lambdaInfo!!.explicitParameters) {