extensions_ui.rs

   1mod components;
   2mod extension_suggest;
   3mod extension_version_selector;
   4
   5use std::sync::OnceLock;
   6use std::time::Duration;
   7use std::{ops::Range, sync::Arc};
   8
   9use client::{ExtensionMetadata, ExtensionProvides};
  10use collections::{BTreeMap, BTreeSet};
  11use editor::{Editor, EditorElement, EditorStyle};
  12use extension_host::{ExtensionManifest, ExtensionOperation, ExtensionStore};
  13use fuzzy::{StringMatchCandidate, match_strings};
  14use gpui::{
  15    Action, App, ClipboardItem, Context, Entity, EventEmitter, Flatten, Focusable,
  16    InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
  17    UniformListScrollHandle, WeakEntity, Window, actions, point, uniform_list,
  18};
  19use num_format::{Locale, ToFormattedString};
  20use project::DirectoryLister;
  21use release_channel::ReleaseChannel;
  22use settings::Settings;
  23use strum::IntoEnumIterator as _;
  24use theme::ThemeSettings;
  25use ui::{
  26    CheckboxWithLabel, ContextMenu, PopoverMenu, ScrollableHandle, Scrollbar, ScrollbarState,
  27    ToggleButton, Tooltip, prelude::*,
  28};
  29use vim_mode_setting::VimModeSetting;
  30use workspace::{
  31    Workspace, WorkspaceId,
  32    item::{Item, ItemEvent},
  33};
  34use zed_actions::ExtensionCategoryFilter;
  35
  36use crate::components::{ExtensionCard, FeatureUpsell};
  37use crate::extension_version_selector::{
  38    ExtensionVersionSelector, ExtensionVersionSelectorDelegate,
  39};
  40
  41actions!(zed, [InstallDevExtension]);
  42
  43pub fn init(cx: &mut App) {
  44    cx.observe_new(move |workspace: &mut Workspace, window, cx| {
  45        let Some(window) = window else {
  46            return;
  47        };
  48        workspace
  49            .register_action(
  50                move |workspace, action: &zed_actions::Extensions, window, cx| {
  51                    let provides_filter = action.category_filter.map(|category| match category {
  52                        ExtensionCategoryFilter::Themes => ExtensionProvides::Themes,
  53                        ExtensionCategoryFilter::IconThemes => ExtensionProvides::IconThemes,
  54                        ExtensionCategoryFilter::Languages => ExtensionProvides::Languages,
  55                        ExtensionCategoryFilter::Grammars => ExtensionProvides::Grammars,
  56                        ExtensionCategoryFilter::LanguageServers => {
  57                            ExtensionProvides::LanguageServers
  58                        }
  59                        ExtensionCategoryFilter::ContextServers => {
  60                            ExtensionProvides::ContextServers
  61                        }
  62                        ExtensionCategoryFilter::SlashCommands => ExtensionProvides::SlashCommands,
  63                        ExtensionCategoryFilter::IndexedDocsProviders => {
  64                            ExtensionProvides::IndexedDocsProviders
  65                        }
  66                        ExtensionCategoryFilter::Snippets => ExtensionProvides::Snippets,
  67                    });
  68
  69                    let existing = workspace
  70                        .active_pane()
  71                        .read(cx)
  72                        .items()
  73                        .find_map(|item| item.downcast::<ExtensionsPage>());
  74
  75                    if let Some(existing) = existing {
  76                        if provides_filter.is_some() {
  77                            existing.update(cx, |extensions_page, cx| {
  78                                extensions_page.change_provides_filter(provides_filter, cx);
  79                            });
  80                        }
  81
  82                        workspace.activate_item(&existing, true, true, window, cx);
  83                    } else {
  84                        let extensions_page =
  85                            ExtensionsPage::new(workspace, provides_filter, window, cx);
  86                        workspace.add_item_to_active_pane(
  87                            Box::new(extensions_page),
  88                            None,
  89                            true,
  90                            window,
  91                            cx,
  92                        )
  93                    }
  94                },
  95            )
  96            .register_action(move |workspace, _: &InstallDevExtension, window, cx| {
  97                let store = ExtensionStore::global(cx);
  98                let prompt = workspace.prompt_for_open_path(
  99                    gpui::PathPromptOptions {
 100                        files: false,
 101                        directories: true,
 102                        multiple: false,
 103                    },
 104                    DirectoryLister::Local(
 105                        workspace.project().clone(),
 106                        workspace.app_state().fs.clone(),
 107                    ),
 108                    window,
 109                    cx,
 110                );
 111
 112                let workspace_handle = cx.entity().downgrade();
 113                window
 114                    .spawn(cx, async move |cx| {
 115                        let extension_path =
 116                            match Flatten::flatten(prompt.await.map_err(|e| e.into())) {
 117                                Ok(Some(mut paths)) => paths.pop()?,
 118                                Ok(None) => return None,
 119                                Err(err) => {
 120                                    workspace_handle
 121                                        .update(cx, |workspace, cx| {
 122                                            workspace.show_portal_error(err.to_string(), cx);
 123                                        })
 124                                        .ok();
 125                                    return None;
 126                                }
 127                            };
 128
 129                        let install_task = store
 130                            .update(cx, |store, cx| {
 131                                store.install_dev_extension(extension_path, cx)
 132                            })
 133                            .ok()?;
 134
 135                        match install_task.await {
 136                            Ok(_) => {}
 137                            Err(err) => {
 138                                log::error!("Failed to install dev extension: {:?}", err);
 139                                workspace_handle
 140                                    .update(cx, |workspace, cx| {
 141                                        workspace.show_error(
 142                                            // NOTE: using `anyhow::context` here ends up not printing
 143                                            // the error
 144                                            &format!("Failed to install dev extension: {}", err),
 145                                            cx,
 146                                        );
 147                                    })
 148                                    .ok();
 149                            }
 150                        }
 151
 152                        Some(())
 153                    })
 154                    .detach();
 155            });
 156
 157        cx.subscribe_in(workspace.project(), window, |_, _, event, window, cx| {
 158            if let project::Event::LanguageNotFound(buffer) = event {
 159                extension_suggest::suggest(buffer.clone(), window, cx);
 160            }
 161        })
 162        .detach();
 163    })
 164    .detach();
 165}
 166
 167fn extension_provides_label(provides: ExtensionProvides) -> &'static str {
 168    match provides {
 169        ExtensionProvides::Themes => "Themes",
 170        ExtensionProvides::IconThemes => "Icon Themes",
 171        ExtensionProvides::Languages => "Languages",
 172        ExtensionProvides::Grammars => "Grammars",
 173        ExtensionProvides::LanguageServers => "Language Servers",
 174        ExtensionProvides::ContextServers => "MCP Servers",
 175        ExtensionProvides::SlashCommands => "Slash Commands",
 176        ExtensionProvides::IndexedDocsProviders => "Indexed Docs Providers",
 177        ExtensionProvides::Snippets => "Snippets",
 178    }
 179}
 180
 181#[derive(Clone)]
 182pub enum ExtensionStatus {
 183    NotInstalled,
 184    Installing,
 185    Upgrading,
 186    Installed(Arc<str>),
 187    Removing,
 188}
 189
 190#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
 191enum ExtensionFilter {
 192    All,
 193    Installed,
 194    NotInstalled,
 195}
 196
 197impl ExtensionFilter {
 198    pub fn include_dev_extensions(&self) -> bool {
 199        match self {
 200            Self::All | Self::Installed => true,
 201            Self::NotInstalled => false,
 202        }
 203    }
 204}
 205
 206#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
 207enum Feature {
 208    Git,
 209    OpenIn,
 210    Vim,
 211    LanguageBash,
 212    LanguageC,
 213    LanguageCpp,
 214    LanguageGo,
 215    LanguagePython,
 216    LanguageReact,
 217    LanguageRust,
 218    LanguageTypescript,
 219}
 220
 221fn keywords_by_feature() -> &'static BTreeMap<Feature, Vec<&'static str>> {
 222    static KEYWORDS_BY_FEATURE: OnceLock<BTreeMap<Feature, Vec<&'static str>>> = OnceLock::new();
 223    KEYWORDS_BY_FEATURE.get_or_init(|| {
 224        BTreeMap::from_iter([
 225            (Feature::Git, vec!["git"]),
 226            (
 227                Feature::OpenIn,
 228                vec![
 229                    "github",
 230                    "gitlab",
 231                    "bitbucket",
 232                    "codeberg",
 233                    "sourcehut",
 234                    "permalink",
 235                    "link",
 236                    "open in",
 237                ],
 238            ),
 239            (Feature::Vim, vec!["vim"]),
 240            (Feature::LanguageBash, vec!["sh", "bash"]),
 241            (Feature::LanguageC, vec!["c", "clang"]),
 242            (Feature::LanguageCpp, vec!["c++", "cpp", "clang"]),
 243            (Feature::LanguageGo, vec!["go", "golang"]),
 244            (Feature::LanguagePython, vec!["python", "py"]),
 245            (Feature::LanguageReact, vec!["react"]),
 246            (Feature::LanguageRust, vec!["rust", "rs"]),
 247            (
 248                Feature::LanguageTypescript,
 249                vec!["type", "typescript", "ts"],
 250            ),
 251        ])
 252    })
 253}
 254
 255struct ExtensionCardButtons {
 256    install_or_uninstall: Button,
 257    upgrade: Option<Button>,
 258    configure: Option<Button>,
 259}
 260
 261pub struct ExtensionsPage {
 262    workspace: WeakEntity<Workspace>,
 263    list: UniformListScrollHandle,
 264    is_fetching_extensions: bool,
 265    filter: ExtensionFilter,
 266    remote_extension_entries: Vec<ExtensionMetadata>,
 267    dev_extension_entries: Vec<Arc<ExtensionManifest>>,
 268    filtered_remote_extension_indices: Vec<usize>,
 269    query_editor: Entity<Editor>,
 270    query_contains_error: bool,
 271    provides_filter: Option<ExtensionProvides>,
 272    _subscriptions: [gpui::Subscription; 2],
 273    extension_fetch_task: Option<Task<()>>,
 274    upsells: BTreeSet<Feature>,
 275    scrollbar_state: ScrollbarState,
 276}
 277
 278impl ExtensionsPage {
 279    pub fn new(
 280        workspace: &Workspace,
 281        provides_filter: Option<ExtensionProvides>,
 282        window: &mut Window,
 283        cx: &mut Context<Workspace>,
 284    ) -> Entity<Self> {
 285        cx.new(|cx| {
 286            let store = ExtensionStore::global(cx);
 287            let workspace_handle = workspace.weak_handle();
 288            let subscriptions = [
 289                cx.observe(&store, |_: &mut Self, _, cx| cx.notify()),
 290                cx.subscribe_in(
 291                    &store,
 292                    window,
 293                    move |this, _, event, window, cx| match event {
 294                        extension_host::Event::ExtensionsUpdated => {
 295                            this.fetch_extensions_debounced(None, cx)
 296                        }
 297                        extension_host::Event::ExtensionInstalled(extension_id) => this
 298                            .on_extension_installed(
 299                                workspace_handle.clone(),
 300                                extension_id,
 301                                window,
 302                                cx,
 303                            ),
 304                        _ => {}
 305                    },
 306                ),
 307            ];
 308
 309            let query_editor = cx.new(|cx| {
 310                let mut input = Editor::single_line(window, cx);
 311                input.set_placeholder_text("Search extensions...", cx);
 312                input
 313            });
 314            cx.subscribe(&query_editor, Self::on_query_change).detach();
 315
 316            let scroll_handle = UniformListScrollHandle::new();
 317
 318            let mut this = Self {
 319                workspace: workspace.weak_handle(),
 320                list: scroll_handle.clone(),
 321                is_fetching_extensions: false,
 322                filter: ExtensionFilter::All,
 323                dev_extension_entries: Vec::new(),
 324                filtered_remote_extension_indices: Vec::new(),
 325                remote_extension_entries: Vec::new(),
 326                query_contains_error: false,
 327                provides_filter,
 328                extension_fetch_task: None,
 329                _subscriptions: subscriptions,
 330                query_editor,
 331                upsells: BTreeSet::default(),
 332                scrollbar_state: ScrollbarState::new(scroll_handle),
 333            };
 334            this.fetch_extensions(
 335                None,
 336                Some(BTreeSet::from_iter(this.provides_filter)),
 337                None,
 338                cx,
 339            );
 340            this
 341        })
 342    }
 343
 344    fn on_extension_installed(
 345        &mut self,
 346        workspace: WeakEntity<Workspace>,
 347        extension_id: &str,
 348        window: &mut Window,
 349        cx: &mut Context<Self>,
 350    ) {
 351        let extension_store = ExtensionStore::global(cx).read(cx);
 352        let themes = extension_store
 353            .extension_themes(extension_id)
 354            .map(|name| name.to_string())
 355            .collect::<Vec<_>>();
 356        if !themes.is_empty() {
 357            workspace
 358                .update(cx, |_workspace, cx| {
 359                    window.dispatch_action(
 360                        zed_actions::theme_selector::Toggle {
 361                            themes_filter: Some(themes),
 362                        }
 363                        .boxed_clone(),
 364                        cx,
 365                    );
 366                })
 367                .ok();
 368            return;
 369        }
 370
 371        let icon_themes = extension_store
 372            .extension_icon_themes(extension_id)
 373            .map(|name| name.to_string())
 374            .collect::<Vec<_>>();
 375        if !icon_themes.is_empty() {
 376            workspace
 377                .update(cx, |_workspace, cx| {
 378                    window.dispatch_action(
 379                        zed_actions::icon_theme_selector::Toggle {
 380                            themes_filter: Some(icon_themes),
 381                        }
 382                        .boxed_clone(),
 383                        cx,
 384                    );
 385                })
 386                .ok();
 387        }
 388    }
 389
 390    /// Returns whether a dev extension currently exists for the extension with the given ID.
 391    fn dev_extension_exists(extension_id: &str, cx: &mut Context<Self>) -> bool {
 392        let extension_store = ExtensionStore::global(cx).read(cx);
 393
 394        extension_store
 395            .dev_extensions()
 396            .any(|dev_extension| dev_extension.id.as_ref() == extension_id)
 397    }
 398
 399    fn extension_status(extension_id: &str, cx: &mut Context<Self>) -> ExtensionStatus {
 400        let extension_store = ExtensionStore::global(cx).read(cx);
 401
 402        match extension_store.outstanding_operations().get(extension_id) {
 403            Some(ExtensionOperation::Install) => ExtensionStatus::Installing,
 404            Some(ExtensionOperation::Remove) => ExtensionStatus::Removing,
 405            Some(ExtensionOperation::Upgrade) => ExtensionStatus::Upgrading,
 406            None => match extension_store.installed_extensions().get(extension_id) {
 407                Some(extension) => ExtensionStatus::Installed(extension.manifest.version.clone()),
 408                None => ExtensionStatus::NotInstalled,
 409            },
 410        }
 411    }
 412
 413    fn filter_extension_entries(&mut self, cx: &mut Context<Self>) {
 414        self.filtered_remote_extension_indices.clear();
 415        self.filtered_remote_extension_indices.extend(
 416            self.remote_extension_entries
 417                .iter()
 418                .enumerate()
 419                .filter(|(_, extension)| match self.filter {
 420                    ExtensionFilter::All => true,
 421                    ExtensionFilter::Installed => {
 422                        let status = Self::extension_status(&extension.id, cx);
 423                        matches!(status, ExtensionStatus::Installed(_))
 424                    }
 425                    ExtensionFilter::NotInstalled => {
 426                        let status = Self::extension_status(&extension.id, cx);
 427
 428                        matches!(status, ExtensionStatus::NotInstalled)
 429                    }
 430                })
 431                .map(|(ix, _)| ix),
 432        );
 433        cx.notify();
 434    }
 435
 436    fn scroll_to_top(&mut self, cx: &mut Context<Self>) {
 437        self.list.set_offset(point(px(0.), px(0.)));
 438        cx.notify();
 439    }
 440
 441    fn fetch_extensions(
 442        &mut self,
 443        search: Option<String>,
 444        provides_filter: Option<BTreeSet<ExtensionProvides>>,
 445        on_complete: Option<Box<dyn FnOnce(&mut Self, &mut Context<Self>) + Send>>,
 446        cx: &mut Context<Self>,
 447    ) {
 448        self.is_fetching_extensions = true;
 449        cx.notify();
 450
 451        let extension_store = ExtensionStore::global(cx);
 452
 453        let dev_extensions = extension_store
 454            .read(cx)
 455            .dev_extensions()
 456            .cloned()
 457            .collect::<Vec<_>>();
 458
 459        let remote_extensions = extension_store.update(cx, |store, cx| {
 460            store.fetch_extensions(search.as_deref(), provides_filter.as_ref(), cx)
 461        });
 462
 463        cx.spawn(async move |this, cx| {
 464            let dev_extensions = if let Some(search) = search {
 465                let match_candidates = dev_extensions
 466                    .iter()
 467                    .enumerate()
 468                    .map(|(ix, manifest)| StringMatchCandidate::new(ix, &manifest.name))
 469                    .collect::<Vec<_>>();
 470
 471                let matches = match_strings(
 472                    &match_candidates,
 473                    &search,
 474                    false,
 475                    match_candidates.len(),
 476                    &Default::default(),
 477                    cx.background_executor().clone(),
 478                )
 479                .await;
 480                matches
 481                    .into_iter()
 482                    .map(|mat| dev_extensions[mat.candidate_id].clone())
 483                    .collect()
 484            } else {
 485                dev_extensions
 486            };
 487
 488            let fetch_result = remote_extensions.await;
 489            this.update(cx, |this, cx| {
 490                cx.notify();
 491                this.dev_extension_entries = dev_extensions;
 492                this.is_fetching_extensions = false;
 493                this.remote_extension_entries = fetch_result?;
 494                this.filter_extension_entries(cx);
 495                if let Some(callback) = on_complete {
 496                    callback(this, cx);
 497                }
 498                anyhow::Ok(())
 499            })?
 500        })
 501        .detach_and_log_err(cx);
 502    }
 503
 504    fn render_extensions(
 505        &mut self,
 506        range: Range<usize>,
 507        _: &mut Window,
 508        cx: &mut Context<Self>,
 509    ) -> Vec<ExtensionCard> {
 510        let dev_extension_entries_len = if self.filter.include_dev_extensions() {
 511            self.dev_extension_entries.len()
 512        } else {
 513            0
 514        };
 515        range
 516            .map(|ix| {
 517                if ix < dev_extension_entries_len {
 518                    let extension = &self.dev_extension_entries[ix];
 519                    self.render_dev_extension(extension, cx)
 520                } else {
 521                    let extension_ix =
 522                        self.filtered_remote_extension_indices[ix - dev_extension_entries_len];
 523                    let extension = &self.remote_extension_entries[extension_ix];
 524                    self.render_remote_extension(extension, cx)
 525                }
 526            })
 527            .collect()
 528    }
 529
 530    fn render_dev_extension(
 531        &self,
 532        extension: &ExtensionManifest,
 533        cx: &mut Context<Self>,
 534    ) -> ExtensionCard {
 535        let status = Self::extension_status(&extension.id, cx);
 536
 537        let repository_url = extension.repository.clone();
 538
 539        let can_configure = !extension.context_servers.is_empty();
 540
 541        ExtensionCard::new()
 542            .child(
 543                h_flex()
 544                    .justify_between()
 545                    .child(
 546                        h_flex()
 547                            .gap_2()
 548                            .items_end()
 549                            .child(Headline::new(extension.name.clone()).size(HeadlineSize::Medium))
 550                            .child(
 551                                Headline::new(format!("v{}", extension.version))
 552                                    .size(HeadlineSize::XSmall),
 553                            ),
 554                    )
 555                    .child(
 556                        h_flex()
 557                            .gap_2()
 558                            .justify_between()
 559                            .child(
 560                                Button::new(
 561                                    SharedString::from(format!("rebuild-{}", extension.id)),
 562                                    "Rebuild",
 563                                )
 564                                .on_click({
 565                                    let extension_id = extension.id.clone();
 566                                    move |_, _, cx| {
 567                                        ExtensionStore::global(cx).update(cx, |store, cx| {
 568                                            store.rebuild_dev_extension(extension_id.clone(), cx)
 569                                        });
 570                                    }
 571                                })
 572                                .color(Color::Accent)
 573                                .disabled(matches!(status, ExtensionStatus::Upgrading)),
 574                            )
 575                            .child(
 576                                Button::new(SharedString::from(extension.id.clone()), "Uninstall")
 577                                    .on_click({
 578                                        let extension_id = extension.id.clone();
 579                                        move |_, _, cx| {
 580                                            ExtensionStore::global(cx).update(cx, |store, cx| {
 581                                                store.uninstall_extension(extension_id.clone(), cx)
 582                                            });
 583                                        }
 584                                    })
 585                                    .color(Color::Accent)
 586                                    .disabled(matches!(status, ExtensionStatus::Removing)),
 587                            )
 588                            .when(can_configure, |this| {
 589                                this.child(
 590                                    Button::new(
 591                                        SharedString::from(format!("configure-{}", extension.id)),
 592                                        "Configure",
 593                                    )
 594
 595
 596                                    .on_click({
 597                                        let manifest = Arc::new(extension.clone());
 598                                        move |_, _, cx| {
 599                                            if let Some(events) =
 600                                                extension::ExtensionEvents::try_global(cx)
 601                                            {
 602                                                events.update(cx, |this, cx| {
 603                                                    this.emit(
 604                                                        extension::Event::ConfigureExtensionRequested(
 605                                                            manifest.clone(),
 606                                                        ),
 607                                                        cx,
 608                                                    )
 609                                                });
 610                                            }
 611                                        }
 612                                    })
 613                                    .color(Color::Accent)
 614                                    .disabled(matches!(status, ExtensionStatus::Installing)),
 615                                )
 616                            }),
 617                    ),
 618            )
 619            .child(
 620                h_flex()
 621                    .gap_2()
 622                    .justify_between()
 623                    .child(
 624                        Label::new(format!(
 625                            "{}: {}",
 626                            if extension.authors.len() > 1 {
 627                                "Authors"
 628                            } else {
 629                                "Author"
 630                            },
 631                            extension.authors.join(", ")
 632                        ))
 633                        .size(LabelSize::Small)
 634                        .color(Color::Muted)
 635                        .truncate(),
 636                    )
 637                    .child(Label::new("<>").size(LabelSize::Small)),
 638            )
 639            .child(
 640                h_flex()
 641                    .gap_2()
 642                    .justify_between()
 643                    .children(extension.description.as_ref().map(|description| {
 644                        Label::new(description.clone())
 645                            .size(LabelSize::Small)
 646                            .color(Color::Default)
 647                            .truncate()
 648                    }))
 649                    .children(repository_url.map(|repository_url| {
 650                        IconButton::new(
 651                            SharedString::from(format!("repository-{}", extension.id)),
 652                            IconName::Github,
 653                        )
 654                        .icon_color(Color::Accent)
 655                        .icon_size(IconSize::Small)
 656                        .on_click(cx.listener({
 657                            let repository_url = repository_url.clone();
 658                            move |_, _, _, cx| {
 659                                cx.open_url(&repository_url);
 660                            }
 661                        }))
 662                        .tooltip(Tooltip::text(repository_url.clone()))
 663                    })),
 664            )
 665    }
 666
 667    fn render_remote_extension(
 668        &self,
 669        extension: &ExtensionMetadata,
 670        cx: &mut Context<Self>,
 671    ) -> ExtensionCard {
 672        let this = cx.entity().clone();
 673        let status = Self::extension_status(&extension.id, cx);
 674        let has_dev_extension = Self::dev_extension_exists(&extension.id, cx);
 675
 676        let extension_id = extension.id.clone();
 677        let buttons = self.buttons_for_entry(extension, &status, has_dev_extension, cx);
 678        let version = extension.manifest.version.clone();
 679        let repository_url = extension.manifest.repository.clone();
 680        let authors = extension.manifest.authors.clone();
 681
 682        let installed_version = match status {
 683            ExtensionStatus::Installed(installed_version) => Some(installed_version),
 684            _ => None,
 685        };
 686
 687        ExtensionCard::new()
 688            .overridden_by_dev_extension(has_dev_extension)
 689            .child(
 690                h_flex()
 691                    .justify_between()
 692                    .child(
 693                        h_flex()
 694                            .gap_2()
 695                            .child(
 696                                Headline::new(extension.manifest.name.clone())
 697                                    .size(HeadlineSize::Medium),
 698                            )
 699                            .child(Headline::new(format!("v{version}")).size(HeadlineSize::XSmall))
 700                            .children(
 701                                installed_version
 702                                    .filter(|installed_version| *installed_version != version)
 703                                    .map(|installed_version| {
 704                                        Headline::new(format!("(v{installed_version} installed)",))
 705                                            .size(HeadlineSize::XSmall)
 706                                    }),
 707                            )
 708                            .map(|parent| {
 709                                if extension.manifest.provides.is_empty() {
 710                                    return parent;
 711                                }
 712
 713                                parent.child(
 714                                    h_flex().gap_2().children(
 715                                        extension
 716                                            .manifest
 717                                            .provides
 718                                            .iter()
 719                                            .map(|provides| {
 720                                                div()
 721                                                    .bg(cx.theme().colors().element_background)
 722                                                    .px_0p5()
 723                                                    .border_1()
 724                                                    .border_color(cx.theme().colors().border)
 725                                                    .rounded_sm()
 726                                                    .child(
 727                                                        Label::new(extension_provides_label(
 728                                                            *provides,
 729                                                        ))
 730                                                        .size(LabelSize::XSmall),
 731                                                    )
 732                                            })
 733                                            .collect::<Vec<_>>(),
 734                                    ),
 735                                )
 736                            }),
 737                    )
 738                    .child(
 739                        h_flex()
 740                            .gap_2()
 741                            .justify_between()
 742                            .children(buttons.upgrade)
 743                            .children(buttons.configure)
 744                            .child(buttons.install_or_uninstall),
 745                    ),
 746            )
 747            .child(
 748                h_flex()
 749                    .gap_2()
 750                    .justify_between()
 751                    .child(
 752                        Label::new(format!(
 753                            "{}: {}",
 754                            if extension.manifest.authors.len() > 1 {
 755                                "Authors"
 756                            } else {
 757                                "Author"
 758                            },
 759                            extension.manifest.authors.join(", ")
 760                        ))
 761                        .size(LabelSize::Small)
 762                        .color(Color::Muted)
 763                        .truncate(),
 764                    )
 765                    .child(
 766                        Label::new(format!(
 767                            "Downloads: {}",
 768                            extension.download_count.to_formatted_string(&Locale::en)
 769                        ))
 770                        .size(LabelSize::Small),
 771                    ),
 772            )
 773            .child(
 774                h_flex()
 775                    .gap_2()
 776                    .justify_between()
 777                    .children(extension.manifest.description.as_ref().map(|description| {
 778                        Label::new(description.clone())
 779                            .size(LabelSize::Small)
 780                            .color(Color::Default)
 781                            .truncate()
 782                    }))
 783                    .child(
 784                        h_flex()
 785                            .gap_2()
 786                            .child(
 787                                IconButton::new(
 788                                    SharedString::from(format!("repository-{}", extension.id)),
 789                                    IconName::Github,
 790                                )
 791                                .icon_color(Color::Accent)
 792                                .icon_size(IconSize::Small)
 793                                .on_click(cx.listener({
 794                                    let repository_url = repository_url.clone();
 795                                    move |_, _, _, cx| {
 796                                        cx.open_url(&repository_url);
 797                                    }
 798                                }))
 799                                .tooltip(Tooltip::text(repository_url.clone())),
 800                            )
 801                            .child(
 802                                PopoverMenu::new(SharedString::from(format!(
 803                                    "more-{}",
 804                                    extension.id
 805                                )))
 806                                .trigger(
 807                                    IconButton::new(
 808                                        SharedString::from(format!("more-{}", extension.id)),
 809                                        IconName::Ellipsis,
 810                                    )
 811                                    .icon_color(Color::Accent)
 812                                    .icon_size(IconSize::Small),
 813                                )
 814                                .menu(move |window, cx| {
 815                                    Some(Self::render_remote_extension_context_menu(
 816                                        &this,
 817                                        extension_id.clone(),
 818                                        authors.clone(),
 819                                        window,
 820                                        cx,
 821                                    ))
 822                                }),
 823                            ),
 824                    ),
 825            )
 826    }
 827
 828    fn render_remote_extension_context_menu(
 829        this: &Entity<Self>,
 830        extension_id: Arc<str>,
 831        authors: Vec<String>,
 832        window: &mut Window,
 833        cx: &mut App,
 834    ) -> Entity<ContextMenu> {
 835        let context_menu = ContextMenu::build(window, cx, |context_menu, window, _| {
 836            context_menu
 837                .entry(
 838                    "Install Another Version...",
 839                    None,
 840                    window.handler_for(this, {
 841                        let extension_id = extension_id.clone();
 842                        move |this, window, cx| {
 843                            this.show_extension_version_list(extension_id.clone(), window, cx)
 844                        }
 845                    }),
 846                )
 847                .entry("Copy Extension ID", None, {
 848                    let extension_id = extension_id.clone();
 849                    move |_, cx| {
 850                        cx.write_to_clipboard(ClipboardItem::new_string(extension_id.to_string()));
 851                    }
 852                })
 853                .entry("Copy Author Info", None, {
 854                    let authors = authors.clone();
 855                    move |_, cx| {
 856                        cx.write_to_clipboard(ClipboardItem::new_string(authors.join(", ")));
 857                    }
 858                })
 859        });
 860
 861        context_menu
 862    }
 863
 864    fn show_extension_version_list(
 865        &mut self,
 866        extension_id: Arc<str>,
 867        window: &mut Window,
 868        cx: &mut Context<Self>,
 869    ) {
 870        let Some(workspace) = self.workspace.upgrade() else {
 871            return;
 872        };
 873
 874        cx.spawn_in(window, async move |this, cx| {
 875            let extension_versions_task = this.update(cx, |_, cx| {
 876                let extension_store = ExtensionStore::global(cx);
 877
 878                extension_store.update(cx, |store, cx| {
 879                    store.fetch_extension_versions(&extension_id, cx)
 880                })
 881            })?;
 882
 883            let extension_versions = extension_versions_task.await?;
 884
 885            workspace.update_in(cx, |workspace, window, cx| {
 886                let fs = workspace.project().read(cx).fs().clone();
 887                workspace.toggle_modal(window, cx, |window, cx| {
 888                    let delegate = ExtensionVersionSelectorDelegate::new(
 889                        fs,
 890                        cx.entity().downgrade(),
 891                        extension_versions,
 892                    );
 893
 894                    ExtensionVersionSelector::new(delegate, window, cx)
 895                });
 896            })?;
 897
 898            anyhow::Ok(())
 899        })
 900        .detach_and_log_err(cx);
 901    }
 902
 903    fn buttons_for_entry(
 904        &self,
 905        extension: &ExtensionMetadata,
 906        status: &ExtensionStatus,
 907        has_dev_extension: bool,
 908        cx: &mut Context<Self>,
 909    ) -> ExtensionCardButtons {
 910        let is_compatible =
 911            extension_host::is_version_compatible(ReleaseChannel::global(cx), extension);
 912
 913        if has_dev_extension {
 914            // If we have a dev extension for the given extension, just treat it as uninstalled.
 915            // The button here is a placeholder, as it won't be interactable anyways.
 916            return ExtensionCardButtons {
 917                install_or_uninstall: Button::new(
 918                    SharedString::from(extension.id.clone()),
 919                    "Install",
 920                ),
 921                configure: None,
 922                upgrade: None,
 923            };
 924        }
 925
 926        let is_configurable = extension
 927            .manifest
 928            .provides
 929            .contains(&ExtensionProvides::ContextServers);
 930
 931        match status.clone() {
 932            ExtensionStatus::NotInstalled => ExtensionCardButtons {
 933                install_or_uninstall: Button::new(
 934                    SharedString::from(extension.id.clone()),
 935                    "Install",
 936                )
 937                .on_click({
 938                    let extension_id = extension.id.clone();
 939                    move |_, _, cx| {
 940                        telemetry::event!("Extension Installed");
 941                        ExtensionStore::global(cx).update(cx, |store, cx| {
 942                            store.install_latest_extension(extension_id.clone(), cx)
 943                        });
 944                    }
 945                }),
 946                configure: None,
 947                upgrade: None,
 948            },
 949            ExtensionStatus::Installing => ExtensionCardButtons {
 950                install_or_uninstall: Button::new(
 951                    SharedString::from(extension.id.clone()),
 952                    "Install",
 953                )
 954                .disabled(true),
 955                configure: None,
 956                upgrade: None,
 957            },
 958            ExtensionStatus::Upgrading => ExtensionCardButtons {
 959                install_or_uninstall: Button::new(
 960                    SharedString::from(extension.id.clone()),
 961                    "Uninstall",
 962                )
 963                .disabled(true),
 964                configure: is_configurable.then(|| {
 965                    Button::new(
 966                        SharedString::from(format!("configure-{}", extension.id)),
 967                        "Configure",
 968                    )
 969                    .disabled(true)
 970                }),
 971                upgrade: Some(
 972                    Button::new(SharedString::from(extension.id.clone()), "Upgrade").disabled(true),
 973                ),
 974            },
 975            ExtensionStatus::Installed(installed_version) => ExtensionCardButtons {
 976                install_or_uninstall: Button::new(
 977                    SharedString::from(extension.id.clone()),
 978                    "Uninstall",
 979                )
 980                .on_click({
 981                    let extension_id = extension.id.clone();
 982                    move |_, _, cx| {
 983                        telemetry::event!("Extension Uninstalled", extension_id);
 984                        ExtensionStore::global(cx).update(cx, |store, cx| {
 985                            store.uninstall_extension(extension_id.clone(), cx)
 986                        });
 987                    }
 988                }),
 989                configure: is_configurable.then(|| {
 990                    Button::new(
 991                        SharedString::from(format!("configure-{}", extension.id)),
 992                        "Configure",
 993                    )
 994                    .on_click({
 995                        let extension_id = extension.id.clone();
 996                        move |_, _, cx| {
 997                            if let Some(manifest) = ExtensionStore::global(cx)
 998                                .read(cx)
 999                                .extension_manifest_for_id(&extension_id)
1000                                .cloned()
1001                            {
1002                                if let Some(events) = extension::ExtensionEvents::try_global(cx) {
1003                                    events.update(cx, |this, cx| {
1004                                        this.emit(
1005                                            extension::Event::ConfigureExtensionRequested(manifest),
1006                                            cx,
1007                                        )
1008                                    });
1009                                }
1010                            }
1011                        }
1012                    })
1013                }),
1014                upgrade: if installed_version == extension.manifest.version {
1015                    None
1016                } else {
1017                    Some(
1018                        Button::new(SharedString::from(extension.id.clone()), "Upgrade")
1019                            .when(!is_compatible, |upgrade_button| {
1020                                upgrade_button.disabled(true).tooltip({
1021                                    let version = extension.manifest.version.clone();
1022                                    move |_, cx| {
1023                                        Tooltip::simple(
1024                                            format!(
1025                                                "v{version} is not compatible with this version of Zed.",
1026                                            ),
1027                                             cx,
1028                                        )
1029                                    }
1030                                })
1031                            })
1032                            .disabled(!is_compatible)
1033                            .on_click({
1034                                let extension_id = extension.id.clone();
1035                                let version = extension.manifest.version.clone();
1036                                move |_, _, cx| {
1037                                    telemetry::event!("Extension Installed", extension_id, version);
1038                                    ExtensionStore::global(cx).update(cx, |store, cx| {
1039                                        store
1040                                            .upgrade_extension(
1041                                                extension_id.clone(),
1042                                                version.clone(),
1043                                                cx,
1044                                            )
1045                                            .detach_and_log_err(cx)
1046                                    });
1047                                }
1048                            }),
1049                    )
1050                },
1051            },
1052            ExtensionStatus::Removing => ExtensionCardButtons {
1053                install_or_uninstall: Button::new(
1054                    SharedString::from(extension.id.clone()),
1055                    "Uninstall",
1056                )
1057                .disabled(true),
1058                configure: is_configurable.then(|| {
1059                    Button::new(
1060                        SharedString::from(format!("configure-{}", extension.id)),
1061                        "Configure",
1062                    )
1063                    .disabled(true)
1064                }),
1065                upgrade: None,
1066            },
1067        }
1068    }
1069
1070    fn render_search(&self, cx: &mut Context<Self>) -> Div {
1071        let mut key_context = KeyContext::new_with_defaults();
1072        key_context.add("BufferSearchBar");
1073
1074        let editor_border = if self.query_contains_error {
1075            Color::Error.color(cx)
1076        } else {
1077            cx.theme().colors().border
1078        };
1079
1080        h_flex()
1081            .key_context(key_context)
1082            .h_8()
1083            .flex_1()
1084            .min_w(rems_from_px(384.))
1085            .pl_1p5()
1086            .pr_2()
1087            .py_1()
1088            .gap_2()
1089            .border_1()
1090            .border_color(editor_border)
1091            .rounded_lg()
1092            .child(Icon::new(IconName::MagnifyingGlass).color(Color::Muted))
1093            .child(self.render_text_input(&self.query_editor, cx))
1094    }
1095
1096    fn render_text_input(
1097        &self,
1098        editor: &Entity<Editor>,
1099        cx: &mut Context<Self>,
1100    ) -> impl IntoElement {
1101        let settings = ThemeSettings::get_global(cx);
1102        let text_style = TextStyle {
1103            color: if editor.read(cx).read_only(cx) {
1104                cx.theme().colors().text_disabled
1105            } else {
1106                cx.theme().colors().text
1107            },
1108            font_family: settings.ui_font.family.clone(),
1109            font_features: settings.ui_font.features.clone(),
1110            font_fallbacks: settings.ui_font.fallbacks.clone(),
1111            font_size: rems(0.875).into(),
1112            font_weight: settings.ui_font.weight,
1113            line_height: relative(1.3),
1114            ..Default::default()
1115        };
1116
1117        EditorElement::new(
1118            editor,
1119            EditorStyle {
1120                background: cx.theme().colors().editor_background,
1121                local_player: cx.theme().players().local(),
1122                text: text_style,
1123                ..Default::default()
1124            },
1125        )
1126    }
1127
1128    fn on_query_change(
1129        &mut self,
1130        _: Entity<Editor>,
1131        event: &editor::EditorEvent,
1132        cx: &mut Context<Self>,
1133    ) {
1134        if let editor::EditorEvent::Edited { .. } = event {
1135            self.query_contains_error = false;
1136            self.refresh_search(cx);
1137        }
1138    }
1139
1140    fn refresh_search(&mut self, cx: &mut Context<Self>) {
1141        self.fetch_extensions_debounced(
1142            Some(Box::new(|this, cx| {
1143                this.scroll_to_top(cx);
1144            })),
1145            cx,
1146        );
1147        self.refresh_feature_upsells(cx);
1148    }
1149
1150    pub fn change_provides_filter(
1151        &mut self,
1152        provides_filter: Option<ExtensionProvides>,
1153        cx: &mut Context<Self>,
1154    ) {
1155        self.provides_filter = provides_filter;
1156        self.refresh_search(cx);
1157    }
1158
1159    fn fetch_extensions_debounced(
1160        &mut self,
1161        on_complete: Option<Box<dyn FnOnce(&mut Self, &mut Context<Self>) + Send>>,
1162        cx: &mut Context<ExtensionsPage>,
1163    ) {
1164        self.extension_fetch_task = Some(cx.spawn(async move |this, cx| {
1165            let search = this
1166                .update(cx, |this, cx| this.search_query(cx))
1167                .ok()
1168                .flatten();
1169
1170            // Only debounce the fetching of extensions if we have a search
1171            // query.
1172            //
1173            // If the search was just cleared then we can just reload the list
1174            // of extensions without a debounce, which allows us to avoid seeing
1175            // an intermittent flash of a "no extensions" state.
1176            if search.is_some() {
1177                cx.background_executor()
1178                    .timer(Duration::from_millis(250))
1179                    .await;
1180            };
1181
1182            this.update(cx, |this, cx| {
1183                this.fetch_extensions(
1184                    search,
1185                    Some(BTreeSet::from_iter(this.provides_filter)),
1186                    on_complete,
1187                    cx,
1188                );
1189            })
1190            .ok();
1191        }));
1192    }
1193
1194    pub fn search_query(&self, cx: &mut App) -> Option<String> {
1195        let search = self.query_editor.read(cx).text(cx);
1196        if search.trim().is_empty() {
1197            None
1198        } else {
1199            Some(search)
1200        }
1201    }
1202
1203    fn render_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {
1204        let has_search = self.search_query(cx).is_some();
1205
1206        let message = if self.is_fetching_extensions {
1207            "Loading extensions..."
1208        } else {
1209            match self.filter {
1210                ExtensionFilter::All => {
1211                    if has_search {
1212                        "No extensions that match your search."
1213                    } else {
1214                        "No extensions."
1215                    }
1216                }
1217                ExtensionFilter::Installed => {
1218                    if has_search {
1219                        "No installed extensions that match your search."
1220                    } else {
1221                        "No installed extensions."
1222                    }
1223                }
1224                ExtensionFilter::NotInstalled => {
1225                    if has_search {
1226                        "No not installed extensions that match your search."
1227                    } else {
1228                        "No not installed extensions."
1229                    }
1230                }
1231            }
1232        };
1233
1234        Label::new(message)
1235    }
1236
1237    fn update_settings<T: Settings>(
1238        &mut self,
1239        selection: &ToggleState,
1240
1241        cx: &mut Context<Self>,
1242        callback: impl 'static + Send + Fn(&mut T::FileContent, bool),
1243    ) {
1244        if let Some(workspace) = self.workspace.upgrade() {
1245            let fs = workspace.read(cx).app_state().fs.clone();
1246            let selection = *selection;
1247            settings::update_settings_file::<T>(fs, cx, move |settings, _| {
1248                let value = match selection {
1249                    ToggleState::Unselected => false,
1250                    ToggleState::Selected => true,
1251                    _ => return,
1252                };
1253
1254                callback(settings, value)
1255            });
1256        }
1257    }
1258
1259    fn refresh_feature_upsells(&mut self, cx: &mut Context<Self>) {
1260        let Some(search) = self.search_query(cx) else {
1261            self.upsells.clear();
1262            return;
1263        };
1264
1265        let search = search.to_lowercase();
1266        let search_terms = search
1267            .split_whitespace()
1268            .map(|term| term.trim())
1269            .collect::<Vec<_>>();
1270
1271        for (feature, keywords) in keywords_by_feature() {
1272            if keywords
1273                .iter()
1274                .any(|keyword| search_terms.contains(keyword))
1275            {
1276                self.upsells.insert(*feature);
1277            } else {
1278                self.upsells.remove(feature);
1279            }
1280        }
1281    }
1282
1283    fn render_feature_upsells(&self, cx: &mut Context<Self>) -> impl IntoElement {
1284        let upsells_count = self.upsells.len();
1285
1286        v_flex().children(self.upsells.iter().enumerate().map(|(ix, feature)| {
1287            let upsell = match feature {
1288                Feature::Git => FeatureUpsell::new(
1289                    "Zed comes with basic Git support. More Git features are coming in the future.",
1290                )
1291                .docs_url("https://zed.dev/docs/git"),
1292                Feature::OpenIn => FeatureUpsell::new(
1293                    "Zed supports linking to a source line on GitHub and others.",
1294                )
1295                .docs_url("https://zed.dev/docs/git#git-integrations"),
1296                Feature::Vim => FeatureUpsell::new("Vim support is built-in to Zed!")
1297                    .docs_url("https://zed.dev/docs/vim")
1298                    .child(CheckboxWithLabel::new(
1299                        "enable-vim",
1300                        Label::new("Enable vim mode"),
1301                        if VimModeSetting::get_global(cx).0 {
1302                            ui::ToggleState::Selected
1303                        } else {
1304                            ui::ToggleState::Unselected
1305                        },
1306                        cx.listener(move |this, selection, _, cx| {
1307                            telemetry::event!("Vim Mode Toggled", source = "Feature Upsell");
1308                            this.update_settings::<VimModeSetting>(
1309                                selection,
1310                                cx,
1311                                |setting, value| *setting = Some(value),
1312                            );
1313                        }),
1314                    )),
1315                Feature::LanguageBash => FeatureUpsell::new("Shell support is built-in to Zed!")
1316                    .docs_url("https://zed.dev/docs/languages/bash"),
1317                Feature::LanguageC => FeatureUpsell::new("C support is built-in to Zed!")
1318                    .docs_url("https://zed.dev/docs/languages/c"),
1319                Feature::LanguageCpp => FeatureUpsell::new("C++ support is built-in to Zed!")
1320                    .docs_url("https://zed.dev/docs/languages/cpp"),
1321                Feature::LanguageGo => FeatureUpsell::new("Go support is built-in to Zed!")
1322                    .docs_url("https://zed.dev/docs/languages/go"),
1323                Feature::LanguagePython => FeatureUpsell::new("Python support is built-in to Zed!")
1324                    .docs_url("https://zed.dev/docs/languages/python"),
1325                Feature::LanguageReact => FeatureUpsell::new("React support is built-in to Zed!")
1326                    .docs_url("https://zed.dev/docs/languages/typescript"),
1327                Feature::LanguageRust => FeatureUpsell::new("Rust support is built-in to Zed!")
1328                    .docs_url("https://zed.dev/docs/languages/rust"),
1329                Feature::LanguageTypescript => {
1330                    FeatureUpsell::new("Typescript support is built-in to Zed!")
1331                        .docs_url("https://zed.dev/docs/languages/typescript")
1332                }
1333            };
1334
1335            upsell.when(ix < upsells_count, |upsell| upsell.border_b_1())
1336        }))
1337    }
1338}
1339
1340impl Render for ExtensionsPage {
1341    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1342        v_flex()
1343            .size_full()
1344            .bg(cx.theme().colors().editor_background)
1345            .child(
1346                v_flex()
1347                    .gap_4()
1348                    .pt_4()
1349                    .px_4()
1350                    .bg(cx.theme().colors().editor_background)
1351                    .child(
1352                        h_flex()
1353                            .w_full()
1354                            .gap_2()
1355                            .justify_between()
1356                            .child(Headline::new("Extensions").size(HeadlineSize::XLarge))
1357                            .child(
1358                                Button::new("install-dev-extension", "Install Dev Extension")
1359                                    .style(ButtonStyle::Filled)
1360                                    .size(ButtonSize::Large)
1361                                    .on_click(|_event, window, cx| {
1362                                        window.dispatch_action(Box::new(InstallDevExtension), cx)
1363                                    }),
1364                            ),
1365                    )
1366                    .child(
1367                        h_flex()
1368                            .w_full()
1369                            .gap_4()
1370                            .flex_wrap()
1371                            .child(self.render_search(cx))
1372                            .child(
1373                                h_flex()
1374                                    .child(
1375                                        ToggleButton::new("filter-all", "All")
1376                                            .style(ButtonStyle::Filled)
1377                                            .size(ButtonSize::Large)
1378                                            .toggle_state(self.filter == ExtensionFilter::All)
1379                                            .on_click(cx.listener(|this, _event, _, cx| {
1380                                                this.filter = ExtensionFilter::All;
1381                                                this.filter_extension_entries(cx);
1382                                                this.scroll_to_top(cx);
1383                                            }))
1384                                            .tooltip(move |_, cx| {
1385                                                Tooltip::simple("Show all extensions", cx)
1386                                            })
1387                                            .first(),
1388                                    )
1389                                    .child(
1390                                        ToggleButton::new("filter-installed", "Installed")
1391                                            .style(ButtonStyle::Filled)
1392                                            .size(ButtonSize::Large)
1393                                            .toggle_state(self.filter == ExtensionFilter::Installed)
1394                                            .on_click(cx.listener(|this, _event, _, cx| {
1395                                                this.filter = ExtensionFilter::Installed;
1396                                                this.filter_extension_entries(cx);
1397                                                this.scroll_to_top(cx);
1398                                            }))
1399                                            .tooltip(move |_, cx| {
1400                                                Tooltip::simple("Show installed extensions", cx)
1401                                            })
1402                                            .middle(),
1403                                    )
1404                                    .child(
1405                                        ToggleButton::new("filter-not-installed", "Not Installed")
1406                                            .style(ButtonStyle::Filled)
1407                                            .size(ButtonSize::Large)
1408                                            .toggle_state(
1409                                                self.filter == ExtensionFilter::NotInstalled,
1410                                            )
1411                                            .on_click(cx.listener(|this, _event, _, cx| {
1412                                                this.filter = ExtensionFilter::NotInstalled;
1413                                                this.filter_extension_entries(cx);
1414                                                this.scroll_to_top(cx);
1415                                            }))
1416                                            .tooltip(move |_, cx| {
1417                                                Tooltip::simple("Show not installed extensions", cx)
1418                                            })
1419                                            .last(),
1420                                    ),
1421                            ),
1422                    ),
1423            )
1424            .child(
1425                h_flex()
1426                    .id("filter-row")
1427                    .gap_2()
1428                    .py_2p5()
1429                    .px_4()
1430                    .border_b_1()
1431                    .border_color(cx.theme().colors().border_variant)
1432                    .overflow_x_scroll()
1433                    .child(
1434                        Button::new("filter-all-categories", "All")
1435                            .when(self.provides_filter.is_none(), |button| {
1436                                button.style(ButtonStyle::Filled)
1437                            })
1438                            .when(self.provides_filter.is_some(), |button| {
1439                                button.style(ButtonStyle::Subtle)
1440                            })
1441                            .toggle_state(self.provides_filter.is_none())
1442                            .on_click(cx.listener(|this, _event, _, cx| {
1443                                this.change_provides_filter(None, cx);
1444                            })),
1445                    )
1446                    .children(ExtensionProvides::iter().map(|provides| {
1447                        let label = extension_provides_label(provides);
1448                        Button::new(
1449                            SharedString::from(format!("filter-category-{}", label)),
1450                            label,
1451                        )
1452                        .style(if self.provides_filter == Some(provides) {
1453                            ButtonStyle::Filled
1454                        } else {
1455                            ButtonStyle::Subtle
1456                        })
1457                        .toggle_state(self.provides_filter == Some(provides))
1458                        .on_click({
1459                            cx.listener(move |this, _event, _, cx| {
1460                                this.change_provides_filter(Some(provides), cx);
1461                            })
1462                        })
1463                    })),
1464            )
1465            .child(self.render_feature_upsells(cx))
1466            .child(
1467                v_flex()
1468                    .pl_4()
1469                    .pr_6()
1470                    .size_full()
1471                    .overflow_y_hidden()
1472                    .map(|this| {
1473                        let mut count = self.filtered_remote_extension_indices.len();
1474                        if self.filter.include_dev_extensions() {
1475                            count += self.dev_extension_entries.len();
1476                        }
1477
1478                        if count == 0 {
1479                            return this.py_4().child(self.render_empty_state(cx));
1480                        }
1481
1482                        let extensions_page = cx.entity().clone();
1483                        let scroll_handle = self.list.clone();
1484                        this.child(
1485                            uniform_list(
1486                                extensions_page,
1487                                "entries",
1488                                count,
1489                                Self::render_extensions,
1490                            )
1491                            .flex_grow()
1492                            .pb_4()
1493                            .track_scroll(scroll_handle),
1494                        )
1495                        .child(
1496                            div()
1497                                .absolute()
1498                                .right_1()
1499                                .top_0()
1500                                .bottom_0()
1501                                .w(px(12.))
1502                                .children(Scrollbar::vertical(self.scrollbar_state.clone())),
1503                        )
1504                    }),
1505            )
1506    }
1507}
1508
1509impl EventEmitter<ItemEvent> for ExtensionsPage {}
1510
1511impl Focusable for ExtensionsPage {
1512    fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
1513        self.query_editor.read(cx).focus_handle(cx)
1514    }
1515}
1516
1517impl Item for ExtensionsPage {
1518    type Event = ItemEvent;
1519
1520    fn tab_content_text(&self, _detail: usize, _cx: &App) -> SharedString {
1521        "Extensions".into()
1522    }
1523
1524    fn telemetry_event_text(&self) -> Option<&'static str> {
1525        Some("Extensions Page Opened")
1526    }
1527
1528    fn show_toolbar(&self) -> bool {
1529        false
1530    }
1531
1532    fn clone_on_split(
1533        &self,
1534        _workspace_id: Option<WorkspaceId>,
1535        _window: &mut Window,
1536        _: &mut Context<Self>,
1537    ) -> Option<Entity<Self>> {
1538        None
1539    }
1540
1541    fn to_item_events(event: &Self::Event, mut f: impl FnMut(workspace::item::ItemEvent)) {
1542        f(*event)
1543    }
1544}