Automatically uninstall release extension prior to dev extension install (#38088)

Finn Evers created

Closes https://github.com/zed-industries/zed/issues/31106

This fixes an issue where you would have to manually uninstall the
release extension before installing the dev extension in case that is
locally installed.

Release Notes:

- Installing a dev extension will now automatically remove the release
extension should it be installed.

Change summary

crates/extension_host/src/extension_host.rs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

Detailed changes

crates/extension_host/src/extension_host.rs 🔗

@@ -938,6 +938,20 @@ impl ExtensionStore {
                 ExtensionManifest::load(fs.clone(), &extension_source_path).await?;
             let extension_id = extension_manifest.id.clone();
 
+            if let Some(uninstall_task) = this
+                .update(cx, |this, cx| {
+                    this.extension_index
+                        .extensions
+                        .get(extension_id.as_ref())
+                        .is_some_and(|index_entry| !index_entry.dev)
+                        .then(|| this.uninstall_extension(extension_id.clone(), cx))
+                })
+                .ok()
+                .flatten()
+            {
+                uninstall_task.await.log_err();
+            }
+
             if !this.update(cx, |this, cx| {
                 match this.outstanding_operations.entry(extension_id.clone()) {
                     btree_map::Entry::Occupied(_) => return false,
@@ -986,7 +1000,7 @@ impl ExtensionStore {
                     )
                     .await?;
                 } else {
-                    bail!("extension {extension_id} is already installed");
+                    bail!("extension {extension_id} is still installed");
                 }
             }