Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Add Enso_Project.data entry to the searcher #1393

Merged
merged 5 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
example, having selected node with Table output and adding a new node with
expression `at "x" == "y"` the selected node was applied to the right side of
`==`: `at "x" == operator1."y"` instead of `operator1.at "x" == "y"`.
- [`Enso_Project.data` is visible in searcher][1393].

#### EnsoGL (rendering engine)

Expand All @@ -94,6 +95,7 @@ you can find their release notes
[1348]: https://github.com/enso-org/ide/pull/1348
[1353]: https://github.com/enso-org/ide/pull/1353
[1385]: https://github.com/enso-org/ide/pull/1385
[1393]: https://github.com/enso-org/ide/pull/1393

<br/>

Expand Down
40 changes: 34 additions & 6 deletions src/rust/ide/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use crate::prelude::*;

use crate::controller::graph::FailedToCreateNode;
use crate::controller::graph::NewNodeInfo;

use crate::double_representation::graph::GraphInfo;
use crate::double_representation::graph::LocationHint;
use crate::double_representation::module::QualifiedName;
use crate::double_representation::node::NodeInfo;
use crate::double_representation::tp;
use crate::model::module::MethodId;
use crate::model::module::NodeMetadata;
use crate::model::module::Position;
Expand All @@ -33,6 +35,9 @@ pub use action::Action;
/// See: https://github.com/enso-org/ide/issues/1067
pub const ASSIGN_NAMES_FOR_NODES:bool = true;

/// The special module used for mock `Enso_Project.data` entry.
/// See also [`Searcher::add_enso_project_data_entry`].
const ENSO_PROJECT_SPECIAL_MODULE:&str = "Standard.Base.Enso_Project";


// ==============
Expand Down Expand Up @@ -734,12 +739,15 @@ impl Searcher {


fn add_required_imports(&self) -> FallibleResult {
let data_borrowed = self.data.borrow();
let fragments = data_borrowed.fragments_added_by_picking.iter();
let imports = fragments.map(|frag| self.code_to_insert(frag).imports).flatten();
let mut module = self.module();
let here = self.module_qualified_name();
for mut import in imports {
let data_borrowed = self.data.borrow();
let fragments = data_borrowed.fragments_added_by_picking.iter();
let imports = fragments.map(|frag| self.code_to_insert(frag).imports).flatten();
let mut module = self.module();
let here = self.module_qualified_name();
// TODO[ao] this is a temporary workaround. See [`Searcher::add_enso_project_data_entry`]
// documentation.
let without_enso_project = imports.filter(|i| i.to_string() != ENSO_PROJECT_SPECIAL_MODULE);
for mut import in without_enso_project {
import.remove_main_module_segment();
module.add_module_import(&here, &self.parser, &import);
}
Expand Down Expand Up @@ -836,6 +844,7 @@ impl Searcher {
let actions = action::List::new();
if matches!(self.mode.deref(), Mode::NewNode{..}) && self.this_arg.is_none() {
actions.extend(self.database.iterate_examples().map(Action::Example));
Self::add_enso_project_data_entry(&actions)?;
}
for response in completion_responses {
let response = response?;
Expand Down Expand Up @@ -930,6 +939,25 @@ impl Searcher {
pub fn current_user_action(&self) -> UserAction {
self.data.borrow().input.user_action()
}

/// Add to the action list the special mocked entry of `Enso_Project.data`.
///
/// This is a workaround for Engine bug https://github.com/enso-org/enso/issues/1605.
//TODO[ao] this is a temporary workaround.
fn add_enso_project_data_entry(actions:&action::List) -> FallibleResult {
let entry = model::suggestion_database::Entry {
name : "data".to_owned(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding same for root method.

kind : model::suggestion_database::entry::Kind::Method,
module : QualifiedName::from_text(ENSO_PROJECT_SPECIAL_MODULE)?,
arguments : vec![],
return_type : "Standard.Base.System.File.File".to_owned(),
documentation : None,
self_type : Some(tp::QualifiedName::from_text(ENSO_PROJECT_SPECIAL_MODULE)?),
scope : model::suggestion_database::entry::Scope::Everywhere,
};
actions.extend(std::iter::once(Action::Suggestion(Rc::new(entry))));
Ok(())
}
}

/// A simple function call is an AST where function is a single identifier with optional
Expand Down
2 changes: 1 addition & 1 deletion src/rust/ide/src/controller/searcher/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Action {
} else {
completion.name.clone()
}
Self::Example(example) => format!("Example: {}", example.name)
Self::Example(example) => format!("Example: {}", example.name),
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

}
}
}
Expand Down