-
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
Conversation
2b7e26e
to
c200c14
Compare
Michael, this is amazing. One thing that is to be fixed is that sometimes the result needs to be computed for a longer time. Until its computed, a spinner sohuld be shown. Any spinner - could be any shape animated in GLSL. BTW, if you'll be animating in GLSL (like our. text cursor, the animation will stop when you stop moving mouse - this is a bug I'll fix in my PR). |
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.
Added comment above.
@wdanilo Should we plan this as a separate task, though? While I agree that this would be a super useful feature, it seems somewhat unrelated to this task, from a planning standpoint. If anything, I would add this feature as part of the "always show the visualization" task, as that actually touches visualization code. |
app/gui/src/controller/searcher.rs
Outdated
} | ||
Some(mut expression) => { | ||
let new_argument = ast::prefix::Argument { | ||
sast: ast::Shifted::new(pattern_offset.max(1), added_ast), |
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.
magic 1
app/gui/src/presenter/graph/state.rs
Outdated
if displayed.expression != expression { | ||
displayed.expression = expression; | ||
Some(ast_id) | ||
} else { | ||
None |
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.
use .as_some
on bool
instead in such cases.
tracing::debug!( | ||
"Setting node expression from view: {} -> {}", | ||
displayed.expression, | ||
expression | ||
); |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
For me, extracting the message makes the debug statement much less readable.
let debug_message = "Setting node expression from view: {} -> {}";
tracing::debug!(debug_message, displayed.expression, expression);
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.
Before, one could just read the debug statement linearly top to bottom.
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.
you can make it 2 lines instead of 5 lines by extracting &str to var
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it has the same performance - this is &'static str
, it is not allocated, it is build-into the binary, it sohuld be:
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.
app/gui/src/presenter/project.rs
Outdated
@@ -129,6 +129,8 @@ impl Model { | |||
fn editing_aborted(&self) { | |||
let searcher = self.searcher.take(); | |||
if let Some(searcher) = searcher { | |||
let node = self.graph.ast_node_of_view(searcher.input_view()).unwrap(); |
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.
unwrap left in the code
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.
You should be awarded with "creator of the branch with the longest name" badge.
app/gui/src/controller/searcher.rs
Outdated
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 comment
The 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 new_expression
.
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.
Refactored.
app/gui/src/controller/searcher.rs
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This was taken from the original code in commit_node
. But after doing the refactoring into a separate method, it is gone now.
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Now it is.
tracing::debug!( | ||
"Setting node expression from view: {} -> {}", | ||
displayed.expression, | ||
expression | ||
); |
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.
you can make it 2 lines instead of 5 lines by extracting &str to var
I'm not sure if it has the same performance: the format macro can adjust allocated space when knows the string on compilation time.
app/gui/src/controller/searcher.rs
Outdated
let input_chain = self.data.borrow().input.as_prefix_chain(self.ide.parser()); | ||
// We add the required imports before we edit its content. This way, we avoid an | ||
// intermediate state where imports would already be in use but not yet available. | ||
self.add_required_imports()?; | ||
let (expression, intended_method) = expr_and_method(); | ||
let expression = self.get_expression(input_chain); | ||
let intended_method = self.intended_method(); | ||
|
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.
These lines are strangely mixed. I think the add_required_imports should go before variables which are not used by it.
app/gui/src/controller/searcher.rs
Outdated
(expression, intended_method) | ||
}; | ||
let (expression, intended_method) = expr_and_method(); | ||
let expression = self.get_expression(new_expression); |
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.
The name is unclear. Why, having new_expression
we must yet get expression from it?
Additionally, I think new_expression
construction is still duplicated.
…rowser_Selections_to_Source_and_Disassociate_the_Node_That_Is_Edited_by_the_Searcher_From_any_Changes_Not_Made_by_the_Searcher_#182634050 # Conflicts: # CHANGELOG.md
@@ -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; |
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.
sast: ast::Shifted::new( | ||
pattern_offset.max(MINIMUM_PATTERN_OFFSET), | ||
added_ast, |
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.
export to var to make it shorter.
app/gui/src/controller/searcher.rs
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
missing .
at the end.
app/gui/src/controller/searcher.rs
Outdated
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); | ||
Some(expression) |
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.
duplicated code - I've seen it above.
app/gui/src/controller/searcher.rs
Outdated
self.mode.node_id(), | ||
Box::new(|md| md.intended_method = intended_method), | ||
)?; | ||
tracing::debug!("Previewing expression: {:?}", expression); |
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.
- Earlier, the code was enclosed in
"
, here it is not. - Missing dot.
tracing::debug!( | ||
"Setting node expression from controller: {} -> {}", | ||
displayed.expression, | ||
new_displayed_expr |
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.
export msg to var to make it shorter.
tracing::debug!( | ||
"Setting node expression from view: {} -> {}", | ||
displayed.expression, | ||
expression |
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.
export msg to var to make it shorter
app/gui/src/presenter/searcher.rs
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
- double space
- Does it end with dot?
app/gui/src/presenter/searcher.rs
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
does it end with. dot?
…rowser_Selections_to_Source_and_Disassociate_the_Node_That_Is_Edited_by_the_Searcher_From_any_Changes_Not_Made_by_the_Searcher_#182634050
Pull Request Description
Implements #182634050.
Enables visualization previews for selections in the searcher.
Works for the old Searcher and the new Component Browser, but it was easier to show the examples for the old searcher, as the suggestions seem to be better/faster available currently (this will improve with the new implementation using better strings and the new GridView).
Peek.2022-09-07.12-59.mp4
Aborting an edit now also correctly reverts a node.
Peek.2022-09-07.13-00.mp4
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.