diff --git a/platform/platform-impl/rpc/src/com/intellij/ide/rpc/BackendBasedDocument.kt b/platform/platform-impl/rpc/src/com/intellij/ide/rpc/BackendBasedDocument.kt index 9c67cecfc007..b8dc99194ffe 100644 --- a/platform/platform-impl/rpc/src/com/intellij/ide/rpc/BackendBasedDocument.kt +++ b/platform/platform-impl/rpc/src/com/intellij/ide/rpc/BackendBasedDocument.kt @@ -36,13 +36,13 @@ fun Document.bindToBackend( val builder = BackendDocumentBindBuilder().apply(builder) val backendDocumentIdProvider = builder.backendDocumentIdProvider val documentBound = if (backendDocumentIdProvider != null) { - bindToBackend(backendDocumentIdProvider, builder.onBindingDispose) + bindToBackend(backendDocumentIdProvider, builder.onBindingDispose, builder.bindEditors) } else { true } - if (documentBound && builder.bindEditors) { + if (documentBound && builder.bindEditors && backendDocumentIdProvider == null) { // mark the document, so future editors will be bind bindEditorsToBackend() // bind current editors (since they might be created during backends' documents initialization) @@ -90,11 +90,12 @@ private fun Document.bindCurrentEditors() { private suspend fun Document.bindToBackend( backendDocumentIdProvider: suspend (FrontendDocumentId) -> BackendDocumentId?, onBindingDispose: (() -> Unit)?, + bindEditors: Boolean, ): Boolean { val frontendDocument = this val frontendDocumentId = FrontendDocumentId(UID.random()) val registry = FrontendDocumentIdRegistry.EP_NAME.extensionList.firstOrNull() - registry?.registerFrontendDocumentId(frontendDocumentId, frontendDocument, onBindingDispose) + registry?.registerFrontendDocumentId(frontendDocumentId, frontendDocument, onBindingDispose, bindEditors) var backendDocumentId: BackendDocumentId? = null try { backendDocumentId = backendDocumentIdProvider(frontendDocumentId) @@ -164,7 +165,12 @@ interface FrontendDocumentIdRegistry { // TODO: should we deal with session here, // so that it will be registered for session not not app level? - fun registerFrontendDocumentId(frontendDocumentId: FrontendDocumentId, frontendDocument: Document, onBindingDispose: (() -> Unit)?) + fun registerFrontendDocumentId( + frontendDocumentId: FrontendDocumentId, + frontendDocument: Document, + onBindingDispose: (() -> Unit)?, + bindEditors: Boolean, + ) fun unregisterFrontendDocumentId(frontendDocumentId: FrontendDocumentId) } diff --git a/platform/platform-impl/rpc/src/com/intellij/ide/rpc/FileTypeBindings.kt b/platform/platform-impl/rpc/src/com/intellij/ide/rpc/FileTypeBindings.kt index 3a2395199ffa..367de5cd36f5 100644 --- a/platform/platform-impl/rpc/src/com/intellij/ide/rpc/FileTypeBindings.kt +++ b/platform/platform-impl/rpc/src/com/intellij/ide/rpc/FileTypeBindings.kt @@ -13,7 +13,7 @@ import org.jetbrains.annotations.ApiStatus */ // TODO: it is not ok to attach Document to fileType @ApiStatus.Internal -internal fun Document.bindEditorsToBackend() { +fun Document.bindEditorsToBackend() { this.putUserData(BIND_DOCUMENT_EDITORS, true) } @@ -34,4 +34,4 @@ fun Editor.shouldBindToBackend(): Boolean { } @ApiStatus.Internal -private val BIND_DOCUMENT_EDITORS: Key = Key("bindDocumentEditors") \ No newline at end of file +private val BIND_DOCUMENT_EDITORS: Key = Key("bindDocumentEditors")