Skip to content

Commit

Permalink
feat: restartApplication command (#293)
Browse files Browse the repository at this point in the history
* restartApplication command
  • Loading branch information
MarcinVaadin authored Jan 27, 2025
1 parent f4e73ca commit de0765f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.vaadin.plugin.copilot.handler.Handler
import com.vaadin.plugin.copilot.handler.HandlerResponse
import com.vaadin.plugin.copilot.handler.RedoHandler
import com.vaadin.plugin.copilot.handler.RefreshHandler
import com.vaadin.plugin.copilot.handler.RestartApplicationHandler
import com.vaadin.plugin.copilot.handler.ShowInIdeHandler
import com.vaadin.plugin.copilot.handler.UndoHandler
import com.vaadin.plugin.copilot.handler.WriteBase64FileHandler
Expand Down Expand Up @@ -73,6 +74,7 @@ class CopilotPluginUtil {
REFRESH("refresh"),
SHOW_IN_IDE("showInIde"),
GET_MODULE_PATHS("getModulePaths"),
RESTART_APPLICATION("restartApplication"),
}

private val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.vaadin.intellij-plugin"))?.version
Expand All @@ -99,6 +101,7 @@ class CopilotPluginUtil {
HANDLERS.SHOW_IN_IDE.command -> return ShowInIdeHandler(project, data)
HANDLERS.REFRESH.command -> return RefreshHandler(project)
HANDLERS.GET_MODULE_PATHS.command -> return GetModulePathsHandler(project)
HANDLERS.RESTART_APPLICATION.command -> return RestartApplicationHandler(project)
else -> {
LOG.warn("Command $command not supported by plugin")
return object : Handler {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.vaadin.plugin.copilot.handler

import com.intellij.execution.runners.ExecutionUtil
import com.intellij.execution.ui.RunContentManager
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project

class RestartApplicationHandler(project: Project) : AbstractHandler(project) {

override fun run(): HandlerResponse {
runInEdt {
val contentManager = RunContentManager.getInstance(project)
val selectedDescriptor = contentManager.selectedContent
if (selectedDescriptor != null) {
LOG.debug("Restarting ${selectedDescriptor.displayName} (${project.name})")
ExecutionUtil.restart(selectedDescriptor)
} else {
LOG.debug("Restart of ${project.name} failed - content not found")
}
}
return RESPONSE_OK
}
}

0 comments on commit de0765f

Please sign in to comment.