-
Notifications
You must be signed in to change notification settings - Fork 323
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
Show Visualisation Preview when Selecting Item on Searcher #3691
Changes from 6 commits
b09c6ae
c200c14
0853b27
33bd774
3afd1ca
4a8935e
c85e8ac
2794f3f
0c6151f
6babdff
27651d0
e13d48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ pub const ASSIGN_NAMES_FOR_NODES: bool = true; | |
const ENSO_PROJECT_SPECIAL_MODULE: &str = | ||
concatcp!(project::STANDARD_BASE_LIBRARY_PATH, ".Enso_Project"); | ||
|
||
const MINIMUM_PATTERN_OFFSET: usize = 1; | ||
|
||
|
||
// ============== | ||
|
@@ -662,7 +663,10 @@ impl Searcher { | |
} | ||
Some(mut expression) => { | ||
let new_argument = ast::prefix::Argument { | ||
sast: ast::Shifted::new(pattern_offset.max(1), added_ast), | ||
sast: ast::Shifted::new( | ||
pattern_offset.max(MINIMUM_PATTERN_OFFSET), | ||
added_ast, | ||
Comment on lines
+684
to
+686
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export to var to make it shorter. |
||
), | ||
prefix_id: default(), | ||
}; | ||
expression.args.push(new_argument); | ||
|
@@ -696,15 +700,71 @@ impl Searcher { | |
} | ||
|
||
/// Preview the suggestion in the searcher. | ||
pub fn preview_entry_as_suggestion(&self, index: usize) { | ||
pub fn preview_entry_as_suggestion(&self, index: usize) -> FallibleResult { | ||
tracing::debug!("Previewing entry: {:?}", index); | ||
//TODO[MM] the actual functionality here will be implemented as part of task #182634050. | ||
let error = || NoSuchAction { index }; | ||
let suggestion = { | ||
let data = self.data.borrow(); | ||
let list = data.actions.list().ok_or_else(error)?; | ||
list.get_cloned(index).ok_or_else(error)?.action | ||
}; | ||
if let Action::Suggestion(picked_suggestion) = suggestion { | ||
self.preview_suggestion(picked_suggestion)?; | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Use action at given index as a suggestion. The exact outcome depends on the action's type. | ||
pub fn preview_suggestion(&self, selected_suggestion: action::Suggestion) { | ||
//TODO[MM] the actual functionality here will be implemented as part of task #182634050. | ||
tracing::debug!("Previewing suggestion: {:?}", selected_suggestion); | ||
pub fn preview_suggestion(&self, picked_suggestion: action::Suggestion) -> FallibleResult { | ||
tracing::debug!("Previewing suggestion: {:?}", picked_suggestion); | ||
|
||
let id = self.data.borrow().input.next_completion_id(); | ||
let picked_completion = FragmentAddedByPickingSuggestion { id, picked_suggestion }; | ||
let code_to_insert = self.code_to_insert(&picked_completion).code; | ||
tracing::debug!("Code to insert: \"{}\"", code_to_insert); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
let added_ast = self.ide.parser().parse_line_ast(&code_to_insert)?; | ||
let pattern_offset = self.data.borrow().input.pattern_offset; | ||
let new_expression = match self.data.borrow_mut().input.expression.clone() { | ||
None => { | ||
let ast = ast::prefix::Chain::from_ast_non_strict(&added_ast); | ||
ast::Shifted::new(pattern_offset, ast) | ||
} | ||
Some(mut expression) => { | ||
let new_argument = ast::prefix::Argument { | ||
sast: ast::Shifted::new( | ||
pattern_offset.max(MINIMUM_PATTERN_OFFSET), | ||
added_ast, | ||
), | ||
prefix_id: default(), | ||
}; | ||
expression.args.push(new_argument); | ||
expression | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like duplicated code, doesn't it? Perhaps there should be a function returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored. |
||
let expr_and_method = || { | ||
let input_chain = Some(new_expression); | ||
|
||
let expression = match (self.this_var(), input_chain) { | ||
(Some(this_var), Some(input)) => | ||
apply_this_argument(this_var, &input.wrapped.into_ast()).repr(), | ||
(None, Some(input)) => input.wrapped.into_ast().repr(), | ||
(_, None) => "".to_owned(), | ||
}; | ||
let intended_method = self.intended_method(); | ||
(expression, intended_method) | ||
}; | ||
let (expression, intended_method) = expr_and_method(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing it in lambda? I don't even see need for block... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was taken from the original code in |
||
|
||
self.graph.graph().module.with_node_metadata( | ||
self.mode.node_id(), | ||
Box::new(|md| md.intended_method = intended_method), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure: is this restored after editing aborting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it is. |
||
)?; | ||
tracing::debug!("Previewing expression: {:?}", expression); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
self.graph.graph().set_expression(self.mode.node_id(), expression)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Execute given action. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,6 +444,12 @@ impl<'a> ControllerChange<'a> { | |
}; | ||
let mut nodes = self.nodes.borrow_mut(); | ||
let displayed = nodes.get_mut_or_create(ast_id); | ||
tracing::debug!( | ||
"Setting node expression from controller: {} -> {}", | ||
displayed.expression, | ||
new_displayed_expr | ||
Comment on lines
+447
to
+450
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export msg to var to make it shorter. |
||
); | ||
|
||
if displayed.expression != new_displayed_expr { | ||
displayed.expression = new_displayed_expr.clone(); | ||
let new_expressions = | ||
|
@@ -650,6 +656,21 @@ impl<'a> ViewChange<'a> { | |
None | ||
} | ||
} | ||
|
||
/// Set the node expression. | ||
pub fn set_node_expression(&self, id: ViewNodeId, expression: String) -> Option<AstNodeId> { | ||
let mut nodes = self.nodes.borrow_mut(); | ||
let ast_id = nodes.ast_id_of_view(id)?; | ||
let displayed = nodes.get_mut(ast_id)?; | ||
let expression = node_view::Expression::new_plain(expression); | ||
tracing::debug!( | ||
"Setting node expression from view: {} -> {}", | ||
displayed.expression, | ||
expression | ||
Comment on lines
+666
to
+669
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export msg to var to make it shorter |
||
); | ||
Comment on lines
+666
to
+670
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can make it 2 lines instead of 5 lines by extracting &str to var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me, extracting the message makes the debug statement much less readable.
The extra variable does not add any useful contextual information, but now when scanning the debug statement, one has to trace back to the variable to read its content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it has the same performance: the format macro can adjust allocated space when knows the string on compilation time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it has the same performance - this is let debug_message = "Setting node expression from view:";
tracing::debug!("{debug_message} {} -> {}", displayed.expression, expression); It's sharter to look at and I think we should optimize the code lengh, otherwise it's hard to read. If we can change it, I'd be thankful. |
||
let expression_has_changed = displayed.expression != expression; | ||
expression_has_changed.as_some(ast_id) | ||
} | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,9 @@ impl Model { | |
/// Should be called if an entry is selected but not used yet. Only used for the old searcher | ||
/// API. | ||
fn entry_selected_as_suggestion(&self, entry_id: view::searcher::entry::Id) { | ||
self.controller.preview_entry_as_suggestion(entry_id); | ||
if let Err(error) = self.controller.preview_entry_as_suggestion(entry_id) { | ||
tracing::warn!("Failed to preview entry {entry_id:?} because of error: {error:?}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
fn commit_editing(&self, entry_id: Option<view::searcher::entry::Id>) -> Option<AstNodeId> { | ||
|
@@ -151,7 +153,9 @@ impl Model { | |
/// Should be called if a suggestion is selected but not used yet. | ||
fn suggestion_selected(&self, entry_id: list_panel::EntryId) { | ||
let suggestion = self.suggestion_for_entry_id(entry_id).unwrap(); | ||
self.controller.preview_suggestion(suggestion); | ||
if let Err(error) = self.controller.preview_suggestion(suggestion) { | ||
tracing::warn!("Failed to preview suggestion {entry_id:?} because of error: {error:?}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it end with. dot? |
||
} | ||
} | ||
|
||
fn suggestion_accepted( | ||
|
@@ -404,7 +408,6 @@ impl Searcher { | |
let created_node = graph_controller.add_node(new_node)?; | ||
|
||
graph.assign_node_view_explicitly(input, created_node); | ||
graph.allow_expression_auto_updates(created_node, false); | ||
|
||
let source_node = source_node.and_then(|id| graph.ast_node_of_view(id.node)); | ||
|
||
|
@@ -425,14 +428,19 @@ impl Searcher { | |
let SearcherParams { input, .. } = parameters; | ||
let ast_node = graph.ast_node_of_view(input); | ||
|
||
match ast_node { | ||
let mode = match ast_node { | ||
Some(node_id) => Ok(Mode::EditNode { node_id }), | ||
None => { | ||
let (new_node, source_node) = | ||
Self::create_input_node(parameters, graph, graph_editor, graph_controller)?; | ||
Ok(Mode::NewNode { node_id: new_node, source_node }) | ||
} | ||
}; | ||
let target_node = mode.as_ref().map(|mode| mode.node_id()); | ||
if let Ok(target_node) = target_node { | ||
graph.allow_expression_auto_updates(target_node, false); | ||
} | ||
mode | ||
} | ||
|
||
/// Setup new, appropriate searcher controller for the edition of `node_view`, and construct | ||
|
@@ -509,6 +517,11 @@ impl Searcher { | |
/// editing finishes. | ||
pub fn abort_editing(self) {} | ||
|
||
/// Returns the node view that is being edited by the searcher. | ||
pub fn input_view(&self) -> ViewNodeId { | ||
self.model.input_view | ||
} | ||
|
||
/// Returns true if the entry under given index is one of the examples. | ||
pub fn is_entry_an_example(&self, entry: view::searcher::entry::Id) -> bool { | ||
use crate::controller::searcher::action::Action::Example; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No docs, and the name does not explain what it is.