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 {
|
private fun _getBindingContext(position: PsiElement, resolutionFacade: ResolutionFacade): BindingContext {
|
||||||
assert(!position.isPhysical) // position is in synthetic file
|
|
||||||
|
|
||||||
val inStatement = position.findStatementInBlock()
|
val inStatement = position.findStatementInBlock()
|
||||||
val block = inStatement?.parent as KtBlockExpression?
|
val block = inStatement?.parent as KtBlockExpression?
|
||||||
val prevStatement = inStatement?.siblings(forward = false, withItself = false)?.firstIsInstanceOrNull<KtExpression>()
|
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 document = context.document
|
||||||
val editor = context.editor
|
val editor = context.editor
|
||||||
val project = context.project
|
val project = context.project
|
||||||
val chars = document.charsSequence
|
var chars = document.charsSequence
|
||||||
|
|
||||||
val isSmartEnterCompletion = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR
|
val isSmartEnterCompletion = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR
|
||||||
val isReplaceCompletion = completionChar == Lookup.REPLACE_SELECT_CHAR
|
val isReplaceCompletion = completionChar == Lookup.REPLACE_SELECT_CHAR
|
||||||
@@ -127,6 +127,7 @@ sealed class KotlinFunctionInsertHandler(callType: CallType<*>) : KotlinCallable
|
|||||||
|
|
||||||
if (insertTypeArguments) {
|
if (insertTypeArguments) {
|
||||||
document.insertString(offset, "<>")
|
document.insertString(offset, "<>")
|
||||||
|
chars = document.charsSequence
|
||||||
editor.caretModel.moveToOffset(offset + 1)
|
editor.caretModel.moveToOffset(offset + 1)
|
||||||
offset += 2
|
offset += 2
|
||||||
}
|
}
|
||||||
@@ -160,8 +161,8 @@ sealed class KotlinFunctionInsertHandler(callType: CallType<*>) : KotlinCallable
|
|||||||
}
|
}
|
||||||
PsiDocumentManager.getInstance(project).commitDocument(document)
|
PsiDocumentManager.getInstance(project).commitDocument(document)
|
||||||
|
|
||||||
openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)!!
|
openingBracketOffset = document.charsSequence.indexOfSkippingSpace(openingBracket, offset)!!
|
||||||
closeBracketOffset = chars.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)
|
closeBracketOffset = document.charsSequence.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insertLambda && lambdaInfo!!.explicitParameters) {
|
if (insertLambda && lambdaInfo!!.explicitParameters) {
|
||||||
|
|||||||
Reference in New Issue
Block a user