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

Correct import handling when selecting items from the component browser #182634001 #3708

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Sep 14, 2022

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:

  • 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 self-assigned this Sep 14, 2022
@MichaelMauderer MichaelMauderer force-pushed the wip/michaelmauderer/Implement_Correct_Import_Handling_when_selecting_Items_from_the_Component_Browser_#182634001 branch from 87209e3 to 6a7c977 Compare September 17, 2022 12:51
@MichaelMauderer MichaelMauderer force-pushed the wip/michaelmauderer/Implement_Correct_Import_Handling_when_selecting_Items_from_the_Component_Browser_#182634001 branch from 6a7c977 to ccedc51 Compare September 17, 2022 14:18
@MichaelMauderer MichaelMauderer marked this pull request as ready for review September 17, 2022 22:25
@MichaelMauderer MichaelMauderer marked this pull request as draft September 17, 2022 22:27
@MichaelMauderer MichaelMauderer marked this pull request as ready for review September 20, 2022 09:02
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
Copy link
Contributor

@farmaazon farmaazon left a 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
Comment on lines 66 to 71
- [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]
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated entry.

Comment on lines 1032 to 1041
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());
}
}
}
Copy link
Contributor

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.

Comment on lines 1046 to 1052
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:?}"
);
}
});
Copy link
Contributor

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.

@@ -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.
Copy link
Contributor

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.

Comment on lines 534 to 536
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, deserialize_with = "enso_prelude::deserialize_or_default")]
pub info: Option<ImportInfo>,
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 keep ImportInfo in metadata? The only field of ImportInfo should be deducible from the AST.

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 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


Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Removed.

Comment on lines 1029 to 1044
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();
Copy link
Contributor

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.

Comment on lines 1040 to 1042
return Some(id);
}
}
}
None
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 do not return, it isn't even obvious what we're actually returning.

@MichaelMauderer MichaelMauderer added the CI: Ready to merge This PR is eligible for automatic merge label Sep 22, 2022
mergify bot and others added 4 commits September 22, 2022 20:56
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
…ort_Handling_when_selecting_Items_from_the_Component_Browser_#182634001
@mergify mergify bot merged commit ff3c481 into develop Sep 23, 2022
@mergify mergify bot deleted the wip/michaelmauderer/Implement_Correct_Import_Handling_when_selecting_Items_from_the_Component_Browser_#182634001 branch September 23, 2022 14:30
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