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

Ability to change the execution environment between design and live. #6341

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Apr 18, 2023

Pull Request Description

Integrate the UI for electing the Execution Environment with the Language Server and unify existing uses. Implements #5930 + actual integration instead of just mocking it.

Peek.2023-04-18.23-32.mp4

Important Notes

The console output is only emitted as part of the INFO level. A better check would be to look at the messages sent to the backend in the developer console.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@MichaelMauderer MichaelMauderer self-assigned this Apr 18, 2023
@MichaelMauderer MichaelMauderer marked this pull request as ready for review April 18, 2023 22:40
@enso-bot
Copy link

enso-bot bot commented Apr 18, 2023

Michael Mauderer reports a new STANDUP for today (2023-04-18):

Progress: Updated the PR for this task: integrated with the now existing backend API and merged with already implemented functionality on develop. It should be finished by 2023-04-19.

Next Day: Next day I will be working on the #6179 task. Do the same for 6179

Comment on lines +1167 to +1173
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Display)]
pub enum ExecutionEnvironment {
/// Allows editing the graph, but the `Output` context is disabled, so it prevents accidental
/// changes.
Design,
/// Unrestricted, live editing of data.
Live,
Copy link
Member

Choose a reason for hiding this comment

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

  1. I believe we have the strings "design" and "live" hardcoded somewhere in the previous PR.
  2. I don't think that hardcoding that as enum is a good option, as these 2 options are temporary and we will allow users defining custom modes. So we should keep the current mode in string-like struct instead.
  3. This will also make all of helper functions simpler, such as list_all_imstrings.
  4. Function list_all is similar to a function in previous PR, which was already listing all available execution environments, we should unify these codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here they need to be hard-codes as enum, as this is the current LS protocol. The UI elements can handle arbitrary labels. So, would suggest this to be refactored appropriately once custom modes are implemented.

Comment on lines 1203 to 1208
fn try_from(value: &str) -> core::result::Result<Self, Self::Error> {
match value {
"design" | "Design" => Ok(ExecutionEnvironment::Design),
"live" | "Live" => Ok(ExecutionEnvironment::Live),
_ => Err(()),
}
Copy link
Member

Choose a reason for hiding this comment

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

If we want to be error prone, why don't we just do value.to_lowercase() instead?

@@ -308,6 +313,16 @@ impl model::execution_context::API for ExecutionContext {
fn rename_method_pointers(&self, old_project_name: String, new_project_name: String) {
self.model.rename_method_pointers(old_project_name, new_project_name);
}

fn set_mode(&self, mode: ExecutionEnvironment) -> BoxFuture<FallibleResult> {
Copy link
Member

Choose a reason for hiding this comment

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

sometimes the var with exec env is called environment, sometimes mode. This is a minor inconsistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope I spotted the last ones I missed. Will double-check again.

}
});
} else {
error!("Invalid execution mode: {mode:?}");
Copy link
Member

Choose a reason for hiding this comment

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

naming inconsistency - execution mode is not a valid name anymore.

fn make_entries() -> execution_mode_selector::ExecutionModes {
Rc::new(vec!["development".to_string(), "production".to_string()])
fn make_entries() -> ExecutionEnvironments {
Rc::new(vec!["Design".to_string().into(), "Live".to_string().into()])
Copy link
Member

Choose a reason for hiding this comment

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

another hardcoded place with the modes. I would like to ask that all mode names will be defined ONLY in one place in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want all of them in one place only because of crate dependencies: we have a simple demo scene for a chooser that can take arbitrary labels. This element and its demo scene do not need to know about the language server protocol that contains our current ExecutionEnvironment and its valid values. So, it makes sense to just use fixed dummy values there. We can unify those dummy values between the two demo scenes, but I would argue against introducing a dependency on the LS protocol.

Comment on lines 260 to 261
"Live".to_string().into(),
"Design".to_string().into(),
Copy link
Member

Choose a reason for hiding this comment

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

yet another place with mode names. I know this is an example, but as we are keeping it sync'ed with the names, it should probably use the same names defined in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(see above)

Comment on lines 37 to 44
execution_environment_state <- all(out.execution_environment,frp.set_available_execution_environments);

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

external_execution_environment_update <- any(selected_execution_environment,toggled_execution_environment);
execution_environment_selector.set_execution_environment <+ external_execution_environment_update;

Copy link
Member

Choose a reason for hiding this comment

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

100 chars

Comment on lines 52 to 64
init <- source::<()>();
size_update <- all(init,execution_environment_selector.size,inputs.space_for_window_buttons);
eval size_update ([model]((_,size,gap_size)) {
let y_offset = MACOS_TRAFFIC_LIGHTS_VERTICAL_CENTER;
let traffic_light_width = traffic_lights_gap_width();

let execution_environment_selector_x = gap_size.x + traffic_light_width;
model.execution_environment_selector.set_x(execution_environment_selector_x);
let breadcrumb_gap_width = execution_environment_selector_x + size.x + TOP_BAR_ITEM_MARGIN;
model.breadcrumbs.gap_width(breadcrumb_gap_width);

model.execution_environment_selector.set_y(y_offset + size.y / 2.0);
model.breadcrumbs.set_y(y_offset + component::breadcrumbs::HEIGHT / 2.0);
Copy link
Member

Choose a reason for hiding this comment

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

Did you try to use auto-layout instead? I believe the auto-layout would make it a lot simpler. Or is it impossible to be used because of some reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Auto layout would require some larger refactoring we want to avoid doing right now. Some of these components are part of the application and some are part of the graph editor. We should at some point unify them, use layouts and get rid of the constants. Please also note that this is old code that just got moved.

use ensogl::application::shortcut::ActionType::*;



Copy link
Member

Choose a reason for hiding this comment

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

no sections

@MichaelMauderer MichaelMauderer requested a review from wdanilo April 21, 2023 09:59
…_execution_environment_between_design_and_live_on_shortcut

# Conflicts:
#	app/gui/src/presenter/project.rs
#	app/gui/view/examples/execution-environment-dropdown/src/lib.rs
#	app/gui/view/examples/interface/src/lib.rs
#	app/gui/view/execution-environment-selector/src/lib.rs
#	app/gui/view/execution-environment-selector/src/play_button.rs
CHANGELOG.md Outdated
Comment on lines 135 to 136
- - [The IDE UI element for selecting the execution mode of the
project is now sending messages to the backend.][6341].
Copy link
Contributor

Choose a reason for hiding this comment

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

double -

Comment on lines 65 to 66
/// Execution environment of the context.
pub execution_environment: Rc<Cell<ExecutionEnvironment>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to be in Rc? This model does not implement CloneRef, and other fields are just RefCells without being wrapped in Rc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

@@ -174,12 +181,12 @@ impl display::Object for Model {


// =============================
// === ExecutionModeDropdown ===
// === ExecutionEnvironmentDropdown ===
Copy link
Contributor

Choose a reason for hiding this comment

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

Adjust //================= length above and below.

Comment on lines 266 to +267
eval selected_entry ([model] (execution_mode) {
// TODO(#5930): Revisit when connecting with externally set execution mode
let play_button_visibility = match execution_mode.as_str() {
"design" => true,
"live" => false,
_ => {
error!("Play button: invalid execution mode");
false
}
};
let play_button_visibility = matches!(execution_mode.to_lowercase().as_str(), "design");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why TODO was removed? The logic hasn't changed, has it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is implementing the referenced issue (5930) and it appears there is nothing else to do, so no point in keeping the reference to a son to be closed task. This probably should be revisited when we get the custom modes that Wojciech mentioned din one of his other comments.

I guess if we really want to be prepared for it, we could already an API that allows us to set which execution environments should show the play button, but for the current spec that is not needed.

profiling_button: component::profiling::Button,
styles_frp: StyleWatchFrp,
selection_controller: selection::Controller,
execution_environment_selector: execution_environment_selector::ExecutionEnvironmentSelector,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would import ExecutionEnvironmentSelector, as the module name is just repeated information.

…_execution_environment_between_design_and_live_on_shortcut

# Conflicts:
#	app/gui/src/presenter/project.rs
#	app/gui/view/graph-editor/src/lib.rs
Copy link
Contributor

@vitvakatu vitvakatu left a comment

Choose a reason for hiding this comment

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

QA Review: 🔴

  1. Read-only mode is broken. See the comment below.
  2. Changing the execution environment doesn't update the icons on nodes. It might be solved later in Finish execution contexts integration in IDE #6353, so not blocking the merge. I will try to find the needed code change for that later.
  3. (minor side issue) The dropdown is shifted to the side, I believe it should be displayed more to the left, probably align with the green box. I will create a separate issue for that.

Screenshot 2023-04-24 at 16 45 28

  1. At the project's opening, we send a setExecutionEnvironment message (sometimes even two of them). They fail, probably because the engine is not yet ready. I think we shouldn't send them, the engine assumes the project is in a design environment by default.

Screenshot 2023-04-24 at 16 08 05

// 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>>),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
set_available_execution_environments (Rc<Vec<execution_environment_selector::ExecutionEnvironment>>),
set_available_execution_environments (Rc<Vec<ExecutionEnvironment>>),

// === Profiling Mode ===
(Press, "", "cmd p", "toggle_profiling_mode"),
// === Execution Mode ===
(Press, "", "shift ctrl e", "toggle_execution_environment"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this new shortcut to the documentation (shortcuts.md)

(as a debug shortcut)

@@ -385,22 +404,26 @@ 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((mode) model.execution_environment_changed(mode));

eval_ view.toggle_read_only(model.toggle_read_only());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this line is needed? We already have

view.set_read_only <+ view.toggle_read_only.map(f_!(model.toggle_read_only()));

slightly above. I see that read-only mode is broken in a weird way (after toggling it twice removing nodes works, but dragging edges doesn't)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a merge error and the line is removed now.

@vitvakatu vitvakatu added the CI: Ready to merge This PR is eligible for automatic merge label Apr 25, 2023
@vitvakatu
Copy link
Contributor

QA Report 🟢

We are merging it since we need this functionality as soon as possible. However, a few issues must be addressed in the next PR. @MichaelMauderer

  1. I still see the Request timeout error message when opening the project. Probably, we send the request when initializing the FRP of the dropdown. If it is not easy to fix, please create a separate task.
  2. Context switch buttons on nodes need to be updated. I fixed it here: c87ab85. The relevant line is here: c87ab85#diff-55dbc90f2ab0a6203fb1c2a1d80abf6ff798b92b7ec80a9c27a8c8cc7cf0c912R1733. While doing so, I noticed a few things:
    a. set_execution_context input of the graph editor is not used anywhere except for one place. We can probably remove it.
    b. I understand the idea, but the fact that the current dropdown API operates ImString instead of an enum makes implementation harder and requires parsing. See c87ab85#diff-48811d492864133eabe64a151ba79a4d0ebf0e8b8314dfa12d00bc5e94d1b181R51 and how the implementation got simpler in presenter/project.rs
    c. We probably don't need the toggle_execution_environment shortcut anymore. Now we can always use the dropdown itself. Removing it will simplify implementation in some places.
  3. There are three places marked with TODO(#5930) in the code. It must be addressed.

@mergify mergify bot merged commit 0d84a60 into develop Apr 25, 2023
@mergify mergify bot deleted the wip/MichaelMauderer/Ability_to_change_the_execution_environment_between_design_and_live_on_shortcut branch April 25, 2023 20:28
Akirathan pushed a commit that referenced this pull request Apr 26, 2023
…6341)

Integrate the UI for electing the Execution Environment with the Language Server and unify existing uses. Implements  #5930 + actual integration instead of just mocking it.

https://user-images.githubusercontent.com/1428930/232919438-6e1e295a-34fe-4756-86a4-5f5d8f718fa0.mp4

# Important Notes
The console output is only emitted as part of the `INFO` level. A better check would be to look at the messages sent to the backend in the developer console.
Procrat added a commit that referenced this pull request Apr 27, 2023
* develop:
  Passing events to sub-widgets in List Editor and refactoring of the slider component. (#6433)
  Revert "Cloud/desktop mode switcher (#6308)" (#6444)
  Widgets integrated with graph nodes (#6347)
  Table Visualization and display text changes. (#6382)
  Skip redundant compilations (#6436)
  Add parse extensions to Text type. #6330 (#6404)
  Cloud/desktop mode switcher (#6308)
  Replace Table should_equal with should_equal_verbose (#6405)
  Rollback event handling changes for the mouse (#6396)
  Dashboard directory interactivity (#6279)
  Ability to change the execution environment between design and live. (#6341)
  Implementation of elements adding to List Editor and a lot of internal API (#6390)
  Drop method exported from WASM + removing leaks. (#6365)
  Turn null into UnexpectedExpression when Union type is incomplete (#6415)
mergify bot pushed a commit that referenced this pull request Apr 27, 2023
Follow up to  #6341 (comment) . Contains some refactoring and solves some left over to-dos in the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants