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:
-2
@@ -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>()
|
||||
|
||||
+4
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user