Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Disable extension entries when the corresponding dev extension is installed (#10580)
Marshall Bowers0c77e1ce45d6
diff --git a/crates/extensions_ui/src/components/extension_card.rs b/crates/extensions_ui/src/components/extension_card.rsindex 7517f9363c4..d421fd9b9db 100644--- a/crates/extensions_ui/src/components/extension_card.rs+++ b/crates/extensions_ui/src/components/extension_card.rs@@ -4,15 +4,22 @@ use ui::prelude::*;#[derive(IntoElement)]pub struct ExtensionCard {+ overridden_by_dev_extension: bool,children: SmallVec<[AnyElement; 2]>,}impl ExtensionCard {pub fn new() -> Self {Self {+ overridden_by_dev_extension: false,children: SmallVec::new(),}}++ pub fn overridden_by_dev_extension(mut self, overridden: bool) -> Self {+ self.overridden_by_dev_extension = overridden;+ self+ }}impl ParentElement for ExtensionCard {@@ -34,7 +41,24 @@ impl RenderOnce for ExtensionCard {.border_1().border_color(cx.theme().colors().border).rounded_md()- .children(self.children),+ .children(self.children)+ .when(self.overridden_by_dev_extension, |card| {+ card.child(+ h_flex()+ .absolute()+ .top_0()+ .left_0()+ .occlude()+ .size_full()+ .items_center()+ .justify_center()+ .bg(theme::color_alpha(+ cx.theme().colors().elevated_surface_background,+ 0.8,+ ))+ .child(Label::new("Overridden by dev extension.")),+ )+ }),)}}diff --git a/crates/extensions_ui/src/extensions_ui.rs b/crates/extensions_ui/src/extensions_ui.rsindex 0720cc120d6..41d82a1405f 100644--- a/crates/extensions_ui/src/extensions_ui.rs+++ b/crates/extensions_ui/src/extensions_ui.rs@@ -190,6 +190,15 @@ impl ExtensionsPage {}}+ /// Returns whether a dev extension currently exists for the extension with the given ID.+ fn dev_extension_exists(extension_id: &str, cx: &mut ViewContext<Self>) -> bool {+ let extension_store = ExtensionStore::global(cx).read(cx);++ extension_store+ .dev_extensions()+ .any(|dev_extension| dev_extension.id.as_ref() == extension_id)+ }+fn extension_status(extension_id: &str, cx: &mut ViewContext<Self>) -> ExtensionStatus {let extension_store = ExtensionStore::global(cx).read(cx);@@ -417,10 +426,11 @@ impl ExtensionsPage {) -> ExtensionCard {let this = cx.view().clone();let status = Self::extension_status(&extension.id, cx);+ let has_dev_extension = Self::dev_extension_exists(&extension.id, cx);let extension_id = extension.id.clone();let (install_or_uninstall_button, upgrade_button) =- self.buttons_for_entry(extension, &status, cx);+ self.buttons_for_entry(extension, &status, has_dev_extension, cx);let version = extension.manifest.version.clone();let repository_url = extension.manifest.repository.clone();@@ -430,6 +440,7 @@ impl ExtensionsPage {};ExtensionCard::new()+ .overridden_by_dev_extension(has_dev_extension).child(h_flex().justify_between()@@ -588,10 +599,20 @@ impl ExtensionsPage {&self,extension: &ExtensionMetadata,status: &ExtensionStatus,+ has_dev_extension: bool,cx: &mut ViewContext<Self>,) -> (Button, Option<Button>) {let is_compatible = extension::is_version_compatible(&extension);+ if has_dev_extension {+ // If we have a dev extension for the given extension, just treat it as uninstalled.+ // The button here is a placeholder, as it won't be interactable anyways.+ return (+ Button::new(SharedString::from(extension.id.clone()), "Install"),+ None,+ );+ }+match status.clone() {ExtensionStatus::NotInstalled => (Button::new(SharedString::from(extension.id.clone()), "Install").on_click(