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

Virtual Entries in Component Browser #3621

Merged
merged 144 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 140 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
ecaef8d
WIP start adding component::Kind enum
akavel Jul 27, 2022
f3cf705
WIP
akavel Jul 27, 2022
b7cfc59
WIP extend_...
akavel Jul 27, 2022
239fa38
WIP constr. & retain
akavel Jul 27, 2022
f7a53c5
WIP can_be_entered & Display
akavel Jul 27, 2022
3868756
WIP provider
akavel Jul 27, 2022
b5a565d
WIP searcher
akavel Jul 27, 2022
ed5de9f
WIP derive
akavel Jul 27, 2022
fd6d9ea
add some missing borrows
akavel Jul 27, 2022
fa94e59
draft vgroup
akavel Jul 27, 2022
f78979e
Display
akavel Jul 27, 2022
f087d8d
number input
akavel Jul 27, 2022
2fd6f6e
cargo fmt
akavel Jul 28, 2022
4a05df1
WIP ComponentGroup.library
akavel Jul 28, 2022
feae78e
filter_map in ec::synchronized
akavel Jul 28, 2022
e56ded7
WIP thread_local in searcher
akavel Jul 28, 2022
7d78753
WIP find group by fully qual. name
akavel Jul 28, 2022
6051072
WIP add library in comp::Group
akavel Jul 28, 2022
15383fb
fix to compile
akavel Jul 28, 2022
d13dcbe
add a fixme to refactor
akavel Jul 28, 2022
9b928fa
DEBUG libs+names in insert_...
akavel Jul 28, 2022
f93ca4d
move insert_... to initialization of builder
akavel Jul 28, 2022
670d99f
insert_entries
akavel Jul 28, 2022
ccf61f3
WIP if !inserted ...
akavel Jul 28, 2022
903490f
WIP
akavel Aug 1, 2022
05425d6
fix to compile
akavel Aug 1, 2022
3674066
CLEANUP one comment
akavel Aug 1, 2022
2504aac
WIP group::QualifiedName
akavel Aug 1, 2022
b65f8ad
fix to compile
akavel Aug 1, 2022
07ff1e1
rename fn
akavel Aug 1, 2022
1d254de
WIP fixing tests
akavel Aug 1, 2022
de90f8c
WIP fixing tests
akavel Aug 1, 2022
6b0dcfc
WIP fixing tests
akavel Aug 1, 2022
a23234b
fix tests to compile\
akavel Aug 1, 2022
c059e58
filter_map -> map(unwrap) in tests
akavel Aug 1, 2022
6699a01
impl From<Rc<Virtual>> for Component
akavel Aug 2, 2022
d452d4e
CLEANUP some fragments
akavel Aug 2, 2022
ecb08b4
take_grouping_and_order... + some tweaks
akavel Aug 2, 2022
ccc4f2d
cargo fmt + tweak
akavel Aug 2, 2022
3d41309
documentation_html pretty
akavel Aug 2, 2022
60cd659
icon::Id::as_str()
akavel Aug 2, 2022
2477947
cleanup some unnecessary trace
akavel Aug 2, 2022
0adc6b5
cargo fmt + tweaks
akavel Aug 2, 2022
f4ce0df
can_be_entered refactor
akavel Aug 2, 2022
1147898
refactor Component::fmt
akavel Aug 2, 2022
42f2523
tweak from_qual_name_and_virt_comps
akavel Aug 2, 2022
ba51d70
refactor log_group_parsing_error
akavel Aug 2, 2022
a3f9fed
WIP starting to write test
akavel Aug 4, 2022
2302445
fix to compile
akavel Aug 4, 2022
591bd2c
WIP Component::name()
akavel Aug 4, 2022
082ee6d
WIP use Component::name() more
akavel Aug 4, 2022
91b8f97
actual test
akavel Aug 4, 2022
ef11376
WIP 2nd test
akavel Aug 4, 2022
5e4ddd7
group_at_1 in test
akavel Aug 4, 2022
9dbc18f
of_standard_base_library()
akavel Aug 4, 2022
844d619
use it more
akavel Aug 4, 2022
4bbf8fc
test that qn_of_std_base does not panic
akavel Aug 4, 2022
7ed7c9e
drop TODO
akavel Aug 4, 2022
16e4647
WIP const_format
akavel Aug 4, 2022
15b483f
VirtCompWithLiteral
akavel Aug 4, 2022
1ede8b0
cargo fmt
akavel Aug 4, 2022
8a331de
fix clippy
akavel Aug 4, 2022
35b1aa8
Merge remote-tracking branch 'origin/develop' into wip/akavel/virtual…
akavel Aug 8, 2022
2ab03df
s//LiteralVirtualComponent
akavel Aug 8, 2022
c8c130b
INPUT_LITERAL_VIRTUAL_COMPONENTS
akavel Aug 8, 2022
58acf49
INPUT_COMPONENT_GROUP_NAME
akavel Aug 8, 2022
771338c
less <div>s in html
akavel Aug 8, 2022
cdd042c
rename html macro
akavel Aug 8, 2022
db91d0d
doc for LiteralVC
akavel Aug 8, 2022
ae5cd0c
rename local vars in comp_list_builder_w_favs
akavel Aug 8, 2022
ee3dc74
doc for component::Virtual
akavel Aug 8, 2022
f28ddf6
tweak compo::Virtual doc
akavel Aug 8, 2022
a77afe3
docs for Kind
akavel Aug 8, 2022
25c12e9
Snippet & .entry
akavel Aug 8, 2022
2940e31
new_from_db
akavel Aug 8, 2022
a81c20b
docs
akavel Aug 8, 2022
a23ceba
avoid multiline expr
akavel Aug 8, 2022
0a66c9d
tweak LiteralSnippet comment
akavel Aug 8, 2022
2705eb0
FromDb -> FromDatabase
akavel Aug 8, 2022
ef29792
contain/s/ing
akavel Aug 8, 2022
efafbbc
new_from_db doc
akavel Aug 8, 2022
1b72380
docs for getters
akavel Aug 8, 2022
fffc060
shorten macro call line
akavel Aug 8, 2022
ec9b075
entry_name in impl Display
akavel Aug 8, 2022
ba1180f
drop unused imports
akavel Aug 8, 2022
01c46fe
 doc and rename for Group::from_qn_and_snippets
akavel Aug 8, 2022
c7d8536
undo one rename
akavel Aug 8, 2022
13ec195
qn_of_base_lib in tests
akavel Aug 8, 2022
a5eb3e2
tweak test names and add docs
akavel Aug 8, 2022
81c9b3f
doc for group::QualifiedName
akavel Aug 8, 2022
a69aa90
tweak doc of from_name_and_project_and_id
akavel Aug 8, 2022
9497cd5
doc for insert_entries
akavel Aug 8, 2022
1d07b5b
parse docs
akavel Aug 8, 2022
61b9be3
cargo fmt
akavel Aug 8, 2022
840c620
fix tests
akavel Aug 8, 2022
26a77a1
add_comp_from_db_to_grps_by_parent_mod
akavel Aug 8, 2022
e78010d
doc for qn()
akavel Aug 8, 2022
471a88f
del empty line
akavel Aug 8, 2022
ab09fa1
tweak error for parsed_icon for VirtualComponent
akavel Aug 8, 2022
7a6e6ad
doc for as_str
akavel Aug 8, 2022
2710109
cargo fmt
akavel Aug 8, 2022
d02cb07
fix clippy
akavel Aug 8, 2022
d103e49
bump wasm size limit
akavel Aug 8, 2022
54afe55
Revert "add_comp_from_db_to_grps_by_parent_mod"
akavel Aug 8, 2022
39287ab
new_from_database_entry
akavel Aug 8, 2022
0046308
fix for wasm test
akavel Aug 9, 2022
3c9a2f4
Merge remote-tracking branch 'origin/develop' into wip/akavel/virtual…
akavel Aug 9, 2022
889ded4
continue fixing wasm test
akavel Aug 9, 2022
37d7b98
review: drop prefix "of_" in func name
akavel Aug 9, 2022
143385c
review: remove dead code
akavel Aug 9, 2022
f9fe2db
revert unnecessary line split
akavel Aug 9, 2022
e7da4b2
review: rename closure argument
akavel Aug 9, 2022
348abd5
review: delete group::QualifiedName struct
akavel Aug 9, 2022
c745948
WIP create mod component::hardcoded and move type alias there
akavel Aug 9, 2022
e383a19
WIP move stuff to mod hardcoded
akavel Aug 9, 2022
6e605e5
Merge remote-tracking branch 'origin/develop' into wip/akavel/virtual…
akavel Aug 10, 2022
4749c6e
run enso-formatter on new files
akavel Aug 10, 2022
c45e851
WIP splitting LiteralSnippets static vector initialization
akavel Aug 10, 2022
71dba14
WIP use Suggestion helpers to build INPUT_SNIPPETS
akavel Aug 10, 2022
9058ced
WIP finish migration & remove unused LiteralSnippet
akavel Aug 10, 2022
eb13f34
WIP snippet helper
akavel Aug 10, 2022
7049e1e
cargo fmt
akavel Aug 10, 2022
e045d84
review: WIP fix other usages of "Base"
akavel Aug 10, 2022
42da186
review: add constants for "Standard" and "Base"
akavel Aug 11, 2022
cea60f3
review: WIP Kind doc
akavel Aug 11, 2022
fa3b2c3
review: rename Kind to Data + update doc
akavel Aug 11, 2022
969cd92
docs for consts
akavel Aug 11, 2022
297a502
first docs tweaks in mod hardcoded
akavel Aug 11, 2022
9152c11
WIP more doc tweaks
akavel Aug 11, 2022
bb7a481
tweak doc of INPUT_SNIPPETS
akavel Aug 11, 2022
d94aece
tweak doc of standard_base_library
akavel Aug 11, 2022
73287eb
STANDARD_BASE_LIBRARY_PATH
akavel Aug 11, 2022
534d600
small tweak: +full
akavel Aug 11, 2022
7fccc48
add docs for suggestion methods
akavel Aug 11, 2022
0608afe
tweak method helpers docs
akavel Aug 11, 2022
a022cc5
mention parser panic
akavel Aug 11, 2022
567bab3
tweak doc of Data
akavel Aug 11, 2022
02e60e5
tweak comment of fn id
akavel Aug 11, 2022
ac52077
tweak doc of from_n_and_p_and_snippets
akavel Aug 11, 2022
ab701f1
bring back some code in test
akavel Aug 11, 2022
ef6fda1
review: doc of Suggestion::new func
akavel Aug 16, 2022
7b78121
review: tweak doc comments
akavel Aug 16, 2022
5126554
review: tweak doc
akavel Aug 16, 2022
4e16081
Merge branch 'develop' into wip/akavel/virtual-entries-in-cb-181870589
mergify[bot] Aug 17, 2022
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ parser = { path = "language/parser" }
span-tree = { path = "language/span-tree" }
bimap = { version = "0.4.0" }
console_error_panic_hook = { version = "0.1.6" }
const_format = { version = "0.2.22" }
convert_case = { version = "0.5.0" }
failure = { version = "0.1.6" }
flo_stream = { version = "0.4.0" }
Expand Down
1 change: 1 addition & 0 deletions app/gui/controller/double-representation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enso-logger = { path = "../../../../lib/rust/logger" }
enso-prelude = { path = "../../../../lib/rust/prelude" }
enso-profiler = { path = "../../../../lib/rust/profiler" }
enso-text = { path = "../../../../lib/rust/text" }
const_format = { version = "0.2.22" }
failure = { version = "0.1.6" }
itertools = { version = "0.10.0" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
27 changes: 27 additions & 0 deletions app/gui/controller/double-representation/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ use crate::prelude::*;

use crate::identifier::ReferentName;

use const_format::concatcp;
use serde::Deserialize;
use serde::Serialize;



// =================
// === Constants ===
// =================

/// The namespace of the standard library.
pub const STANDARD_NAMESPACE: &str = "Standard";

/// The name of the project in the [`STANDARD_NAMESPACE`] containing the base standard library.
pub const BASE_LIBRARY_NAME: &str = "Base";

/// The full path of the [`BASE_LIBRARY_NAME`] project in the [`STANDARD_NAMESPACE`].
pub const STANDARD_BASE_LIBRARY_PATH: &str = concatcp!(STANDARD_NAMESPACE, ".", BASE_LIBRARY_NAME);



// ==============
// === Errors ===
// ==============
Expand Down Expand Up @@ -76,6 +92,12 @@ impl QualifiedName {
}
}

/// Return the fully qualified name of the [`BASE_LIBRARY_NAME`] project in the
/// [`STANDARD_NAMESPACE`].
pub fn standard_base_library() -> Self {
Self::from_segments(STANDARD_NAMESPACE, BASE_LIBRARY_NAME).unwrap()
}

/// The iterator over name's segments: the namespace and project name.
pub fn segments(&self) -> impl Iterator<Item = &str> {
std::iter::once(self.namespace.as_ref()).chain(std::iter::once(self.project.as_ref()))
Expand Down Expand Up @@ -152,4 +174,9 @@ mod test {
invalid_case("namespace.");
invalid_case(".");
}

#[test]
fn qualified_name_of_standard_base_library_does_not_panic() {
let _ = QualifiedName::standard_base_library();
}
}
25 changes: 17 additions & 8 deletions app/gui/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::model::suggestion_database;
use crate::model::suggestion_database::entry::CodeToInsert;
use crate::notification;

use const_format::concatcp;
use double_representation::graph::GraphInfo;
use double_representation::graph::LocationHint;
use double_representation::module::QualifiedName;
Expand Down Expand Up @@ -47,7 +48,9 @@ pub const ASSIGN_NAMES_FOR_NODES: bool = true;

/// The special module used for mock `Enso_Project.data` entry.
/// See also [`Searcher::add_enso_project_entries`].
const ENSO_PROJECT_SPECIAL_MODULE: &str = "Standard.Base.Enso_Project";
const ENSO_PROJECT_SPECIAL_MODULE: &str =
concatcp!(project::STANDARD_BASE_LIBRARY_PATH, ".Enso_Project");



// ==============
Expand Down Expand Up @@ -1188,6 +1191,10 @@ fn component_list_builder_with_favorites<'a>(
builder = builder.with_local_scope_module_id(id);
}
builder.set_grouping_and_order_of_favorites(suggestion_db, groups);
let base_lib_qn = project::QualifiedName::standard_base_library();
let input_group_name = component::hardcoded::INPUT_GROUP_NAME;
let snippets = component::hardcoded::INPUT_SNIPPETS.with(|s| s.clone());
builder.insert_virtual_components_in_favorites_group(input_group_name, base_lib_qn, snippets);
builder
}

Expand Down Expand Up @@ -1786,7 +1793,7 @@ pub mod test {
// Prepare a sample component group to be returned by a mock Language Server client.
let module_qualified_name = crate::test::mock::data::module_qualified_name().to_string();
let sample_ls_component_group = language_server::LibraryComponentGroup {
library: "".to_string(),
library: project::QualifiedName::standard_base_library().to_string(),
name: "Test Group 1".to_string(),
color: None,
icon: None,
Expand Down Expand Up @@ -1819,17 +1826,19 @@ pub mod test {
format!("{}.{}", entry1.module.project_name.project, entry1.module.name());
assert_eq!(module_group.name, expected_group_name);
let entries = module_group.entries.borrow();
assert_matches!(entries.as_slice(), [e1, e2] if e1.suggestion.name == entry1.name && e2.suggestion.name == entry9.name);
assert_matches!(entries.as_slice(), [e1, e2] if e1.name() == entry1.name && e2.name() == entry9.name);
} else {
ipanic!("Wrong top modules in Component List: {components.top_modules():?}");
}
let favorites = &components.favorites;
assert_eq!(favorites.len(), 1);
let favorites_group = &favorites[0];
assert_eq!(favorites_group.name, "Test Group 1");
let favorites_entries = favorites_group.entries.borrow();
assert_eq!(favorites.len(), 2);
let favorites_group_0 = &favorites[0];
assert_eq!(favorites_group_0.name, component::hardcoded::INPUT_GROUP_NAME);
let favorites_group_1 = &favorites[1];
assert_eq!(favorites_group_1.name, "Test Group 1");
let favorites_entries = favorites_group_1.entries.borrow();
assert_eq!(favorites_entries.len(), 1);
assert_eq!(*favorites_entries[0].id, 1);
assert_eq!(favorites_entries[0].id().unwrap(), 1);
}

#[wasm_bindgen_test]
Expand Down
9 changes: 5 additions & 4 deletions app/gui/src/controller/searcher/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ impl Suggestion {

/// Return the documentation assigned to the suggestion.
pub fn documentation_html(&self) -> Option<&str> {
match self {
Suggestion::FromDatabase(s) => s.documentation_html.as_ref().map(AsRef::<str>::as_ref),
Suggestion::Hardcoded(s) => s.documentation_html,
}
let doc_html = match self {
Suggestion::FromDatabase(s) => &s.documentation_html,
Suggestion::Hardcoded(s) => &s.documentation_html,
};
doc_html.as_ref().map(AsRef::<str>::as_ref)
}

/// The Id of the method called by a suggestion, or [`None`] if the suggestion is not a method
Expand Down
22 changes: 19 additions & 3 deletions app/gui/src/controller/searcher/action/hardcoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ pub struct Suggestion {
/// An import required by the suggestion.
pub imports: Vec<module::QualifiedName>,
/// The documentation bound to the suggestion.
pub documentation_html: Option<&'static str>,
pub documentation_html: Option<String>,
/// The id of the method called by the suggestion.
pub method_id: Option<MethodId>,
/// The name of the icon bound to this entry.
pub icon: ImString,
}

impl Suggestion {
fn new(name: &'static str, code: &'static str, icon: &ImString) -> Self {
/// Construct a suggestion with given name, code, and icon.
akavel marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) fn new(name: &'static str, code: &'static str, icon: &ImString) -> Self {
let icon = icon.clone_ref();
Self { name, code, icon, ..default() }
}
Expand All @@ -130,7 +131,10 @@ impl Suggestion {
self
}

fn with_return_type(
/// Returns a modified suggestion with [`Suggestion::return_type`] field set. This method is
/// only intended to be used when defining hardcoded suggestions and panics if the argument
/// fails to convert to a valid type name.
pub(crate) fn with_return_type(
mut self,
return_type: impl TryInto<tp::QualifiedName, Error: Debug>,
) -> Self {
Expand All @@ -146,6 +150,18 @@ impl Suggestion {
self
}

/// Returns a modified suggestion with [`Suggestion::documentation_html`] field set. This
/// method is only intended to be used when defining hardcoded suggestions and panics if a
/// documentation parser cannot be created or the argument fails to parse as valid
/// documentation.
pub(crate) fn with_documentation(mut self, documentation: &str) -> Self {
let doc_parser = parser::DocParser::new().unwrap();
let doc_string = documentation.to_string();
let documentation_html = doc_parser.generate_html_doc_pure(doc_string);
self.documentation_html = Some(documentation_html.unwrap());
self
}

fn marked_as_method_call(
mut self,
name: &'static str,
Expand Down
90 changes: 73 additions & 17 deletions app/gui/src/controller/searcher/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use convert_case::Casing;

pub mod builder;
pub mod group;
pub mod hardcoded;

pub use group::Group;

Expand Down Expand Up @@ -54,6 +55,31 @@ pub enum Order {



// ============
// === Data ===
// ============

/// Contains detailed data of a [`Component`]. The storage of the details differs depending on
/// where the data originates from (either from the [`suggestion_database`] or from a
/// [`hardcoded::Snippet`]).
#[derive(Clone, CloneRef, Debug)]
pub enum Data {
/// A component from the [`suggestion_database`].
FromDatabase {
/// The ID of the component in the [`suggestion_database`].
id: Immutable<Id>,
/// The component's entry in the [`suggestion_database`].
entry: Rc<suggestion_database::Entry>,
},
/// A virtual component containing a hardcoded snippet of code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the more explicit info how the "component from snippet" work: that the snippet has defined return type, and accepting the component shall just put the snippet at the end of searcher input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on our discussion, I did not mention return type, as it is not currently used. I also did not mention "end of searcher input", but instead used similar phrasing as was used in the documentation of Component before.

Virtual {
/// A hardcoded snippet of code.
snippet: Rc<hardcoded::Snippet>,
},
}



// =================
// === Component ===
// =================
Expand All @@ -69,24 +95,40 @@ pub enum Order {
#[allow(missing_docs)]
#[derive(Clone, CloneRef, Debug)]
pub struct Component {
pub id: Immutable<Id>,
pub suggestion: Rc<suggestion_database::Entry>,
pub data: Data,
pub match_info: Rc<RefCell<MatchInfo>>,
}

impl Component {
/// Construct a new component.
/// Construct a new component from a [`suggestion_database`] entry.
///
/// The matching info will be filled for an empty pattern.
pub fn new(id: Id, suggestion: Rc<suggestion_database::Entry>) -> Self {
Self { id: Immutable(id), suggestion, match_info: default() }
pub fn new_from_database_entry(id: Id, entry: Rc<suggestion_database::Entry>) -> Self {
let data = Data::FromDatabase { id: Immutable(id), entry };
Self { data, match_info: default() }
}

/// The label which should be displayed in the Component Browser.
pub fn label(&self) -> String {
self.to_string()
}

/// The name of the component.
pub fn name(&self) -> &str {
match &self.data {
Data::FromDatabase { entry, .. } => entry.name.as_str(),
Data::Virtual { snippet } => snippet.name,
}
}

/// The [`Id`] of the component in the [`suggestion_database`], or `None` if not applicable.
pub fn id(&self) -> Option<Id> {
match self.data {
Data::FromDatabase { id, .. } => Some(*id),
Data::Virtual { .. } => None,
}
}

/// Checks if component is filtered out.
pub fn is_filtered_out(&self) -> bool {
matches!(*self.match_info.borrow(), MatchInfo::DoesNotMatch)
Expand All @@ -97,7 +139,8 @@ impl Component {
/// Currently, only modules can be entered, and then the Browser should display content and
/// submodules of the entered module.
pub fn can_be_entered(&self) -> bool {
self.suggestion.kind == suggestion_database::entry::Kind::Module
use suggestion_database::entry::Kind as EntryKind;
matches!(&self.data, Data::FromDatabase { entry, .. } if entry.kind == EntryKind::Module)
}

/// Update matching info.
Expand All @@ -117,16 +160,27 @@ impl Component {
}
}

impl From<Rc<hardcoded::Snippet>> for Component {
fn from(snippet: Rc<hardcoded::Snippet>) -> Self {
Self { data: Data::Virtual { snippet }, match_info: default() }
}
}

impl Display for Component {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let self_type_not_here =
self.suggestion.self_type.as_ref().filter(|t| *t != &self.suggestion.module);
if let Some(self_type) = self_type_not_here {
let self_name = self_type.name.from_case(Case::Snake).to_case(Case::Title);
let name = self.suggestion.name.from_case(Case::Snake).to_case(Case::Lower);
write!(f, "{} {}", self_name, name)
} else {
write!(f, "{}", self.suggestion.name.from_case(Case::Snake).to_case(Case::Lower))
match &self.data {
Data::FromDatabase { entry, .. } => {
let entry_name = entry.name.from_case(Case::Snake).to_case(Case::Lower);
let self_type_ref = entry.self_type.as_ref();
let self_type_not_here = self_type_ref.filter(|t| *t != &entry.module);
if let Some(self_type) = self_type_not_here {
let self_name = self_type.name.from_case(Case::Snake).to_case(Case::Title);
write!(f, "{} {}", self_name, entry_name)
} else {
write!(f, "{}", entry_name)
}
}
Data::Virtual { snippet } => write!(f, "{}", snippet.name),
}
}
}
Expand Down Expand Up @@ -240,6 +294,7 @@ pub(crate) mod tests {
use crate::model::suggestion_database::entry::Kind;

use double_representation::module;
use double_representation::project;
use engine_protocol::language_server;


Expand Down Expand Up @@ -312,6 +367,7 @@ pub(crate) mod tests {
) -> Vec<crate::model::execution_context::ComponentGroup> {
let db_entries = component_ids.iter().map(|id| db.lookup(*id).unwrap());
let group = crate::model::execution_context::ComponentGroup {
project: project::QualifiedName::standard_base_library(),
name: "Test Group 1".into(),
color: None,
components: db_entries.into_iter().map(|e| e.qualified_name()).collect(),
Expand All @@ -331,7 +387,7 @@ pub(crate) mod tests {
.borrow()
.iter()
.take_while(|c| matches!(*c.match_info.borrow(), MatchInfo::Matches { .. }))
.map(|c| *c.id)
.map(|c| c.id().unwrap())
.collect_vec();
assert_eq!(ids_of_matches, expected_ids);
}
Expand Down Expand Up @@ -408,7 +464,7 @@ pub(crate) mod tests {
// ("test.Test.TopModule1.SubModule2").
let content = list.get_module_content(3).unwrap();
let expected_content_ids = vec![9, 4];
let content_ids = content.entries.borrow().iter().map(|entry| *entry.id).collect_vec();
let content_ids = content.entries.borrow().iter().map(|e| e.id().unwrap()).collect_vec();
assert_eq!(content_ids, expected_content_ids);
let direct_submodules = list.submodules_of(3).unwrap();
let expected_direct_submodules_ids = vec![Some(4)];
Expand All @@ -419,7 +475,7 @@ pub(crate) mod tests {
// ("test.Test.TopModule1.SubModule1.SubSubModule").
let content = list.get_module_content(4).unwrap();
let expected_content_ids = vec![10];
let content_ids = content.entries.borrow().iter().map(|entry| *entry.id).collect_vec();
let content_ids = content.entries.borrow().iter().map(|e| e.id().unwrap()).collect_vec();
assert_eq!(content_ids, expected_content_ids);
}
}
Loading