diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 6dccf7f088..d0f0da7618 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -51,6 +51,7 @@ import java.net.NetworkInterface import java.nio.charset.Charset import java.nio.file.Paths import java.util.* +import kotlin.coroutines.resume fun uuid(): String { @@ -106,7 +107,9 @@ class AsyncFileSaveListener(private val ideProtocolClient: IdeProtocolClient) : for (event in events) { if (event.path.endsWith(".continue/config.json") || event.path.endsWith(".continue/config.ts") || event.path.endsWith( ".continue\\config.json" - ) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json") || event.path.endsWith(".continuerc.json") + ) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json") || event.path.endsWith( + ".continuerc.json" + ) ) { return object : AsyncFileListener.ChangeApplier { override fun afterVfsChange() { @@ -662,18 +665,41 @@ class IdeProtocolClient( var llm = getModelByRole(config, "applyCodeBlock") if (llm == null) { - val models = (config as? Map<*, *>)?.get("models") as? List> - llm = models?.find { model -> model["title"] == curSelectedModelTitle } as Map - - if (llm == null) { - showToast("error", "Model '$curSelectedModelTitle' not found in config.") + llm = try { + suspendCancellableCoroutine { continuation -> + continuePluginService.coreMessenger?.request( + "config/getSerializedProfileInfo", + null, + null + ) { response -> + val models = + ((response as Map)["config"] as Map)["models"] as List> + val foundModel = models.find { it["title"] == curSelectedModelTitle } + + if (foundModel == null) { + launch { + showToast( + "error", + "Model '$curSelectedModelTitle' not found in config." + ) + } + continuation.resume(null) + } else { + continuation.resume(foundModel) + } + } + } + } catch (e: Exception) { + launch { showToast("error", "Failed to fetch model configuration") } respond(null) return@launch } } + val llmTitle = (llm as? Map<*, *>)?.get("title") as? String ?: "" + val prompt = "The following code was suggested as an edit:\n```\n${text}\n```\nPlease apply it to the previous code."