From 7e72b43d1d0b555d4b8f77edfc31517fffbf8a4f Mon Sep 17 00:00:00 2001 From: Vitaly Legchilkin Date: Wed, 18 Feb 2026 11:24:31 +0100 Subject: [PATCH] PY-87489 Subscribe to currentEditor flow to fix interpreter widget after project cloning StatusBar.currentEditor is a StateFlow initialized with null that resolves asynchronously via a serviceAsync chain. After cloning, the widget's initial update() runs before the flow resolves, so getSelectedFile() returns null and the widget stays hidden. Subscribe to the flow so the widget re-evaluates once the editor becomes available. (cherry picked from commit db0cd436a76fef47e5a1913c2c23b5231c15c60a) IJ-MR-192257 GitOrigin-RevId: 79140e2a60ea656eae21fe9da1f8fdecdb2eb377 --- .../ide/impl/configuration/PySdkStatusBar.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkStatusBar.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkStatusBar.kt index e2526f178b91..22ea24678bb8 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkStatusBar.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PySdkStatusBar.kt @@ -15,6 +15,7 @@ import com.intellij.openapi.roots.ModuleRootListener import com.intellij.openapi.ui.popup.ListPopup import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.wm.StatusBar import com.intellij.openapi.wm.StatusBarWidget import com.intellij.openapi.wm.StatusBarWidgetFactory import com.intellij.openapi.wm.impl.status.EditorBasedStatusBarPopup @@ -28,6 +29,7 @@ import com.jetbrains.python.sdk.PySdkPopupFactory.Companion.shortenNameInPopup import com.jetbrains.python.sdk.legacy.PythonSdkUtil import com.jetbrains.python.sdk.noInterpreterMarker import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch private const val ID: String = "pythonInterpreterWidget" @@ -69,6 +71,15 @@ private class PySdkStatusBar(project: Project, scope: CoroutineScope) : EditorBa scope = scope) { private var module: Module? = null + override fun install(statusBar: StatusBar) { + super.install(statusBar) + // statusBar.currentEditor resolves asynchronously via serviceAsync chain (with null as initial value); + // subscribe to it so the widget re-evaluates once the editor becomes available + scope.launch { + statusBar.currentEditor.collect { update() } + } + } + override fun getWidgetState(file: VirtualFile?): WidgetState { module = findModule(file) ?: return WidgetState.HIDDEN