PY-85162 Add registry key for timeout to guess SDK

(cherry picked from commit b044fee434c707575efe27bb383ef0e57747a347)

IJ-MR-184472

GitOrigin-RevId: ec0c53e404f92c6b75753c8c79b6a2461c2ef461
This commit is contained in:
Alexey Katsman
2025-12-02 19:50:56 +00:00
committed by intellij-monorepo-bot
parent c1189567ed
commit 1a7d3b77fb
2 changed files with 9 additions and 1 deletions
@@ -693,6 +693,8 @@
<!-- Debugger Show value tooltip -->
<registryKey defaultValue="true" description="Show value tooltip" key="python.debugger.show.value.tooltip"/>
<registryKey defaultValue="3" description="Timeout to guess the best suitable SDK when adding new interpreter (seconds)" key="python.guess.sdk.timeout.seconds"/>
</extensions>
<extensionPoints>
@@ -9,6 +9,7 @@ import com.intellij.openapi.ui.ValidationInfo
import com.intellij.openapi.ui.validation.DialogValidationRequestor
import com.intellij.openapi.ui.validation.WHEN_PROPERTY_CHANGED
import com.intellij.openapi.ui.validation.and
import com.intellij.openapi.util.registry.RegistryManager
import com.intellij.platform.ide.progress.ModalTaskOwner
import com.intellij.platform.ide.progress.TaskCancellation
import com.intellij.platform.ide.progress.withModalProgress
@@ -36,6 +37,7 @@ import com.jetbrains.python.sdk.configuration.CreateSdkInfo
import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool
import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus.Internal
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
class ValidationInfoError(val validationInfo: ValidationInfo) : MessageError(validationInfo.message)
@@ -178,7 +180,7 @@ internal class PythonAddCustomInterpreter<P : PathHolder>(
}
else scope.launch(Dispatchers.Default) {
val createSdkInfoWithTool = withModalProgress(ModalTaskOwner.guess(), message("sdk.create.check.environments"), TaskCancellation.cancellable()) {
withTimeoutOrNull(3.seconds) { bestGuessCreateSdkInfo.await() }
withTimeoutOrNull(getGuessSdkTimeout()) { bestGuessCreateSdkInfo.await() }
} ?: return@launch
selectBestTool(createSdkInfoWithTool)
}
@@ -188,6 +190,10 @@ internal class PythonAddCustomInterpreter<P : PathHolder>(
return currentSdkManager.createStatisticsInfo(PythonInterpreterCreationTargets.LOCAL_MACHINE)
}
private fun getGuessSdkTimeout(): Duration = RegistryManager.getInstance().intValue("python.guess.sdk.timeout.seconds").let { i ->
(if (i > 0) i else 3).seconds
}
private fun selectBestTool(createSdkInfoWithTool: CreateSdkInfoWithTool) {
val (manager, configurators) = when (createSdkInfoWithTool.createSdkInfo) {
is CreateSdkInfo.WillCreateEnv -> {