Skip to content

Commit

Permalink
Split Atom suggestion entry to Type and Constructor (#3835)
Browse files Browse the repository at this point in the history
Changelog:
- update: split `Atom` suggestion to `Type` and `Constructor`
- update: gui API
- update: JSONRPC doc
  • Loading branch information
4e6 committed Nov 2, 2022
1 parent 438a284 commit a6ce49e
Show file tree
Hide file tree
Showing 30 changed files with 1,321 additions and 514 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
- [Introduced IO Permission Contexts][3828]
- [Accept Array-like object seamlessly in builtins][3817]
- [Initialize Builtins at Native Image build time][3821]
- [Split Atom suggestion entry to Type and Constructor][3835]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -473,6 +474,7 @@
[3828]: https://github.com/enso-org/enso/pull/3828
[3817]: https://github.com/enso-org/enso/pull/3817
[3821]: https://github.com/enso-org/enso/pull/3821
[3835]: https://github.com/enso-org/enso/pull/3835

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
1 change: 1 addition & 0 deletions app/gui/controller/double-representation/src/import.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! A module with utilities managing imports.

use crate::prelude::*;

use crate::module;
Expand Down
16 changes: 16 additions & 0 deletions app/gui/controller/double-representation/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ impl QualifiedName {
})
})
}

/// Add a segment to this qualified name.
///
/// ```
/// # use double_representation::identifier::ReferentName;
/// # use double_representation::module::QualifiedName;
///
/// let mut name = QualifiedName::from_text("ns.Proj.Foo").unwrap();
/// let bar_segment = ReferentName::new("Bar").unwrap();
///
/// name.push_segment(bar_segment);
/// assert_eq!(name.to_string(), "ns.Proj.Foo.Bar");
/// ```
pub fn push_segment(&mut self, name: ReferentName) {
self.id.segments.push(name);
}
}

impl TryFrom<&str> for QualifiedName {
Expand Down
16 changes: 14 additions & 2 deletions app/gui/controller/engine-protocol/src/language_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,18 @@ pub enum SuggestionEntryType {
#[serde(rename_all = "camelCase")]
pub enum SuggestionEntry {
#[serde(rename_all = "camelCase")]
Atom {
Type {
external_id: Option<Uuid>,
name: String,
module: String,
params: Vec<SuggestionEntryArgument>,
documentation: Option<String>,
documentation_html: Option<String>,
#[serde(default, deserialize_with = "enso_prelude::deserialize_null_as_default")]
documentation_sections: Vec<DocSection>,
},
#[serde(rename_all = "camelCase")]
Constructor {
external_id: Option<Uuid>,
name: String,
module: String,
Expand Down Expand Up @@ -970,7 +981,8 @@ impl SuggestionEntry {
/// Get name of the suggested entity.
pub fn name(&self) -> &String {
match self {
Self::Atom { name, .. } => name,
Self::Type { name, .. } => name,
Self::Constructor { name, .. } => name,
Self::Function { name, .. } => name,
Self::Local { name, .. } => name,
Self::Method { name, .. } => name,
Expand Down
58 changes: 49 additions & 9 deletions app/gui/src/model/suggestion_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ mod test {
assert_eq!(db.version.get(), 123);

// Non-empty db
let entry = SuggestionEntry::Atom {
let entry = SuggestionEntry::Constructor {
name: "TextAtom".to_string(),
module: "TestProject.TestModule".to_string(),
arguments: vec![],
Expand All @@ -477,7 +477,7 @@ mod test {
#[test]
fn applying_update() {
let mut fixture = TestWithLocalPoolExecutor::set_up();
let entry1 = SuggestionEntry::Atom {
let entry1 = SuggestionEntry::Constructor {
name: "Entry1".to_owned(),
module: "TestProject.TestModule".to_owned(),
arguments: vec![],
Expand All @@ -487,7 +487,7 @@ mod test {
documentation_sections: default(),
external_id: None,
};
let entry2 = SuggestionEntry::Atom {
let entry2 = SuggestionEntry::Constructor {
name: "Entry2".to_owned(),
module: "TestProject.TestModule".to_owned(),
arguments: vec![],
Expand All @@ -497,7 +497,7 @@ mod test {
documentation_sections: default(),
external_id: None,
};
let new_entry2 = SuggestionEntry::Atom {
let new_entry2 = SuggestionEntry::Constructor {
name: "NewEntry2".to_owned(),
module: "TestProject.TestModule".to_owned(),
arguments: vec![],
Expand Down Expand Up @@ -773,7 +773,16 @@ mod test {
#[test]
fn lookup_by_fully_qualified_name_in_db_created_from_ls_response() {
// Initialize a suggestion database with sample entries.
let entry1 = SuggestionEntry::Atom {
let entry0 = SuggestionEntry::Type {
name: "TextType".to_string(),
module: "TestProject.TestModule".to_string(),
params: vec![],
documentation: None,
documentation_html: None,
documentation_sections: default(),
external_id: None,
};
let entry1 = SuggestionEntry::Constructor {
name: "TextAtom".to_string(),
module: "TestProject.TestModule".to_string(),
arguments: vec![],
Expand Down Expand Up @@ -818,6 +827,7 @@ mod test {
};
let ls_response = language_server::response::GetSuggestionDatabase {
entries: vec![
db_entry(0, entry0),
db_entry(1, entry1),
db_entry(2, entry2),
db_entry(3, entry3),
Expand All @@ -830,6 +840,7 @@ mod test {

// Check that the entries used to initialize the database can be found using the
// `lookup_by_fully_qualified_name` method.
lookup_and_verify_result_name(&db, "TestProject.TestModule.TextType");
lookup_and_verify_result_name(&db, "TestProject.TestModule.TextAtom");
lookup_and_verify_result_name(&db, "Standard.Builtins.Main.System.create_process");
lookup_and_verify_result_name(&db, "local.Unnamed_6.Main");
Expand Down Expand Up @@ -858,7 +869,7 @@ mod test {
#[test]
fn initialize_database_with_invalid_entries() {
// Prepare some nonsense inputs from the Engine.
let entry_with_empty_name = SuggestionEntry::Atom {
let entry_with_empty_name = SuggestionEntry::Constructor {
name: "".to_string(),
module: "Empty.Entry".to_string(),
arguments: vec![],
Expand Down Expand Up @@ -900,7 +911,16 @@ mod test {
#[test]
fn lookup_by_fully_qualified_name_after_db_update() {
// Initialize a suggestion database with a few sample entries.
let entry1 = SuggestionEntry::Atom {
let entry0 = SuggestionEntry::Type {
name: "TextType".to_string(),
module: "TestProject.TestModule".to_string(),
params: vec![],
documentation: None,
documentation_html: None,
documentation_sections: default(),
external_id: None,
};
let entry1 = SuggestionEntry::Constructor {
name: "TextAtom".to_string(),
module: "TestProject.TestModule".to_string(),
arguments: vec![],
Expand All @@ -924,15 +944,29 @@ mod test {
fn db_entry(id: SuggestionId, suggestion: SuggestionEntry) -> SuggestionsDatabaseEntry {
SuggestionsDatabaseEntry { id, suggestion }
}
let id0 = 0;
let id1 = 1;
let id2 = 2;
let response = language_server::response::GetSuggestionDatabase {
entries: vec![db_entry(id1, entry1), db_entry(id2, entry2)],
entries: vec![
db_entry(id0, entry0),
db_entry(id1, entry1),
db_entry(id2, entry2),
],
current_version: 1,
};
let db = SuggestionDatabase::from_ls_response(response);

// Modify the database contents by applying an update event.
let entry0_modification = Box::new(SuggestionsDatabaseModification {
arguments: vec![],
module: None,
self_type: None,
return_type: None,
documentation: Some(FieldUpdate::set("New doc".to_string())),
documentation_html: None,
scope: None,
});
let entry1_modification = Box::new(SuggestionsDatabaseModification {
arguments: vec![],
module: Some(FieldUpdate::set("NewProject.NewModule".to_string())),
Expand All @@ -951,6 +985,11 @@ mod test {
};
let update = SuggestionDatabaseUpdatesEvent {
updates: vec![
entry::Update::Modify {
id: id0,
external_id: None,
modification: entry0_modification,
},
entry::Update::Modify {
id: id1,
external_id: None,
Expand All @@ -966,6 +1005,7 @@ mod test {
// Check the results of `lookup_by_fully_qualified_name` after the update.
lookup_and_verify_empty_result(&db, "TestProject.TestModule.TextAtom");
lookup_and_verify_result_name(&db, "NewProject.NewModule.TextAtom");
lookup_and_verify_result_name(&db, "TestProject.TestModule.TextType");
lookup_and_verify_empty_result(&db, "Standard.Builtins.Main.System.create_process");
lookup_and_verify_result_name(&db, "local.Unnamed_6.Main");
}
Expand All @@ -977,7 +1017,7 @@ mod test {
#[test]
fn lookup_by_fully_qualified_name_after_db_update_reuses_id() {
// Initialize a suggestion database with a sample entry.
let entry1 = SuggestionEntry::Atom {
let entry1 = SuggestionEntry::Constructor {
name: "TextAtom".to_string(),
module: "TestProject.TestModule".to_string(),
arguments: vec![],
Expand Down
Loading

0 comments on commit a6ce49e

Please sign in to comment.