Skip to content

Commit

Permalink
Show custom icons in Component Browser (#3606)
Browse files Browse the repository at this point in the history
Show custom icons in Component Browser for entries that have a non-empty `Icon` section in their docs with the section's body containing a name of a predefined icon.

https://www.pivotaltracker.com/story/show/182584336

#### Visuals

A screenshot of a couple custom icons in the Component Browser:

<img width="346" alt="Screenshot 2022-07-27 at 15 55 33" src="https://user-images.githubusercontent.com/273837/181265249-d57f861f-8095-4933-9ef6-e62644e11da3.png">

# Important Notes
- The PR assigns icon names to four items in the standard library, but only three of them are shown in the Component Browser because of [a parsing bug in the Engine](https://www.pivotaltracker.com/story/show/182781673).
- Icon names are assigned only to four items in the standard library because only two currently predefined icons match entries in the currently defined Virtual Component Groups. Adjusting the definitions of icons and Virtual Component Groups is covered by [a different task](https://www.pivotaltracker.com/story/show/182584311).
- A bug in the documentation of the Enso protocol message `DocSection` is fixed. A `text` field in the `Tag` interface is renamed to `body` (this is the field name used in Engine).
  • Loading branch information
akavel authored Aug 1, 2022
1 parent 7f8190e commit c6835d2
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 134 deletions.
101 changes: 82 additions & 19 deletions app/gui/controller/engine-protocol/src/language_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,63 @@ pub enum RegisterOptions {
}



// ===================
// === Doc Section ===
// ===================

/// Text rendered as HTML (may contain HTML tags).
pub type HtmlString = String;

/// Documentation section mark.
#[derive(Hash, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub enum Mark {
Important,
Info,
Example,
}

/// A single section of the documentation.
#[derive(Hash, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(tag = "type")]
#[serde(rename_all = "camelCase")]
pub enum DocSection {
/// The documentation tag.
#[serde(rename_all = "camelCase")]
Tag {
/// The tag name.
name: String,
/// The tag text.
body: HtmlString,
},
/// The paragraph of the text.
#[serde(rename_all = "camelCase")]
Paragraph {
/// The elements that make up this paragraph.
body: HtmlString,
},
/// The section that starts with the key followed by the colon and the body.
#[serde(rename_all = "camelCase")]
Keyed {
/// The section key.
key: String,
/// The elements that make up the body of the section.
body: HtmlString,
},
/// The section that starts with the mark followed by the header and the body.
#[serde(rename_all = "camelCase")]
Marked {
/// The section mark.
mark: Mark,
/// The section header.
header: Option<String>,
/// The elements that make up the body of the section.
body: HtmlString,
},
}

// ===========================
// === Suggestion Database ===
// ===========================
Expand Down Expand Up @@ -844,24 +901,28 @@ pub enum SuggestionEntryType {
pub enum SuggestionEntry {
#[serde(rename_all = "camelCase")]
Atom {
external_id: Option<Uuid>,
name: String,
module: String,
arguments: Vec<SuggestionEntryArgument>,
return_type: String,
documentation: Option<String>,
documentation_html: Option<String>,
external_id: Option<Uuid>,
name: String,
module: String,
arguments: Vec<SuggestionEntryArgument>,
return_type: String,
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")]
Method {
external_id: Option<Uuid>,
name: String,
module: String,
arguments: Vec<SuggestionEntryArgument>,
self_type: String,
return_type: String,
documentation: Option<String>,
documentation_html: Option<String>,
external_id: Option<Uuid>,
name: String,
module: String,
arguments: Vec<SuggestionEntryArgument>,
self_type: String,
return_type: String,
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")]
Function {
Expand All @@ -882,10 +943,12 @@ pub enum SuggestionEntry {
},
#[serde(rename_all = "camelCase")]
Module {
module: String,
documentation: Option<String>,
documentation_html: Option<String>,
reexport: Option<String>,
module: String,
documentation: Option<String>,
documentation_html: Option<String>,
reexport: Option<String>,
#[serde(default, deserialize_with = "enso_prelude::deserialize_null_as_default")]
documentation_sections: Vec<DocSection>,
},
}

Expand Down
3 changes: 3 additions & 0 deletions app/gui/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ impl Searcher {
documentation_html: None,
self_type: Some(self_type.clone()),
scope: model::suggestion_database::entry::Scope::Everywhere,
icon_name: None,
};
let action = Action::Suggestion(action::Suggestion::FromDatabase(Rc::new(entry)));
libraries_cat_builder.add_action(action);
Expand Down Expand Up @@ -1492,6 +1493,7 @@ pub mod test {
documentation_html: default(),
self_type: None,
scope,
icon_name: None,
};
let entry2 = model::suggestion_database::Entry {
name: "TestVar1".to_string(),
Expand Down Expand Up @@ -1551,6 +1553,7 @@ pub mod test {
documentation_html: None,
self_type: None,
scope: Scope::Everywhere,
icon_name: None,
};
let entry9 = model::suggestion_database::Entry {
name: "testFunction2".to_string(),
Expand Down
10 changes: 6 additions & 4 deletions app/gui/src/controller/searcher/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ pub(crate) mod tests {

pub fn mock_module(name: &str) -> model::suggestion_database::Entry {
let ls_entry = language_server::SuggestionEntry::Module {
module: name.to_owned(),
documentation: default(),
documentation_html: default(),
reexport: default(),
module: name.to_owned(),
documentation: default(),
documentation_html: default(),
documentation_sections: default(),
reexport: default(),
};
model::suggestion_database::Entry::from_ls_entry(ls_entry).unwrap()
}
Expand All @@ -268,6 +269,7 @@ pub(crate) mod tests {
documentation_html: None,
self_type: None,
scope: model::suggestion_database::entry::Scope::Everywhere,
icon_name: None,
}
}

Expand Down
Loading

0 comments on commit c6835d2

Please sign in to comment.