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 9e4accc7e41f..9c67cecfc007 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 @@ -35,11 +35,14 @@ fun Document.bindToBackend( service().cs.launch(Dispatchers.EDT) { val builder = BackendDocumentBindBuilder().apply(builder) val backendDocumentIdProvider = builder.backendDocumentIdProvider - if (backendDocumentIdProvider != null) { + val documentBound = if (backendDocumentIdProvider != null) { bindToBackend(backendDocumentIdProvider, builder.onBindingDispose) } + else { + true + } - if (builder.bindEditors) { + if (documentBound && builder.bindEditors) { // mark the document, so future editors will be bind bindEditorsToBackend() // bind current editors (since they might be created during backends' documents initialization) @@ -87,7 +90,7 @@ private fun Document.bindCurrentEditors() { private suspend fun Document.bindToBackend( backendDocumentIdProvider: suspend (FrontendDocumentId) -> BackendDocumentId?, onBindingDispose: (() -> Unit)?, -) { +): Boolean { val frontendDocument = this val frontendDocumentId = FrontendDocumentId(UID.random()) val registry = FrontendDocumentIdRegistry.EP_NAME.extensionList.firstOrNull() @@ -102,6 +105,7 @@ private suspend fun Document.bindToBackend( registry?.unregisterFrontendDocumentId(frontendDocumentId) } } + return backendDocumentId != null } @ApiStatus.Internal @@ -188,4 +192,4 @@ interface BackendDocumentBinder { // TODO: should BackendBasedDocument take cs as argument? Let's see by usages @Service(Service.Level.APP) -private class BackendBasedDocumentCoroutineScopeProvider(val cs: CoroutineScope) \ No newline at end of file +private class BackendBasedDocumentCoroutineScopeProvider(val cs: CoroutineScope)