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

Display toasts for successful or failed dev extension installs #22893

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion crates/extension/src/extension_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ impl ExtensionBuilder {
.arg("sysroot")
.output()
.context("failed to run rustc")?;
if !rustc_output.status.success() {
if !rustc_output.status.success()
//TEMPORARY TEST - comment out above line to fail dev extension loading
{
bail!(
"failed to retrieve rust sysroot: {}",
String::from_utf8_lossy(&rustc_output.stderr)
Expand Down
48 changes: 39 additions & 9 deletions crates/extension_host/src/extension_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ pub enum ExtensionOperation {
}

#[derive(Clone)]
pub enum Event {
pub enum ExtensionEvent {
ExtensionsUpdated,
StartedReloading,
DevExtensionInstalling(Arc<str>),
DevExtensionInstallFailed(Arc<str>),
DevExtensionInstallSuccess,
ExtensionInstalled(Arc<str>),
ExtensionFailedToLoad(Arc<str>),
}

impl EventEmitter<Event> for ExtensionStore {}
impl EventEmitter<ExtensionEvent> for ExtensionStore {}

struct GlobalExtensionStore(Model<ExtensionStore>);

Expand Down Expand Up @@ -167,6 +170,8 @@ pub struct ExtensionIndexLanguageEntry {
}

actions!(zed, [ReloadExtensions]);
//moved from extension_us to avoid circular dependency
actions!(zed, [InstallDevExtension]);

pub fn init(
extension_host_proxy: Arc<ExtensionHostProxy>,
Expand Down Expand Up @@ -399,7 +404,7 @@ impl ExtensionStore {
self.reload_tx
.unbounded_send(modified_extension)
.expect("reload task exited");
cx.emit(Event::StartedReloading);
cx.emit(ExtensionEvent::StartedReloading);

async move {
rx.await.ok();
Expand Down Expand Up @@ -688,7 +693,7 @@ impl ExtensionStore {

if let ExtensionOperation::Install = operation {
this.update(&mut cx, |_, cx| {
cx.emit(Event::ExtensionInstalled(extension_id));
cx.emit(ExtensionEvent::ExtensionInstalled(extension_id));
})
.ok();
}
Expand Down Expand Up @@ -826,9 +831,22 @@ impl ExtensionStore {

cx.spawn(move |this, mut cx| async move {
let mut extension_manifest =
ExtensionManifest::load(fs.clone(), &extension_source_path).await?;
let extension_id = extension_manifest.id.clone();
ExtensionManifest::load(fs.clone(), &extension_source_path)
.await
.or_else(|e| {
this.update(&mut cx, |_, cx| {
let arc_string = Arc::new("invalid manifest".to_string());
let arc_str: Arc<str> = Arc::from((&*arc_string).to_string());
cx.emit(ExtensionEvent::DevExtensionInstallFailed(arc_str));
})?;
Err(e)
})?;

let extension_id = extension_manifest.id.clone();
this.update(&mut cx, |_, cx| {
let arc_str: Arc<str> = extension_manifest.id.clone();
cx.emit(ExtensionEvent::DevExtensionInstalling(arc_str));
})?;
if !this.update(&mut cx, |this, cx| {
match this.outstanding_operations.entry(extension_id.clone()) {
btree_map::Entry::Occupied(_) => return false,
Expand Down Expand Up @@ -866,7 +884,14 @@ impl ExtensionStore {
.await
}
})
.await?;
.await
.or_else(|e| {
this.update(&mut cx, |_, cx| {
let arc_str: Arc<str> = Arc::from(e.to_string());
cx.emit(ExtensionEvent::DevExtensionInstallFailed(arc_str));
})?;
Err(e)
})?;

let output_path = &extensions_dir.join(extension_id.as_ref());
if let Some(metadata) = fs.metadata(output_path).await? {
Expand All @@ -889,6 +914,9 @@ impl ExtensionStore {

this.update(&mut cx, |this, cx| this.reload(None, cx))?
.await;
this.update(&mut cx, |_, cx| {
cx.emit(ExtensionEvent::DevExtensionInstallSuccess);
})?;
Ok(())
})
}
Expand Down Expand Up @@ -1132,7 +1160,7 @@ impl ExtensionStore {

self.extension_index = new_index;
cx.notify();
cx.emit(Event::ExtensionsUpdated);
cx.emit(ExtensionEvent::ExtensionsUpdated);

cx.spawn(|this, mut cx| async move {
cx.background_executor()
Expand Down Expand Up @@ -1177,7 +1205,9 @@ impl ExtensionStore {
wasm_extensions.push((extension.manifest.clone(), wasm_extension));
} else {
this.update(&mut cx, |_, cx| {
cx.emit(Event::ExtensionFailedToLoad(extension.manifest.id.clone()))
cx.emit(ExtensionEvent::ExtensionFailedToLoad(
extension.manifest.id.clone(),
))
})
.ok();
}
Expand Down
6 changes: 3 additions & 3 deletions crates/extension_host/src/extension_store_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
Event, ExtensionIndex, ExtensionIndexEntry, ExtensionIndexLanguageEntry,
ExtensionEvent, ExtensionIndex, ExtensionIndexEntry, ExtensionIndexLanguageEntry,
ExtensionIndexThemeEntry, ExtensionManifest, ExtensionSettings, ExtensionStore,
GrammarManifestEntry, SchemaVersion, RELOAD_DEBOUNCE_DURATION,
};
Expand Down Expand Up @@ -592,15 +592,15 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
let executor = cx.executor();
let _task = cx.executor().spawn(async move {
while let Some(event) = events.next().await {
if let Event::StartedReloading = event {
if let ExtensionEvent::StartedReloading = event {
executor.advance_clock(RELOAD_DEBOUNCE_DURATION);
}
}
});

extension_store.update(cx, |_, cx| {
cx.subscribe(&extension_store, |_, _, event, _| {
if matches!(event, Event::ExtensionFailedToLoad(_)) {
if matches!(event, ExtensionEvent::ExtensionFailedToLoad(_)) {
panic!("extension failed to load");
}
})
Expand Down
13 changes: 7 additions & 6 deletions crates/extensions_ui/src/extensions_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::{ops::Range, sync::Arc};
use client::ExtensionMetadata;
use collections::{BTreeMap, BTreeSet};
use editor::{Editor, EditorElement, EditorStyle};
use extension_host::{ExtensionManifest, ExtensionOperation, ExtensionStore};
use extension_host::{ExtensionManifest, ExtensionOperation, ExtensionStore, InstallDevExtension};
use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{
actions, uniform_list, Action, AppContext, ClipboardItem, EventEmitter, Flatten, FocusableView,
uniform_list, Action, AppContext, ClipboardItem, EventEmitter, Flatten, FocusableView,
InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WindowContext,
};
Expand All @@ -34,8 +34,6 @@ use crate::extension_version_selector::{
ExtensionVersionSelector, ExtensionVersionSelectorDelegate,
};

actions!(zed, [InstallDevExtension]);

pub fn init(cx: &mut AppContext) {
cx.observe_new_views(move |workspace: &mut Workspace, cx| {
workspace
Expand Down Expand Up @@ -201,8 +199,10 @@ impl ExtensionsPage {
let subscriptions = [
cx.observe(&store, |_, _, cx| cx.notify()),
cx.subscribe(&store, move |this, _, event, cx| match event {
extension_host::Event::ExtensionsUpdated => this.fetch_extensions_debounced(cx),
extension_host::Event::ExtensionInstalled(extension_id) => {
extension_host::ExtensionEvent::ExtensionsUpdated => {
this.fetch_extensions_debounced(cx)
}
extension_host::ExtensionEvent::ExtensionInstalled(extension_id) => {
this.on_extension_installed(workspace_handle.clone(), extension_id, cx)
}
_ => {}
Expand Down Expand Up @@ -844,6 +844,7 @@ impl ExtensionsPage {
}

fn fetch_extensions_debounced(&mut self, cx: &mut ViewContext<ExtensionsPage>) {
//self.is_installing_dev_extension(None);
self.extension_fetch_task = Some(cx.spawn(|this, mut cx| async move {
let search = this
.update(&mut cx, |this, cx| this.search_query(cx))
Expand Down
1 change: 1 addition & 0 deletions crates/workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ clock.workspace = true
collections.workspace = true
db.workspace = true
derive_more.workspace = true
extension_host.workspace = true
fs.workspace = true
futures.workspace = true
gpui.workspace = true
Expand Down
43 changes: 43 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use client::{
use collections::{hash_map, HashMap, HashSet};
use derive_more::{Deref, DerefMut};
use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle, RESIZE_HANDLE_SIZE};
use extension_host::{ExtensionEvent, ExtensionStore, InstallDevExtension};
use futures::{
channel::{
mpsc::{self, UnboundedReceiver, UnboundedSender},
Expand Down Expand Up @@ -914,6 +915,21 @@ impl Workspace {
});
cx.subscribe(&center_pane, Self::handle_pane_event).detach();

let store = ExtensionStore::global(cx);
cx.subscribe(&store, |workspace, _, event, cx| match event {
ExtensionEvent::DevExtensionInstalling(m) => {
on_dev_extension_install(workspace, cx, &m.clone(), false)
}
ExtensionEvent::DevExtensionInstallSuccess => {
on_dev_extension_install(workspace, cx, &"Complete", false)
}
ExtensionEvent::DevExtensionInstallFailed(e) => {
on_dev_extension_install(workspace, cx, &e.clone(), true);
}
_ => {}
})
.detach();

cx.focus_view(&center_pane);
cx.emit(Event::PaneAdded(center_pane.clone()));

Expand Down Expand Up @@ -6253,6 +6269,33 @@ pub fn move_active_item(
});
}

fn on_dev_extension_install(
workspace: &mut Workspace,
cx: &mut ViewContext<Workspace>,
message: &str,
is_error: bool,
) {
if is_error {
let t = Toast::new(
NotificationId::unique::<InstallDevExtension>(),
format!("ERROR Installing Dev Extension: {}", message),
)
.on_click("Read more about creating Dev Extensions", {
move |cx| {
cx.open_url("https://zed.dev/docs/extensions/developing-extensions");
}
});
workspace.show_toast(t, cx);
} else {
let t = Toast::new(
NotificationId::unique::<InstallDevExtension>(),
format!("Installing Dev Extension: {}", message),
)
.autohide();
workspace.show_toast(t, cx);
}
}

#[cfg(test)]
mod tests {
use std::{cell::RefCell, rc::Rc};
Expand Down
Loading