Add Restart action
This commit is contained in:
parent
12745e5e76
commit
300e75c226
3 changed files with 36 additions and 27 deletions
|
|
@ -7,6 +7,12 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys
|
|||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
|
||||
class RestartContinueProcess : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val pluginService = getContinuePluginService(e.project) ?: return
|
||||
pluginService.coreMessengerManager?.restart()
|
||||
}
|
||||
}
|
||||
|
||||
class AcceptDiffAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
|
|
|
|||
|
|
@ -4,48 +4,44 @@ import com.github.continuedev.continueintellijextension.services.TelemetryServic
|
|||
import com.github.continuedev.continueintellijextension.utils.castNestedOrNull
|
||||
import com.github.continuedev.continueintellijextension.utils.getMachineUniqueID
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.project.Project
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class CoreMessengerManager(
|
||||
private val project: Project,
|
||||
private val ideProtocolClient: IdeProtocolClient,
|
||||
private val coroutineScope: CoroutineScope
|
||||
) {
|
||||
|
||||
var coreMessenger: CoreMessenger? = null
|
||||
var coreMessenger: CoreMessenger = createCoreMessenger()
|
||||
private var lastBackoffInterval = 0.5
|
||||
private val log = Logger.getInstance(CoreMessengerManager::class.java)
|
||||
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
setupCoreMessenger()
|
||||
setupAnonymousTelemetry()
|
||||
}
|
||||
|
||||
fun restart() {
|
||||
try {
|
||||
coreMessenger.killSubProcess()
|
||||
lastBackoffInterval *= 2
|
||||
log.warn("Continue process exited, retrying in $lastBackoffInterval seconds")
|
||||
Thread.sleep((lastBackoffInterval * 1000).toLong())
|
||||
coreMessenger = createCoreMessenger()
|
||||
} catch (e: Exception) {
|
||||
service<TelemetryService>().capture("jetbrains_core_start_error", mapOf("error" to e))
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCoreMessenger() {
|
||||
try {
|
||||
coreMessenger = CoreMessenger(project, ideProtocolClient, coroutineScope, onExit = {
|
||||
lastBackoffInterval *= 2
|
||||
println("CoreMessenger exited, retrying in $lastBackoffInterval seconds")
|
||||
Thread.sleep((lastBackoffInterval * 1000).toLong())
|
||||
setupCoreMessenger()
|
||||
})
|
||||
private fun createCoreMessenger() =
|
||||
CoreMessenger(project, ideProtocolClient, coroutineScope, ::restart)
|
||||
|
||||
coreMessenger?.request("config/getSerializedProfileInfo", null, null) { response ->
|
||||
val allowAnonymousTelemetry =
|
||||
response.castNestedOrNull<Boolean>("content", "result", "config", "allowAnonymousTelemetry")
|
||||
|
||||
val telemetryService = service<TelemetryService>()
|
||||
if (allowAnonymousTelemetry == true || allowAnonymousTelemetry == null) {
|
||||
telemetryService.setup(getMachineUniqueID())
|
||||
}
|
||||
}
|
||||
} catch (err: Throwable) {
|
||||
val telemetryService = service<TelemetryService>()
|
||||
telemetryService.capture("jetbrains_core_start_error", mapOf("error" to err))
|
||||
|
||||
err.printStackTrace()
|
||||
private fun setupAnonymousTelemetry() {
|
||||
coreMessenger.request("config/getSerializedProfileInfo", null, null) { response ->
|
||||
val allowAnonymousTelemetry =
|
||||
response.castNestedOrNull<Boolean>("content", "result", "config", "allowAnonymousTelemetry")
|
||||
if (allowAnonymousTelemetry == true || allowAnonymousTelemetry == null)
|
||||
service<TelemetryService>().setup(getMachineUniqueID())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,13 @@
|
|||
<override-text place="GoToAction" text="Continue: Accept Diff"/>
|
||||
</action>
|
||||
|
||||
<action id="continue.restartProcess"
|
||||
class="com.github.continuedev.continueintellijextension.actions.RestartContinueProcess"
|
||||
text="Restart Process"
|
||||
description="Restart Process">
|
||||
<override-text place="GoToAction" text="Continue: Restart Process"/>
|
||||
</action>
|
||||
|
||||
<action id="continue.rejectDiff"
|
||||
class="com.github.continuedev.continueintellijextension.actions.RejectDiffAction"
|
||||
text="Reject Diff" description="Reject Diff">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue