Add a shortcut for interrupting the program (#3967)

Add shortcuts for interrupting and restarting the program execution.
This commit is contained in:
Dmitry Bushev 2022-12-12 20:48:42 +03:00 committed by GitHub
parent 79de5eecd9
commit 957279153a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 0 deletions

View File

@ -74,6 +74,7 @@
- [Added scroll bounce animation][3836] which activates when scrolling past the
end of scrollable content.
- [Added project snapshot saving on shortcut][3923]
- [Added shortcut to interrupt the program][3967]
#### EnsoGL (rendering engine)
@ -403,6 +404,7 @@
[3885]: https://github.com/enso-org/enso/pull/3885
[3919]: https://github.com/enso-org/enso/pull/3919
[3923]: https://github.com/enso-org/enso/pull/3923
[3967]: https://github.com/enso-org/enso/pull/3967
#### Enso Compiler

View File

@ -151,6 +151,14 @@ trait API {
fn modify_visualisation
(&self, visualisation_id: Uuid, visualisation_config: VisualisationConfiguration) -> ();
/// Interrupt the program execution.
#[MethodInput=InterruptInput, rpc_name="executionContext/interrupt"]
fn interrupt(&self, context_id: ContextId) -> ();
/// Restart the program execution.
#[MethodInput=RecomputeInput, rpc_name="executionContext/recompute"]
fn recompute(&self, context_id: ContextId) -> ();
/// Obtain the full suggestions database.
#[MethodInput=GetSuggestionsDatabaseInput, rpc_name="search/getSuggestionsDatabase"]
fn get_suggestions_database(&self) -> response::GetSuggestionDatabase;

View File

@ -48,6 +48,8 @@ broken and require further investigation.
| <kbd>ctrl</kbd>+<kbd>w</kbd> | Close the application (Windows, Linux) |
| :warning: <kbd>ctrl</kbd>+<kbd>p</kbd> | Toggle profiling mode |
| <kbd>escape</kbd> | Cancel current action. For example, drop currently dragged connection. |
| <kbd>cmd</kbd>+<kbd>shift</kbd>+<kbd>t</kbd> | Terminate the program execution |
| <kbd>cmd</kbd>+<kbd>shift</kbd>+<kbd>r</kbd> | Re-execute the program |
#### Navigation

View File

@ -279,6 +279,18 @@ impl Handle {
Ok(())
}
/// Interrupt the program execution.
pub async fn interrupt(&self) -> FallibleResult {
self.execution_ctx.interrupt().await?;
Ok(())
}
/// Restart the program execution.
pub async fn restart(&self) -> FallibleResult {
self.execution_ctx.restart().await?;
Ok(())
}
/// Get the current call stack frames.
pub fn call_stack(&self) -> Vec<LocalCall> {
self.execution_ctx.stack_items().collect()

View File

@ -493,6 +493,14 @@ pub trait API: Debug {
let detach_actions = visualizations.into_iter().map(move |v| self.detach_visualization(v));
futures::future::join_all(detach_actions).boxed_local()
}
/// Interrupt the program execution.
#[allow(clippy::needless_lifetimes)] // Note: Needless lifetimes
fn interrupt<'a>(&'a self) -> BoxFuture<'a, FallibleResult>;
/// Restart the program execution.
#[allow(clippy::needless_lifetimes)] // Note: Needless lifetimes
fn restart<'a>(&'a self) -> BoxFuture<'a, FallibleResult>;
}
// Note: Needless lifetimes

View File

@ -250,6 +250,14 @@ impl model::execution_context::API for ExecutionContext {
Err(InvalidVisualizationId(visualization_id).into())
}
}
fn interrupt(&self) -> BoxFuture<FallibleResult> {
futures::future::ready(Ok(())).boxed_local()
}
fn restart(&self) -> BoxFuture<FallibleResult> {
futures::future::ready(Ok(())).boxed_local()
}
}

View File

@ -289,6 +289,22 @@ impl model::execution_context::API for ExecutionContext {
debug!("Dispatching visualization update through the context {}", self.id());
self.model.dispatch_visualization_update(visualization_id, data)
}
fn interrupt(&self) -> BoxFuture<FallibleResult> {
async move {
self.language_server.client.interrupt(&self.id).await?;
Ok(())
}
.boxed_local()
}
fn restart(&self) -> BoxFuture<FallibleResult> {
async move {
self.language_server.client.recompute(&self.id).await?;
Ok(())
}
.boxed_local()
}
}
impl Drop for ExecutionContext {

View File

@ -177,6 +177,24 @@ impl Model {
}
})
}
fn execution_context_interrupt(&self) {
let controller = self.graph_controller.clone_ref();
executor::global::spawn(async move {
if let Err(err) = controller.interrupt().await {
error!("Error interrupting execution context: {err}");
}
})
}
fn execution_context_restart(&self) {
let controller = self.graph_controller.clone_ref();
executor::global::spawn(async move {
if let Err(err) = controller.restart().await {
error!("Error restarting execution context: {err}");
}
})
}
}
@ -246,6 +264,10 @@ impl Project {
view.values_updated <+ values_computed;
eval_ view.save_project_snapshot(model.save_project_snapshot());
eval_ view.execution_context_interrupt(model.execution_context_interrupt());
eval_ view.execution_context_restart(model.execution_context_restart());
}
let graph_controller = self.model.graph_controller.clone_ref();

View File

@ -84,6 +84,10 @@ ensogl::define_endpoints! {
disable_debug_mode(),
/// A set of value updates has been processed and rendered.
values_updated(),
/// Interrupt the running program.
execution_context_interrupt(),
/// Restart the program execution.
execution_context_restart(),
}
Output {
@ -834,6 +838,8 @@ impl application::View for View {
(Press, "", "cmd y", "redo"),
(Press, "!debug_mode", DEBUG_MODE_SHORTCUT, "enable_debug_mode"),
(Press, "debug_mode", DEBUG_MODE_SHORTCUT, "disable_debug_mode"),
(Press, "", "cmd shift t", "execution_context_interrupt"),
(Press, "", "cmd shift r", "execution_context_restart"),
]
.iter()
.map(|(a, b, c, d)| Self::self_shortcut_when(*a, *c, *d, *b))