Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restartApplication command #293

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually restart?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It restarts run profile used in current execution environment. Execution environment is found (somehow) from current data context.

Basically it is used in run toolbar while clicking run/restart button.

I might improve it by adding check if our hotswap executor has been used with this project run, currently it will restart anything what is running.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it is needed as long as Copilot uses it from a "Restart now" button or similar

} else {
LOG.debug("Restart of ${project.name} failed - content not found")
}
}
return RESPONSE_OK
}
}
Loading