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

Execution environment integration fixes. #6434

Merged
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions app/gui/controller/engine-protocol/src/language_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,29 +1184,6 @@ impl ExecutionEnvironment {
pub fn list_all() -> Vec<Self> {
vec![ExecutionEnvironment::Design, ExecutionEnvironment::Live]
}

/// List all available execution environments as ImStrings. Useful for UI.
pub fn list_all_as_imstrings() -> Vec<ImString> {
Self::list_all().iter().map(|env| (*env).into()).collect()
}
}

impl From<ExecutionEnvironment> for ImString {
fn from(env: ExecutionEnvironment) -> Self {
ImString::new(env.to_string())
}
}

impl TryFrom<&str> for ExecutionEnvironment {
type Error = ();

fn try_from(value: &str) -> core::result::Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"design" => Ok(ExecutionEnvironment::Design),
"live" => Ok(ExecutionEnvironment::Live),
_ => Err(()),
}
}
}

impl ExecutionEnvironment {
Expand Down
5 changes: 3 additions & 2 deletions app/gui/docs/product/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ broken and require further investigation.
#### General Shortcuts

| Shortcut | Action |
| ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|---------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <kbd>cmd</kbd>+<kbd>alt</kbd>+<kbd>shift</kbd>+<kbd>t</kbd> | Toggle light/dark application style. Currently doesn't work properly, as the Theme Switcher is not created yet. (https://github.com/enso-org/ide/issues/795) |
| <kbd>ctrl</kbd>+<kbd>`</kbd> | Show Code Editor. Please note that the Code Editor implementation is in a very early stage and you should not use it. Even just openning it can cause errors in the IDE. Do not try using the graph editor while having the code editor tab openned. |
| <kbd>cmd</kbd>+<kbd>o</kbd> | Open project |
Expand All @@ -50,7 +50,8 @@ broken and require further investigation.
| <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 |
| <kbd>cmd</kbd>+<kbd>shift</kbd>+<kbd>e</kbd> | Toggle the execution environment between Live and Design. |
| <kbd>cmd</kbd>+<kbd>shift</kbd>+<kbd>k</kbd> | Switch the execution environment to Design. |
| <kbd>cmd</kbd>+<kbd>shift</kbd>+<kbd>l</kbd> | Switch the execution environment to Live. |

#### Navigation

Expand Down
5 changes: 5 additions & 0 deletions app/gui/src/controller/graph/executed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ impl Handle {
self.execution_ctx.set_execution_environment(execution_environment).await?;
Ok(())
}

/// Get the current execution environment.
pub fn execution_environment(&self) -> ExecutionEnvironment {
self.execution_ctx.execution_environment()
}
}


Expand Down
3 changes: 3 additions & 0 deletions app/gui/src/model/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ pub trait API: Debug {
&'a self,
execution_environment: ExecutionEnvironment,
) -> BoxFuture<'a, FallibleResult>;

/// Get the execution environment of the context.
fn execution_environment(&self) -> ExecutionEnvironment;
}

// Note: Needless lifetimes
Expand Down
4 changes: 4 additions & 0 deletions app/gui/src/model/execution_context/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ impl model::execution_context::API for ExecutionContext {
self.execution_environment.set(environment);
futures::future::ready(Ok(())).boxed_local()
}

fn execution_environment(&self) -> ExecutionEnvironment {
self.execution_environment.get()
}
}


Expand Down
4 changes: 4 additions & 0 deletions app/gui/src/model/execution_context/synchronized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ impl model::execution_context::API for ExecutionContext {
}
.boxed_local()
}

fn execution_environment(&self) -> ExecutionEnvironment {
self.model.execution_environment.get()
}
}

impl Drop for ExecutionContext {
Expand Down
38 changes: 8 additions & 30 deletions app/gui/src/presenter/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::presenter::graph::state::State;
use double_representation::context_switch::Context;
use double_representation::context_switch::ContextSwitch;
use double_representation::context_switch::ContextSwitchExpression;
use engine_protocol::language_server::ExecutionEnvironment;
use engine_protocol::language_server::SuggestionId;
use enso_frp as frp;
use futures::future::LocalBoxFuture;
Expand Down Expand Up @@ -83,15 +82,13 @@ pub fn default_node_position() -> Vector2 {

#[derive(Debug)]
struct Model {
project: model::Project,
controller: controller::ExecutedGraph,
view: view::graph_editor::GraphEditor,
state: Rc<State>,
_visualization: Visualization,
widget: controller::Widget,
_execution_stack: CallStack,
// TODO(#5930): Move me once we synchronise the execution environment with the language server.
execution_environment: Rc<Cell<ExecutionEnvironment>>,
project: model::Project,
controller: controller::ExecutedGraph,
view: view::graph_editor::GraphEditor,
state: Rc<State>,
_visualization: Visualization,
widget: controller::Widget,
_execution_stack: CallStack,
}

impl Model {
Expand All @@ -118,7 +115,6 @@ impl Model {
_visualization: visualization,
widget,
_execution_stack: execution_stack,
execution_environment: Default::default(),
}
}

Expand Down Expand Up @@ -188,7 +184,7 @@ impl Model {
/// ```
fn node_action_context_switch(&self, id: ViewNodeId, active: bool) {
let context = Context::Output;
let environment = self.execution_environment.get();
let environment = self.controller.execution_environment();
let current_state = environment.output_context_enabled();
let switch = if current_state { ContextSwitch::Disable } else { ContextSwitch::Enable };
let expr = if active {
Expand Down Expand Up @@ -493,15 +489,6 @@ impl Model {
}
}
}

fn toggle_execution_environment(&self) -> ExecutionEnvironment {
let new_environment = match self.execution_environment.get() {
ExecutionEnvironment::Live => ExecutionEnvironment::Design,
ExecutionEnvironment::Design => ExecutionEnvironment::Live,
};
self.execution_environment.set(new_environment);
new_environment
}
}


Expand Down Expand Up @@ -717,15 +704,6 @@ impl Graph {
}
}));


// === Execution Environment ===

// TODO(#5930): Delete me once we synchronise the execution environment with the
// language server.
view.set_execution_environment <+ view.toggle_execution_environment.map(
f_!(model.toggle_execution_environment()));


// === Refreshing Nodes ===

remove_node <= update_data.map(|update| update.remove_nodes());
Expand Down
26 changes: 11 additions & 15 deletions app/gui/src/presenter/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,16 @@ impl Model {

fn execution_environment_changed(
&self,
execution_environment: &ide_view::execution_environment_selector::ExecutionEnvironment,
execution_environment: ide_view::execution_environment_selector::ExecutionEnvironment,
) {
if let Ok(execution_environment) = execution_environment.as_str().try_into() {
let graph_controller = self.graph_controller.clone_ref();
executor::global::spawn(async move {
if let Err(err) =
graph_controller.set_execution_environment(execution_environment).await
{
error!("Error setting execution environment: {err}");
}
});
} else {
error!("Invalid execution environment: {execution_environment:?}");
}
let graph_controller = self.graph_controller.clone_ref();
executor::global::spawn(async move {
if let Err(err) =
graph_controller.set_execution_environment(execution_environment).await
{
error!("Error setting execution environment: {err}");
}
});
}
}

Expand Down Expand Up @@ -404,7 +400,7 @@ impl Project {
eval_ view.execution_context_restart(model.execution_context_restart());

view.set_read_only <+ view.toggle_read_only.map(f_!(model.toggle_read_only()));
eval graph_view.execution_environment((env) model.execution_environment_changed(env));
eval graph_view.execution_environment((env) model.execution_environment_changed(*env));
}

let graph_controller = self.model.graph_controller.clone_ref();
Expand All @@ -418,7 +414,7 @@ impl Project {
/// Initialises execution environment.
fn init_execution_environments(self) -> Self {
let graph = &self.model.view.graph();
let entries = Rc::new(ExecutionEnvironment::list_all_as_imstrings());
let entries = Rc::new(ExecutionEnvironment::list_all());
graph.set_available_execution_environments(entries);
self
}
Expand Down
1 change: 1 addition & 0 deletions app/gui/view/execution-environment-selector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ ensogl-drop-down-menu = { path = "../../../../lib/rust/ensogl/component/drop-dow
ensogl-gui-component = { path = "../../../../lib/rust/ensogl/component/gui" }
ensogl-hardcoded-theme = { path = "../../../../lib/rust/ensogl/app/theme/hardcoded" }
ensogl-list-view = { path = "../../../../lib/rust/ensogl/component/list-view" }
engine-protocol = { path = "../../controller/engine-protocol" }
14 changes: 8 additions & 6 deletions app/gui/view/execution-environment-selector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ impl Style {
// ===========

/// An identifier of a execution environment.
pub type ExecutionEnvironment = ImString;
pub type ExecutionEnvironment = engine_protocol::language_server::ExecutionEnvironment;

/// A list of execution environments.
pub type ExecutionEnvironments = Rc<Vec<ExecutionEnvironment>>;

/// Provide a dummy list of execution environments. Used for testing and demo scenes.
pub fn make_dummy_execution_environments() -> ExecutionEnvironments {
Rc::new(vec!["Design".to_string().into(), "Live".to_string().into()])
Rc::new(ExecutionEnvironment::list_all())
}

ensogl::define_endpoints_2! {
Expand Down Expand Up @@ -156,7 +157,8 @@ impl Model {
}

fn set_entries(&self, entries: Rc<Vec<ExecutionEnvironment>>) {
let provider = ensogl_list_view::entry::AnyModelProvider::from(entries.clone_ref());
let labels = Rc::new(entries.iter().map(|e| e.to_string()).collect_vec());
let provider = ensogl_list_view::entry::AnyModelProvider::from(labels);
self.dropdown.set_entries(provider);
self.dropdown.set_selected(0);
}
Expand Down Expand Up @@ -260,11 +262,11 @@ impl component::Frp<Model> for Frp {

selected_id <- dropdown.frp.chosen_entry.unwrap();
selection <- all(input.set_available_execution_environments, selected_id);
selected_entry <- selection.map(|(entries, entry_id)| entries[*entry_id].clone());
output.selected_execution_environment <+ selected_entry;
selected_entry <- selection.map(|(entries, entry_id)| entries[*entry_id]);
output.selected_execution_environment <+ selected_entry.on_change();

eval selected_entry ([model] (execution_mode) {
let play_button_visibility = matches!(execution_mode.to_lowercase().as_str(), "design");
let play_button_visibility = matches!(execution_mode, ExecutionEnvironment::Design);
model.set_play_button_visibility(play_button_visibility);
});
play_button.reset <+ selected_entry.constant(());
Expand Down
28 changes: 6 additions & 22 deletions app/gui/view/graph-editor/src/execution_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ use super::*;

use crate::Frp;

use ide_view_execution_environment_selector::ExecutionEnvironment;



// =============================
// === Execution Environment ===
// =============================

fn get_next_execution_environment(
current: &ExecutionEnvironment,
available: &[ExecutionEnvironment],
) -> Option<ExecutionEnvironment> {
let index = available.iter().position(|mode| mode == current)?;
let next_index = (index + 1) % available.len();
Some(available[next_index].clone())
}

/// Initialise the FRP logic for the execution environment selector.
pub fn init_frp(frp: &Frp, model: &GraphEditorModelWithNetwork) {
let out = &frp.private.output;
Expand All @@ -34,20 +23,15 @@ pub fn init_frp(frp: &Frp, model: &GraphEditorModelWithNetwork) {
// === Execution Environment Changes ===

selector.set_available_execution_environments <+ frp.set_available_execution_environments;
selected_environment <- frp.set_execution_environment.map(|env| (*env).into());
environment_state
<- all(out.execution_environment,frp.set_available_execution_environments);

environment_toggled <- environment_state.sample(&frp.toggle_execution_environment);
toggled_execution_environment <- environment_toggled.map(|(mode,available)|
get_next_execution_environment(mode,available)).unwrap();

external_update <- any(selected_environment,toggled_execution_environment);
toggle_to_live <-
frp.switch_to_live_execution_environment.constant(ExecutionEnvironment::Live);
toggle_to_design <-
frp.switch_to_design_execution_environment.constant(ExecutionEnvironment::Design);
external_update <- any(toggle_to_live,toggle_to_design);
selector.set_execution_environment <+ external_update;

execution_environment_update
<- any(selector.selected_execution_environment,external_update);
out.execution_environment <+ execution_environment_update;
out.execution_environment <+ selector.selected_execution_environment.on_change();
out.execution_environment_play_button_pressed <+ selector.play_press;


Expand Down
13 changes: 6 additions & 7 deletions app/gui/view/graph-editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,10 @@ ensogl::define_endpoints_2! {

// === Execution Environment ===

// TODO(#5930): Temporary shortcut for testing different execution environments
toggle_execution_environment(),
/// Set the execution environmenta available to the graph.
set_available_execution_environments (Rc<Vec<execution_environment_selector::ExecutionEnvironment>>),
set_execution_environment (ExecutionEnvironment),
/// Set the execution environments available to the graph.
set_available_execution_environments (Rc<Vec<ExecutionEnvironment>>),
switch_to_design_execution_environment(),
switch_to_live_execution_environment(),


// === Debug ===
Expand Down Expand Up @@ -767,7 +766,7 @@ ensogl::define_endpoints_2! {
min_x_spacing_for_new_nodes (f32),

/// The selected environment mode.
execution_environment (execution_environment_selector::ExecutionEnvironment),
execution_environment (ExecutionEnvironment),
/// A press of the execution environment selector play button.
execution_environment_play_button_pressed (),
}
Expand Down Expand Up @@ -1732,7 +1731,7 @@ impl GraphEditorModelWithNetwork {

// === Execution Environment ===

node.set_execution_environment <+ self.model.frp.input.set_execution_environment;
node.set_execution_environment <+ self.model.frp.output.execution_environment;
}


Expand Down
5 changes: 3 additions & 2 deletions app/gui/view/graph-editor/src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub const SHORTCUTS: &[(ensogl::application::shortcut::ActionType, &str, &str, &
(Press, "debug_mode", "ctrl shift enter", "debug_push_breadcrumb"),
(Press, "debug_mode", "ctrl shift up", "debug_pop_breadcrumb"),
(Press, "debug_mode", "ctrl n", "add_node_at_cursor"),
vitvakatu marked this conversation as resolved.
Show resolved Hide resolved
// === Execution Mode ===
(Press, "", "shift ctrl e", "toggle_execution_environment"),
vitvakatu marked this conversation as resolved.
Show resolved Hide resolved
// Execution Environment
(Press, "", "cmd shift k", "switch_to_design_execution_environment"),
(Press, "", "cmd shift l", "switch_to_live_execution_environment"),
];