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

Create new node when opening searcher and no node is selected. #3645

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Aug 12, 2022

Pull Request Description

So far, when opening the searcher with no node selected, an empty input without an associated AST node was created. This input was manipulated by the user and the final expression from the input was used to create a new node when the user confirmed their input. This PR changes this, so that when the searcher is opened without a selected node, a new AST node is created right away with some placeholder content, and this node is updated when the user confirms their input.

The only change visible to the user, is that if the text editor is opened during editing, a new node will appear in the source when the searcher is opened to create a new node. All other behaviour should stay the same.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

@MichaelMauderer MichaelMauderer marked this pull request as ready for review August 18, 2022 08:32
@@ -416,6 +416,7 @@ pub mod tests {
// Setup the controller.
let mut fixture = crate::test::mock::Unified::new().fixture();
let Fixture { executed_graph, execution, executor, .. } = &mut fixture;
executor.run_until_stalled();
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is required at this point, shan't it be called always when constructing the fixture?

Comment on lines 396 to 401
fn with_new_node(
parameters: SearcherParams,
graph: &presenter::Graph,
graph_editor: &GraphEditor,
graph_controller: &controller::Graph,
) -> FallibleResult<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a bit of responsibilities mixing. So far, controllers does not know anything about views - it was the presenter who know both, set up and call them directly. There was an idea to make controllers, and presenter separate crates (view is already one).

let mut new_node = NewNodeInfo::new_pushed_back(DEFAULT_INPUT_EXPRESSION);
new_node.metadata = Some(metadata);
new_node.introduce_pattern = false;
let created_node = graph_controller.add_node(new_node)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think creating new node should not be a part of "Mode" constructor, as "Mode" is rather a description according to docs. A data structure, not an object in terms of OOP.

Comment on lines 894 to 899
let mut graph_info = GraphInfo::from_definition(graph_definition.item);
graph_info.add_node(&node, LocationHint::End)?;
module.ast = module.ast.set_traversing(&graph_definition.crumbs, graph_info.ast())?;
let position =
self.graph.graph().node(self.mode.node_id())?.metadata.and_then(|md| md.position);
let metadata = NodeMetadata { position, ..default() };
Copy link
Contributor

Choose a reason for hiding this comment

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

When adding an example, we still create a new node. Are we sure the old one is removed? Maybe we can just update the existing node expression instead of adding a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default, the newly created node is cleared unless, we prevent that by calling prevent_revert on the edit guard.
The only case that could result in a weird state is, if we edit a node and choose an example. Then the original node would be reverted to pre-edit and the example is inserted. But I think examples are only available for empty prompts and are not meant to be used with other nodes (at the moment).

Comment on lines 957 to 968
fn init_input(&self) {
if let Mode::NewNode { source_node, .. } = self.mode.deref() {
if source_node.is_none() {
if let Err(e) = self.set_input("".to_string()) {
tracing::error!(
"Failed to clear input when creating searcher for a new node: {:?}",
e
);
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? Does the view make some input update before being cleared? IMO, whatever reason, it should be handled rather by presenter (to not propagate view input to searcher or AST changes to view).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The input would otherwise be set to whatever is sued as the default value of a new node. I added a comment and moved this to the presenter.

@MichaelMauderer MichaelMauderer added the CI: Ready to merge This PR is eligible for automatic merge label Aug 22, 2022
…Source_when_opening_Seacher_for_a_new_Node_#182633544
@farmaazon farmaazon removed the CI: Ready to merge This PR is eligible for automatic merge label Aug 22, 2022
@MichaelMauderer MichaelMauderer added the CI: Ready to merge This PR is eligible for automatic merge label Aug 22, 2022
@mergify mergify bot merged commit 58fb383 into develop Aug 22, 2022
@mergify mergify bot deleted the wip/michaelmauderer/Create_a_New_Node_in_Source_when_opening_Seacher_for_a_new_Node_#182633544 branch August 22, 2022 15:32
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.

2 participants