-
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
Correct import handling when selecting items from the component browser #182634001 #3708
Conversation
87209e3
to
6a7c977
Compare
6a7c977
to
ccedc51
Compare
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
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.
First, I would not keep a duplicated info in the source file.
CHANGELOG.md
Outdated
- [Selecting a suggestion from the searcher or component browser now updates the | ||
visualisation of the edited node to preview the results of applying the | ||
suggestion.][3691] | ||
- [Selecting a suggestion from the searcher or component browser now updates the | ||
visualisation of the edited node to preview the results of applying the | ||
suggestion.][3691] |
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 entry.
app/gui/src/controller/searcher.rs
Outdated
for import_metadata in self.graph.graph().module.all_import_metadata() { | ||
if import_metadata.is_temporary { | ||
if let Some(import_info) = &import_metadata.info { | ||
if let Err(e) = module.remove_import(import_info) { | ||
tracing::warn!("Failed to remove import because of: {e:?}"); | ||
} | ||
to_remove.push(import_info.id()); | ||
} | ||
} | ||
} |
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.
Instead of mutable to_remove
field, we could take an "iterators" approach: let to_remove = self.graph.graph().module.all_import_metadata().into_iter().filter_map(|...|)
. This way, it is clear where to_remove is created and where is it used.
app/gui/src/controller/searcher.rs
Outdated
to_remove.iter().for_each(|id| { | ||
if let Err(e) = self.graph.graph().module.remove_import_metadata(*id) { | ||
tracing::warn!( | ||
"Failed to remove import metadata for import id {id} because of: {e:?}" | ||
); | ||
} | ||
}); |
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.
Here in turn, I would use for
syntax, which is essentially the same as foreach
except you avoid making closures.
app/gui/src/model/module.rs
Outdated
@@ -39,6 +41,11 @@ pub use double_representation::tp::QualifiedName as TypeQualifiedName; | |||
#[derive(Debug, Clone, Copy, Fail)] | |||
#[fail(display = "Node with ID {} was not found in metadata.", _0)] | |||
pub struct NodeMetadataNotFound(pub ast::Id); | |||
/// Failure for missing node metadata. |
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 docs. Additionally, in other places we do not add docs for error structures, as the message in fail
should be descriptive enough.
app/gui/src/model/module.rs
Outdated
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[serde(default, deserialize_with = "enso_prelude::deserialize_or_default")] | ||
pub info: Option<ImportInfo>, |
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 do we keep ImportInfo in metadata? The only field of ImportInfo should be deducible from the 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.
This made it easier to use the existing API for removing imports, which require ImportInfo
. It also makes debugging the metadata slightly nicer, as it adds the text of the import to the metadata. But it is a bit of overhead, so I’ve removed it in favour of a new API to remove imports by ID.
@@ -2,6 +2,7 @@ | |||
|
|||
wasm-size-limit: 14.60 MiB | |||
|
|||
|
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.
Is this an intentional change?
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. Removed.
app/gui/src/controller/searcher.rs
Outdated
let to_remove = self | ||
.graph | ||
.graph() | ||
.module | ||
.all_import_metadata() | ||
.into_iter() | ||
.filter_map(|(id, import_metadata)| { | ||
if import_metadata.is_temporary { | ||
if let Err(e) = module.remove_import_by_id(id) { | ||
tracing::warn!("Failed to remove import because of: {e:?}"); | ||
} | ||
to_remove.push(import_info.id()); | ||
return Some(id); | ||
} | ||
} | ||
} | ||
None | ||
}) | ||
.collect_vec(); |
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.
Please split it into several lets to avoid "vertical noise". For example, self.graph.graph().module
could be in a single line.
app/gui/src/controller/searcher.rs
Outdated
return Some(id); | ||
} | ||
} | ||
} | ||
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.
Let's do not return, it isn't even obvious what we're actually returning.
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
Pull Request Description
Implements Task #182634001
Handles adding and removing of imports for the visualization preview of suggestions.
Peek.2022-09-18.23-10.mp4
Important Notes
[ci no changelog needed]
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.