mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 21:40:41 +01:00
extensions_ui: Show installed extensions when offline (#64766)
Closes #12163 Supersedes https://github.com/zed-industries/zed/pull/56941 This PR changes the way we show installed extensions when offline - instead of basing it on the remote extensions list, we now compute a "displayed_extensions" list based on the local state and use that as the source of truth. This enables us to fix the issues listed below, as we are no longer depending on the remote info, but instead use what we have at our hands as the source of truth in cases where the server response is either not available or incomplete (we truncate currently and will add pagination at some point, so this is nice to have in either case). Release Notes: - Installed extensions will now also show in the extensions tab when offline. - Fixed a bug where some extensions would not show in the "Installed" tab despite being installed.
This commit is contained in:
@@ -197,6 +197,15 @@ pub enum ExtensionOperation {
|
||||
Remove,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum ExtensionStatus {
|
||||
NotInstalled,
|
||||
Installing,
|
||||
Upgrading,
|
||||
Installed(Arc<str>),
|
||||
Removing,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Event {
|
||||
ExtensionsUpdated,
|
||||
@@ -560,6 +569,27 @@ impl ExtensionStore {
|
||||
&self.extension_index.extensions
|
||||
}
|
||||
|
||||
/// Returns the status of the extension, where outstanding operations take
|
||||
/// precedence over the installed state.
|
||||
pub fn extension_status(&self, extension_id: &str) -> ExtensionStatus {
|
||||
match self.outstanding_operations.get(extension_id) {
|
||||
Some(ExtensionOperation::Install) => ExtensionStatus::Installing,
|
||||
Some(ExtensionOperation::Remove) => ExtensionStatus::Removing,
|
||||
Some(ExtensionOperation::Upgrade) => ExtensionStatus::Upgrading,
|
||||
None => match self.extension_index.extensions.get(extension_id) {
|
||||
Some(extension) => ExtensionStatus::Installed(extension.manifest.version.clone()),
|
||||
None => ExtensionStatus::NotInstalled,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_dev_extension(&self, extension_id: &str) -> bool {
|
||||
self.extension_index
|
||||
.extensions
|
||||
.get(extension_id)
|
||||
.is_some_and(|extension| extension.dev)
|
||||
}
|
||||
|
||||
pub fn dev_extensions(&self) -> impl Iterator<Item = &Arc<ExtensionManifest>> {
|
||||
self.extension_index
|
||||
.extensions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
mod extension_card;
|
||||
|
||||
pub use extension_card::ExtensionCard;
|
||||
pub(crate) use extension_card::{extension_provides_label, remote_extension_status};
|
||||
pub(crate) use extension_card::extension_provides_label;
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{collections::BTreeSet, sync::Arc};
|
||||
|
||||
use cloud_api_types::{ExtensionApiManifest, ExtensionMetadata, ExtensionProvides};
|
||||
use extension::{ExtensionManifest, SchemaVersion};
|
||||
use extension_host::{ExtensionOperation, ExtensionStore};
|
||||
use extension_host::{ExtensionOperation, ExtensionStatus, ExtensionStore};
|
||||
use gpui::{Anchor, ElementId, Entity, Point, SharedString, prelude::*};
|
||||
use num_format::{Locale, ToFormattedString};
|
||||
use release_channel::ReleaseChannel;
|
||||
@@ -13,52 +13,31 @@ type ContextMenuBuilder = Box<
|
||||
>;
|
||||
type ExtensionCardActions = [Option<Button>; 3];
|
||||
|
||||
fn extension_status(extension_id: &str, extension_store: &ExtensionStore) -> ExtensionStatus {
|
||||
match extension_store.outstanding_operations().get(extension_id) {
|
||||
Some(ExtensionOperation::Install) => ExtensionStatus::Installing,
|
||||
Some(ExtensionOperation::Remove) => ExtensionStatus::Removing,
|
||||
Some(ExtensionOperation::Upgrade) => ExtensionStatus::Upgrading,
|
||||
None => match extension_store.installed_extensions().get(extension_id) {
|
||||
Some(extension) => ExtensionStatus::Installed(extension.manifest.version.clone()),
|
||||
None => ExtensionStatus::NotInstalled,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn remote_extension_status(extension_id: &str, cx: &App) -> ExtensionStatus {
|
||||
let extension_store = ExtensionStore::global(cx).read(cx);
|
||||
if extension_store
|
||||
.installed_extensions()
|
||||
.get(extension_id)
|
||||
.is_some_and(|extension| extension.dev)
|
||||
{
|
||||
ExtensionStatus::OverriddenByDevExtension
|
||||
} else {
|
||||
extension_status(extension_id, extension_store)
|
||||
}
|
||||
}
|
||||
|
||||
/// Local state of a published extension, derived from the `ExtensionStore`.
|
||||
#[derive(Clone)]
|
||||
pub(crate) enum ExtensionStatus {
|
||||
NotInstalled,
|
||||
Installing,
|
||||
Upgrading,
|
||||
Installed(Arc<str>),
|
||||
Removing,
|
||||
enum PublishedExtensionState {
|
||||
/// A dev extension with the same id is installed locally and takes
|
||||
/// precedence, so the published version can't be installed or managed.
|
||||
/// This replaces the store status, which would describe the dev extension.
|
||||
OverriddenByDevExtension,
|
||||
/// Managed by the store like any other extension.
|
||||
Store(ExtensionStatus),
|
||||
}
|
||||
|
||||
impl ExtensionStatus {
|
||||
pub fn disables_actions(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Installing | Self::Upgrading | Self::Removing | Self::OverriddenByDevExtension
|
||||
)
|
||||
impl PublishedExtensionState {
|
||||
fn new(extension_id: &str, extension_store: &ExtensionStore) -> Self {
|
||||
if extension_store.is_dev_extension(extension_id) {
|
||||
Self::OverriddenByDevExtension
|
||||
} else {
|
||||
Self::Store(extension_store.extension_status(extension_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_installed(&self) -> bool {
|
||||
matches!(self, Self::Installed(_) | Self::Upgrading | Self::Removing)
|
||||
}
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum LocalExtensionKind {
|
||||
Dev,
|
||||
Installed,
|
||||
}
|
||||
|
||||
struct ExtensionCardDetails {
|
||||
@@ -76,8 +55,9 @@ struct ExtensionCardDetails {
|
||||
#[derive(Clone)]
|
||||
enum ExtensionCardSource {
|
||||
Dev,
|
||||
Installed,
|
||||
Remote {
|
||||
status: ExtensionStatus,
|
||||
state: PublishedExtensionState,
|
||||
download_count: u64,
|
||||
},
|
||||
}
|
||||
@@ -86,7 +66,7 @@ impl ExtensionCardSource {
|
||||
fn installed_version(&self, latest_version: &Arc<str>) -> Option<Arc<str>> {
|
||||
match self {
|
||||
Self::Remote {
|
||||
status: ExtensionStatus::Installed(installed_version),
|
||||
state: PublishedExtensionState::Store(ExtensionStatus::Installed(installed_version)),
|
||||
..
|
||||
} if installed_version != latest_version => Some(installed_version.clone()),
|
||||
_ => None,
|
||||
@@ -96,7 +76,7 @@ impl ExtensionCardSource {
|
||||
fn download_count(&self) -> Option<u64> {
|
||||
match self {
|
||||
Self::Remote { download_count, .. } => Some(*download_count),
|
||||
Self::Dev => None,
|
||||
Self::Dev | Self::Installed => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +88,7 @@ impl ExtensionCardSource {
|
||||
matches!(
|
||||
self,
|
||||
Self::Remote {
|
||||
status: ExtensionStatus::OverriddenByDevExtension,
|
||||
state: PublishedExtensionState::OverriddenByDevExtension,
|
||||
..
|
||||
}
|
||||
)
|
||||
@@ -123,22 +103,34 @@ pub struct ExtensionCard {
|
||||
}
|
||||
|
||||
impl ExtensionCard {
|
||||
pub fn for_dev(extension: Arc<ExtensionManifest>, cx: &App) -> Self {
|
||||
let extension_store = ExtensionStore::global(cx).read(cx);
|
||||
let status = extension_status(&extension.id, extension_store);
|
||||
Self::dev::<true>(extension, status)
|
||||
pub fn for_dev(extension: Arc<ExtensionManifest>, extension_store: &ExtensionStore) -> Self {
|
||||
let status = extension_store.extension_status(&extension.id);
|
||||
Self::manifest(extension, status, LocalExtensionKind::Dev)
|
||||
}
|
||||
|
||||
pub fn for_remote(extension: &ExtensionMetadata, cx: &App) -> Self {
|
||||
let status = remote_extension_status(&extension.id, cx);
|
||||
Self::remote::<true>(extension, status, cx)
|
||||
pub fn for_installed(
|
||||
extension: Arc<ExtensionManifest>,
|
||||
extension_store: &ExtensionStore,
|
||||
) -> Self {
|
||||
let status = extension_store.extension_status(&extension.id);
|
||||
Self::manifest(extension, status, LocalExtensionKind::Installed)
|
||||
}
|
||||
|
||||
fn dev<const ENABLE_HANDLERS: bool>(
|
||||
pub fn for_remote(
|
||||
extension: &ExtensionMetadata,
|
||||
extension_store: &ExtensionStore,
|
||||
cx: &App,
|
||||
) -> Self {
|
||||
let state = PublishedExtensionState::new(&extension.id, extension_store);
|
||||
Self::remote(extension, state, cx)
|
||||
}
|
||||
|
||||
fn manifest(
|
||||
extension: Arc<ExtensionManifest>,
|
||||
status: ExtensionStatus,
|
||||
kind: LocalExtensionKind,
|
||||
) -> Self {
|
||||
let actions = Self::actions_for_dev_extension::<ENABLE_HANDLERS>(&extension, &status);
|
||||
let actions = Self::actions_for_manifest_extension(&extension, &status, kind);
|
||||
let details = ExtensionCardDetails {
|
||||
id: extension.id.clone(),
|
||||
name: extension.name.clone().into(),
|
||||
@@ -148,7 +140,10 @@ impl ExtensionCard {
|
||||
repository_url: extension.repository.clone().map(Into::into),
|
||||
repository_icon: IconName::Link,
|
||||
provided_features: provided_feature_labels(extension.provides()),
|
||||
source: ExtensionCardSource::Dev,
|
||||
source: match kind {
|
||||
LocalExtensionKind::Dev => ExtensionCardSource::Dev,
|
||||
LocalExtensionKind::Installed => ExtensionCardSource::Installed,
|
||||
},
|
||||
};
|
||||
|
||||
Self {
|
||||
@@ -158,12 +153,8 @@ impl ExtensionCard {
|
||||
}
|
||||
}
|
||||
|
||||
fn remote<const ENABLE_HANDLERS: bool>(
|
||||
extension: &ExtensionMetadata,
|
||||
status: ExtensionStatus,
|
||||
cx: &App,
|
||||
) -> Self {
|
||||
let actions = Self::actions_for_remote_extension::<ENABLE_HANDLERS>(extension, &status, cx);
|
||||
fn remote(extension: &ExtensionMetadata, state: PublishedExtensionState, cx: &App) -> Self {
|
||||
let actions = Self::actions_for_remote_extension(extension, &state, cx);
|
||||
let details = ExtensionCardDetails {
|
||||
id: extension.id.clone(),
|
||||
name: extension.manifest.name.clone().into(),
|
||||
@@ -174,7 +165,7 @@ impl ExtensionCard {
|
||||
repository_icon: IconName::Link,
|
||||
provided_features: provided_feature_labels(extension.manifest.provides.iter().copied()),
|
||||
source: ExtensionCardSource::Remote {
|
||||
status,
|
||||
state,
|
||||
download_count: extension.download_count,
|
||||
},
|
||||
};
|
||||
@@ -186,36 +177,40 @@ impl ExtensionCard {
|
||||
}
|
||||
}
|
||||
|
||||
fn disables_actions(status: &ExtensionStatus) -> bool {
|
||||
match status {
|
||||
ExtensionStatus::Installing
|
||||
| ExtensionStatus::Upgrading
|
||||
| ExtensionStatus::Removing => true,
|
||||
ExtensionStatus::NotInstalled | ExtensionStatus::Installed(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn button_id(extension_id: &Arc<str>, operation: ExtensionOperation) -> ElementId {
|
||||
(SharedString::from(extension_id.clone()), operation as usize).into()
|
||||
}
|
||||
|
||||
fn uninstall_button<const ENABLE_HANDLERS: bool>(
|
||||
extension_id: &Arc<str>,
|
||||
is_dev: bool,
|
||||
) -> Button {
|
||||
fn uninstall_button(extension_id: &Arc<str>, is_dev: bool) -> Button {
|
||||
Button::new(
|
||||
Self::button_id(extension_id, ExtensionOperation::Remove),
|
||||
"Uninstall",
|
||||
)
|
||||
.when(ENABLE_HANDLERS, |button| {
|
||||
button.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
if !is_dev {
|
||||
telemetry::event!("Extension Uninstalled", extension_id);
|
||||
}
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store
|
||||
.uninstall_extension(extension_id.clone(), cx)
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
if !is_dev {
|
||||
telemetry::event!("Extension Uninstalled", extension_id);
|
||||
}
|
||||
})
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store
|
||||
.uninstall_extension(extension_id.clone(), cx)
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn configure_button<const ENABLE_HANDLERS: bool>(
|
||||
fn configure_button(
|
||||
extension_id: &Arc<str>,
|
||||
manifest: Option<Arc<ExtensionManifest>>,
|
||||
) -> Button {
|
||||
@@ -223,40 +218,40 @@ impl ExtensionCard {
|
||||
SharedString::from(format!("configure-{extension_id}")),
|
||||
"Configure",
|
||||
)
|
||||
.when(ENABLE_HANDLERS, |button| {
|
||||
button.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
let manifest = manifest.clone().or_else(|| {
|
||||
ExtensionStore::global(cx)
|
||||
.read(cx)
|
||||
.extension_manifest_for_id(&extension_id)
|
||||
.cloned()
|
||||
.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
let manifest = manifest.clone().or_else(|| {
|
||||
ExtensionStore::global(cx)
|
||||
.read(cx)
|
||||
.extension_manifest_for_id(&extension_id)
|
||||
.cloned()
|
||||
});
|
||||
if let Some(manifest) = manifest
|
||||
&& let Some(events) = extension::ExtensionEvents::try_global(cx)
|
||||
{
|
||||
events.update(cx, |this, cx| {
|
||||
this.emit(extension::Event::ConfigureExtensionRequested(manifest), cx)
|
||||
});
|
||||
if let Some(manifest) = manifest
|
||||
&& let Some(events) = extension::ExtensionEvents::try_global(cx)
|
||||
{
|
||||
events.update(cx, |this, cx| {
|
||||
this.emit(extension::Event::ConfigureExtensionRequested(manifest), cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn actions_for_dev_extension<const ENABLE_HANDLERS: bool>(
|
||||
fn actions_for_manifest_extension(
|
||||
extension: &Arc<ExtensionManifest>,
|
||||
status: &ExtensionStatus,
|
||||
kind: LocalExtensionKind,
|
||||
) -> ExtensionCardActions {
|
||||
let rebuild = Button::new(
|
||||
SharedString::from(format!("rebuild-{}", extension.id)),
|
||||
"Rebuild",
|
||||
)
|
||||
.color(Color::Accent)
|
||||
.disabled(status.disables_actions())
|
||||
.when(ENABLE_HANDLERS, |button| {
|
||||
button.on_click({
|
||||
let is_dev = kind == LocalExtensionKind::Dev;
|
||||
let rebuild = is_dev.then(|| {
|
||||
Button::new(
|
||||
SharedString::from(format!("rebuild-{}", extension.id)),
|
||||
"Rebuild",
|
||||
)
|
||||
.color(Color::Accent)
|
||||
.disabled(Self::disables_actions(status))
|
||||
.on_click({
|
||||
let extension_id = extension.id.clone();
|
||||
move |_, _, cx| {
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
@@ -265,19 +260,31 @@ impl ExtensionCard {
|
||||
}
|
||||
})
|
||||
});
|
||||
let uninstall = Self::uninstall_button::<ENABLE_HANDLERS>(&extension.id, true)
|
||||
.color(Color::Accent)
|
||||
.disabled(status.disables_actions());
|
||||
let uninstall = Self::uninstall_button(&extension.id, is_dev)
|
||||
.when_else(
|
||||
is_dev,
|
||||
|button| button.color(Color::Accent),
|
||||
|button| button.style(ButtonStyle::OutlinedGhost),
|
||||
)
|
||||
.disabled(Self::disables_actions(status));
|
||||
let configure = (!extension.context_servers.is_empty()).then(|| {
|
||||
Self::configure_button::<ENABLE_HANDLERS>(&extension.id, Some(extension.clone()))
|
||||
.color(Color::Accent)
|
||||
.disabled(status.disables_actions())
|
||||
Self::configure_button(&extension.id, Some(extension.clone()))
|
||||
.when_else(
|
||||
is_dev,
|
||||
|button| button.color(Color::Accent),
|
||||
|button| button.style(ButtonStyle::OutlinedGhost),
|
||||
)
|
||||
.disabled(Self::disables_actions(status))
|
||||
});
|
||||
|
||||
[Some(rebuild), Some(uninstall), configure]
|
||||
if is_dev {
|
||||
[rebuild, Some(uninstall), configure]
|
||||
} else {
|
||||
[None, configure, Some(uninstall)]
|
||||
}
|
||||
}
|
||||
|
||||
fn install_button<const ENABLE_HANDLERS: bool>(extension_id: &Arc<str>) -> Button {
|
||||
fn install_button(extension_id: &Arc<str>) -> Button {
|
||||
Button::new(
|
||||
Self::button_id(extension_id, ExtensionOperation::Install),
|
||||
"Install",
|
||||
@@ -288,22 +295,20 @@ impl ExtensionCard {
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Muted),
|
||||
)
|
||||
.when(ENABLE_HANDLERS, |button| {
|
||||
button.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
telemetry::event!("Extension Installed");
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store.install_latest_extension(extension_id.clone(), cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
.on_click({
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, _, cx| {
|
||||
telemetry::event!("Extension Installed");
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store.install_latest_extension(extension_id.clone(), cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn actions_for_remote_extension<const ENABLE_HANDLERS: bool>(
|
||||
fn actions_for_remote_extension(
|
||||
extension: &ExtensionMetadata,
|
||||
status: &ExtensionStatus,
|
||||
state: &PublishedExtensionState,
|
||||
cx: &App,
|
||||
) -> ExtensionCardActions {
|
||||
let is_configurable = extension
|
||||
@@ -311,38 +316,44 @@ impl ExtensionCard {
|
||||
.provides
|
||||
.contains(&ExtensionProvides::ContextServers);
|
||||
|
||||
let status = match state {
|
||||
PublishedExtensionState::OverriddenByDevExtension => {
|
||||
return [
|
||||
None,
|
||||
None,
|
||||
Some(Self::install_button(&extension.id).disabled(true)),
|
||||
];
|
||||
}
|
||||
PublishedExtensionState::Store(status) => status,
|
||||
};
|
||||
|
||||
match status {
|
||||
ExtensionStatus::OverriddenByDevExtension
|
||||
| ExtensionStatus::NotInstalled
|
||||
| ExtensionStatus::Installing => [
|
||||
ExtensionStatus::NotInstalled | ExtensionStatus::Installing => [
|
||||
None,
|
||||
None,
|
||||
Some(
|
||||
Self::install_button::<ENABLE_HANDLERS>(&extension.id)
|
||||
.disabled(status.disables_actions()),
|
||||
),
|
||||
Some(Self::install_button(&extension.id).disabled(Self::disables_actions(status))),
|
||||
],
|
||||
ExtensionStatus::Upgrading | ExtensionStatus::Removing => {
|
||||
let uninstall = Self::uninstall_button::<ENABLE_HANDLERS>(&extension.id, false)
|
||||
let uninstall = Self::uninstall_button(&extension.id, false)
|
||||
.style(ButtonStyle::OutlinedGhost)
|
||||
.disabled(status.disables_actions());
|
||||
.disabled(Self::disables_actions(status));
|
||||
let upgrade = matches!(status, ExtensionStatus::Upgrading).then(|| {
|
||||
Button::new(
|
||||
Self::button_id(&extension.id, ExtensionOperation::Upgrade),
|
||||
"Upgrade",
|
||||
)
|
||||
.disabled(status.disables_actions())
|
||||
.disabled(Self::disables_actions(status))
|
||||
});
|
||||
let configure = is_configurable.then(|| {
|
||||
Self::configure_button::<ENABLE_HANDLERS>(&extension.id, None)
|
||||
.disabled(status.disables_actions())
|
||||
Self::configure_button(&extension.id, None)
|
||||
.disabled(Self::disables_actions(status))
|
||||
});
|
||||
|
||||
[upgrade, configure, Some(uninstall)]
|
||||
}
|
||||
ExtensionStatus::Installed(installed_version) => {
|
||||
let uninstall = Self::uninstall_button::<ENABLE_HANDLERS>(&extension.id, false)
|
||||
.style(ButtonStyle::OutlinedGhost);
|
||||
let uninstall =
|
||||
Self::uninstall_button(&extension.id, false).style(ButtonStyle::OutlinedGhost);
|
||||
let upgrade = (installed_version != &extension.manifest.version).then(|| {
|
||||
let is_compatible = extension_host::is_version_compatible(
|
||||
ReleaseChannel::global(cx),
|
||||
@@ -367,28 +378,21 @@ impl ExtensionCard {
|
||||
})
|
||||
})
|
||||
.disabled(!is_compatible)
|
||||
.when(ENABLE_HANDLERS, |button| {
|
||||
button.on_click({
|
||||
let extension_id = extension.id.clone();
|
||||
let version = extension.manifest.version.clone();
|
||||
move |_, _, cx| {
|
||||
telemetry::event!("Extension Installed", extension_id, version);
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store
|
||||
.upgrade_extension(
|
||||
extension_id.clone(),
|
||||
version.clone(),
|
||||
cx,
|
||||
)
|
||||
.detach_and_log_err(cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
.on_click({
|
||||
let extension_id = extension.id.clone();
|
||||
let version = extension.manifest.version.clone();
|
||||
move |_, _, cx| {
|
||||
telemetry::event!("Extension Installed", extension_id, version);
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store
|
||||
.upgrade_extension(extension_id.clone(), version.clone(), cx)
|
||||
.detach_and_log_err(cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
let configure = is_configurable.then(|| {
|
||||
Self::configure_button::<ENABLE_HANDLERS>(&extension.id, None)
|
||||
.style(ButtonStyle::OutlinedGhost)
|
||||
Self::configure_button(&extension.id, None).style(ButtonStyle::OutlinedGhost)
|
||||
});
|
||||
|
||||
[upgrade, configure, Some(uninstall)]
|
||||
@@ -437,18 +441,6 @@ pub(crate) fn extension_provides_label(provides: ExtensionProvides) -> &'static
|
||||
}
|
||||
}
|
||||
|
||||
fn preview_dev_card(extension: Arc<ExtensionManifest>, status: ExtensionStatus) -> ExtensionCard {
|
||||
ExtensionCard::dev::<false>(extension, status)
|
||||
}
|
||||
|
||||
fn preview_remote_card(
|
||||
extension: &ExtensionMetadata,
|
||||
status: ExtensionStatus,
|
||||
cx: &App,
|
||||
) -> ExtensionCard {
|
||||
ExtensionCard::remote::<false>(extension, status, cx)
|
||||
}
|
||||
|
||||
impl Component for ExtensionCard {
|
||||
fn scope() -> ComponentScope {
|
||||
ComponentScope::DataDisplay
|
||||
@@ -486,7 +478,8 @@ impl Component for ExtensionCard {
|
||||
|
||||
fn dev_extension() -> Arc<ExtensionManifest> {
|
||||
Arc::new(ExtensionManifest {
|
||||
id: "preview-dev-theme".into(),
|
||||
// Fake ID which will never be accepted during publishing
|
||||
id: "zed-demo-theme".into(),
|
||||
name: "Local Theme".to_owned(),
|
||||
version: "0.1.0".into(),
|
||||
schema_version: SchemaVersion::ZERO,
|
||||
@@ -512,7 +505,7 @@ impl Component for ExtensionCard {
|
||||
let examples = vec![
|
||||
single_example(
|
||||
"Available to Install",
|
||||
preview_remote_card(
|
||||
ExtensionCard::remote(
|
||||
&remote_extension(
|
||||
"preview-toml",
|
||||
"TOML",
|
||||
@@ -521,14 +514,14 @@ impl Component for ExtensionCard {
|
||||
482_391,
|
||||
[ExtensionProvides::Languages],
|
||||
),
|
||||
ExtensionStatus::NotInstalled,
|
||||
PublishedExtensionState::Store(ExtensionStatus::NotInstalled),
|
||||
cx,
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Installed",
|
||||
preview_remote_card(
|
||||
ExtensionCard::remote(
|
||||
&remote_extension(
|
||||
"preview-python",
|
||||
"Python",
|
||||
@@ -541,14 +534,14 @@ impl Component for ExtensionCard {
|
||||
ExtensionProvides::ContextServers,
|
||||
],
|
||||
),
|
||||
ExtensionStatus::Installed("0.5.1".into()),
|
||||
PublishedExtensionState::Store(ExtensionStatus::Installed("0.5.1".into())),
|
||||
cx,
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Update Available",
|
||||
preview_remote_card(
|
||||
ExtensionCard::remote(
|
||||
&remote_extension(
|
||||
"preview-rust",
|
||||
"Rust",
|
||||
@@ -560,19 +553,23 @@ impl Component for ExtensionCard {
|
||||
ExtensionProvides::LanguageServers,
|
||||
],
|
||||
),
|
||||
ExtensionStatus::Installed("0.3.1".into()),
|
||||
PublishedExtensionState::Store(ExtensionStatus::Installed("0.3.1".into())),
|
||||
cx,
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Development Extension",
|
||||
preview_dev_card(dev_extension(), ExtensionStatus::Installed("0.1.0".into()))
|
||||
.into_any_element(),
|
||||
ExtensionCard::manifest(
|
||||
dev_extension(),
|
||||
ExtensionStatus::Installed("0.1.0".into()),
|
||||
LocalExtensionKind::Dev,
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Overridden by Development Extension",
|
||||
preview_remote_card(
|
||||
ExtensionCard::remote(
|
||||
&remote_extension(
|
||||
"preview-overridden-theme",
|
||||
"Local Theme",
|
||||
@@ -581,7 +578,7 @@ impl Component for ExtensionCard {
|
||||
36_512,
|
||||
[ExtensionProvides::Themes],
|
||||
),
|
||||
ExtensionStatus::OverriddenByDevExtension,
|
||||
PublishedExtensionState::OverriddenByDevExtension,
|
||||
cx,
|
||||
)
|
||||
.into_any_element(),
|
||||
|
||||
@@ -11,7 +11,7 @@ use cloud_api_types::{ExtensionMetadata, ExtensionProvides};
|
||||
use collections::{BTreeMap, BTreeSet};
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use editor::{Editor, EditorElement, EditorStyle};
|
||||
use extension_host::{ExtensionManifest, ExtensionStore};
|
||||
use extension_host::{ExtensionIndexEntry, ExtensionManifest, ExtensionStore};
|
||||
use fuzzy::{StringMatch, StringMatchCandidate, match_strings};
|
||||
use git::{GitHostingProviderRegistry, parse_git_remote_url};
|
||||
use gpui::{
|
||||
@@ -29,8 +29,8 @@ use settings::{Settings, SettingsContent};
|
||||
use strum::IntoEnumIterator as _;
|
||||
use theme_settings::ThemeSettings;
|
||||
use ui::{
|
||||
Banner, ContextMenu, Divider, ListItem, ListItemSpacing, ScrollableHandle, Switch,
|
||||
ToggleButtonGroup, ToggleButtonGroupSize, ToggleButtonGroupStyle, ToggleButtonSimple,
|
||||
Banner, CommonAnimationExt, ContextMenu, Divider, ListItem, ListItemSpacing, ScrollableHandle,
|
||||
Switch, ToggleButtonGroup, ToggleButtonGroupSize, ToggleButtonGroupStyle, ToggleButtonSimple,
|
||||
WithScrollbar, prelude::*,
|
||||
};
|
||||
use util::ResultExt;
|
||||
@@ -42,7 +42,7 @@ use workspace::{
|
||||
};
|
||||
use zed_actions::ExtensionCategoryFilter;
|
||||
|
||||
use crate::components::{ExtensionCard, extension_provides_label, remote_extension_status};
|
||||
use crate::components::{ExtensionCard, extension_provides_label};
|
||||
use crate::extension_version_selector::{
|
||||
ExtensionVersionSelector, ExtensionVersionSelectorDelegate,
|
||||
};
|
||||
@@ -293,15 +293,6 @@ enum ExtensionFilter {
|
||||
NotInstalled,
|
||||
}
|
||||
|
||||
impl ExtensionFilter {
|
||||
pub fn include_dev_extensions(&self) -> bool {
|
||||
match self {
|
||||
Self::All | Self::Installed => true,
|
||||
Self::NotInstalled => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
enum Feature {
|
||||
AgentClaude,
|
||||
@@ -371,22 +362,50 @@ fn keywords_by_feature() -> &'static BTreeMap<Feature, Vec<&'static str>> {
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum DisplayedExtension {
|
||||
/// Index into the installed search results. `remote_index` points to the
|
||||
/// extension's metadata from the latest fetch, if it was part of it.
|
||||
Installed {
|
||||
index: usize,
|
||||
remote_index: Option<usize>,
|
||||
},
|
||||
/// Index into the remote extensions.
|
||||
Remote(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum ExtensionFetchState {
|
||||
Fetching,
|
||||
Succeeded,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum FetchDebounce {
|
||||
Immediate,
|
||||
/// Debounce the fetch if there is a search query.
|
||||
WhenSearching,
|
||||
}
|
||||
|
||||
pub struct ExtensionsPage {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
extension_store: Entity<ExtensionStore>,
|
||||
provider_registry: Arc<GitHostingProviderRegistry>,
|
||||
list: UniformListScrollHandle,
|
||||
is_fetching_extensions: bool,
|
||||
fetch_failed: bool,
|
||||
fetch_state: ExtensionFetchState,
|
||||
filter: ExtensionFilter,
|
||||
remote_extension_entries: Vec<ExtensionMetadata>,
|
||||
dev_extension_entries: Vec<Arc<ExtensionManifest>>,
|
||||
filtered_remote_extension_indices: Vec<usize>,
|
||||
filtered_dev_extension_indices: Vec<usize>,
|
||||
/// Installed extensions matching the current search.
|
||||
installed_search_results: Vec<ExtensionIndexEntry>,
|
||||
/// Results of the latest fetch, empty if it failed.
|
||||
remote_extensions: Vec<ExtensionMetadata>,
|
||||
displayed_extensions: Vec<DisplayedExtension>,
|
||||
query_editor: Entity<Editor>,
|
||||
query_contains_error: bool,
|
||||
provides_filter: Option<ExtensionProvides>,
|
||||
_subscriptions: [gpui::Subscription; 2],
|
||||
extension_fetch_task: Option<Task<()>>,
|
||||
local_search_task: Option<Task<()>>,
|
||||
upsells: BTreeSet<Feature>,
|
||||
}
|
||||
|
||||
@@ -399,16 +418,16 @@ impl ExtensionsPage {
|
||||
cx: &mut Context<Workspace>,
|
||||
) -> Entity<Self> {
|
||||
cx.new(|cx| {
|
||||
let store = ExtensionStore::global(cx);
|
||||
let extension_store = ExtensionStore::global(cx);
|
||||
let workspace_handle = workspace.weak_handle();
|
||||
let subscriptions = [
|
||||
cx.observe(&store, |_: &mut Self, _, cx| cx.notify()),
|
||||
cx.observe(&extension_store, |_: &mut Self, _, cx| cx.notify()),
|
||||
cx.subscribe_in(
|
||||
&store,
|
||||
&extension_store,
|
||||
window,
|
||||
move |this, _, event, window, cx| match event {
|
||||
extension_host::Event::ExtensionsUpdated => {
|
||||
this.fetch_extensions_debounced(None, cx)
|
||||
this.update_local_search_results(cx)
|
||||
}
|
||||
extension_host::Event::ExtensionInstalled(extension_id) => this
|
||||
.on_extension_installed(
|
||||
@@ -437,28 +456,24 @@ impl ExtensionsPage {
|
||||
|
||||
let mut this = Self {
|
||||
workspace: workspace.weak_handle(),
|
||||
extension_store,
|
||||
provider_registry,
|
||||
list: scroll_handle,
|
||||
is_fetching_extensions: false,
|
||||
fetch_failed: false,
|
||||
fetch_state: ExtensionFetchState::Fetching,
|
||||
filter: ExtensionFilter::All,
|
||||
dev_extension_entries: Vec::new(),
|
||||
filtered_remote_extension_indices: Vec::new(),
|
||||
filtered_dev_extension_indices: Vec::new(),
|
||||
remote_extension_entries: Vec::new(),
|
||||
installed_search_results: Vec::new(),
|
||||
remote_extensions: Vec::new(),
|
||||
displayed_extensions: Vec::new(),
|
||||
query_contains_error: false,
|
||||
provides_filter,
|
||||
extension_fetch_task: None,
|
||||
local_search_task: None,
|
||||
_subscriptions: subscriptions,
|
||||
query_editor,
|
||||
upsells: BTreeSet::default(),
|
||||
};
|
||||
this.fetch_extensions(
|
||||
this.search_query(cx),
|
||||
Some(BTreeSet::from_iter(this.provides_filter)),
|
||||
None,
|
||||
cx,
|
||||
);
|
||||
this.update_local_search_results(cx);
|
||||
this.fetch_extensions(FetchDebounce::Immediate, None, cx);
|
||||
this
|
||||
})
|
||||
}
|
||||
@@ -476,7 +491,7 @@ impl ExtensionsPage {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let extension_store = ExtensionStore::global(cx).read(cx);
|
||||
let extension_store = self.extension_store.read(cx);
|
||||
let themes = extension_store
|
||||
.extension_themes(extension_id)
|
||||
.map(|name| name.to_string())
|
||||
@@ -515,43 +530,117 @@ impl ExtensionsPage {
|
||||
}
|
||||
}
|
||||
|
||||
fn filter_extension_entries(&mut self, cx: &mut Context<Self>) {
|
||||
self.filtered_remote_extension_indices.clear();
|
||||
self.filtered_remote_extension_indices.extend(
|
||||
self.remote_extension_entries
|
||||
/// Runs the search against the locally installed extensions, independently of
|
||||
/// the remote fetch, so local results show up without waiting for the server.
|
||||
fn update_local_search_results(&mut self, cx: &mut Context<Self>) {
|
||||
let search = self.search_query(cx);
|
||||
let mut installed_extensions = self
|
||||
.extension_store
|
||||
.read(cx)
|
||||
.installed_extensions()
|
||||
.values()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
self.local_search_task = Some(cx.spawn(async move |this, cx| {
|
||||
let results = match search.as_deref() {
|
||||
None => {
|
||||
installed_extensions
|
||||
.sort_by_cached_key(|extension| extension.manifest.name.to_lowercase());
|
||||
installed_extensions
|
||||
}
|
||||
Some(search) => {
|
||||
if let Some(extension_id) = search.strip_prefix("id:") {
|
||||
installed_extensions
|
||||
.into_iter()
|
||||
.filter(|extension| extension.manifest.id.as_ref() == extension_id)
|
||||
.collect()
|
||||
} else {
|
||||
let match_candidates = installed_extensions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, extension)| {
|
||||
StringMatchCandidate::new(index, &extension.manifest.name)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let matches = match_strings(
|
||||
&match_candidates,
|
||||
search,
|
||||
false,
|
||||
true,
|
||||
match_candidates.len(),
|
||||
&Default::default(),
|
||||
cx.background_executor().clone(),
|
||||
)
|
||||
.await;
|
||||
matches
|
||||
.into_iter()
|
||||
.filter_map(|matched| {
|
||||
installed_extensions.get(matched.candidate_id).cloned()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.update(cx, |this, cx| {
|
||||
this.installed_search_results = results;
|
||||
this.rebuild_displayed_extensions(cx);
|
||||
})
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
|
||||
fn rebuild_displayed_extensions(&mut self, cx: &mut Context<Self>) {
|
||||
let installed_extensions = self.extension_store.read(cx).installed_extensions();
|
||||
let provides_filter = self.provides_filter;
|
||||
|
||||
// Remote results can lag behind a provides filter change by one fetch, so
|
||||
// the filter is applied locally as well.
|
||||
let installed_rows =
|
||||
self.installed_search_results
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, extension)| {
|
||||
if self.filter == ExtensionFilter::All {
|
||||
return true;
|
||||
}
|
||||
|
||||
let status = remote_extension_status(&extension.id, cx);
|
||||
match self.filter {
|
||||
ExtensionFilter::Installed => status.is_installed(),
|
||||
ExtensionFilter::NotInstalled => !status.is_installed(),
|
||||
ExtensionFilter::All => true,
|
||||
}
|
||||
})
|
||||
.filter(|(_, extension)| match self.provides_filter {
|
||||
Some(provides) => extension.manifest.provides.contains(&provides),
|
||||
None => true,
|
||||
})
|
||||
.map(|(ix, _)| ix),
|
||||
);
|
||||
|
||||
self.filtered_dev_extension_indices.clear();
|
||||
self.filtered_dev_extension_indices.extend(
|
||||
self.dev_extension_entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, manifest)| match self.provides_filter {
|
||||
Some(provides) => manifest.provides().contains(&provides),
|
||||
None => true,
|
||||
})
|
||||
.map(|(ix, _)| ix),
|
||||
);
|
||||
provides_filter
|
||||
.is_none_or(|provides| extension.manifest.provides().contains(&provides))
|
||||
});
|
||||
let remote_rows = self
|
||||
.remote_extensions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, extension)| {
|
||||
provides_filter
|
||||
.is_none_or(|provides| extension.manifest.provides.contains(&provides))
|
||||
});
|
||||
let installed_row = |(index, extension): (usize, &ExtensionIndexEntry)| {
|
||||
let remote_index = (!extension.dev).then(|| {
|
||||
self.remote_extensions
|
||||
.iter()
|
||||
.position(|remote| remote.id == extension.manifest.id)
|
||||
});
|
||||
DisplayedExtension::Installed {
|
||||
index,
|
||||
remote_index: remote_index.flatten(),
|
||||
}
|
||||
};
|
||||
let remote_row = |(index, _)| DisplayedExtension::Remote(index);
|
||||
|
||||
self.displayed_extensions = match self.filter {
|
||||
ExtensionFilter::All if self.fetch_state == ExtensionFetchState::Failed => {
|
||||
installed_rows.map(installed_row).collect()
|
||||
}
|
||||
ExtensionFilter::All => installed_rows
|
||||
.filter(|(_, extension)| extension.dev)
|
||||
.map(installed_row)
|
||||
.chain(remote_rows.map(remote_row))
|
||||
.collect(),
|
||||
ExtensionFilter::Installed => installed_rows.map(installed_row).collect(),
|
||||
ExtensionFilter::NotInstalled => remote_rows
|
||||
.filter(|(_, extension)| !installed_extensions.contains_key(&extension.id))
|
||||
.map(remote_row)
|
||||
.collect(),
|
||||
};
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -560,97 +649,79 @@ impl ExtensionsPage {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Fetches the remote extensions for the current search. Any fetch still in
|
||||
/// flight is cancelled.
|
||||
fn fetch_extensions(
|
||||
&mut self,
|
||||
search: Option<String>,
|
||||
provides_filter: Option<BTreeSet<ExtensionProvides>>,
|
||||
on_complete: Option<Box<dyn FnOnce(&mut Self, &mut Context<Self>) + Send>>,
|
||||
debounce: FetchDebounce,
|
||||
on_complete: Option<Box<dyn FnOnce(&mut Self, &mut Context<Self>)>>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.is_fetching_extensions = true;
|
||||
self.fetch_failed = false;
|
||||
let search = self.search_query(cx);
|
||||
let provides_filter = BTreeSet::from_iter(self.provides_filter);
|
||||
self.fetch_state = ExtensionFetchState::Fetching;
|
||||
cx.notify();
|
||||
|
||||
let extension_store = ExtensionStore::global(cx);
|
||||
self.extension_fetch_task = Some(cx.spawn(async move |this, cx| {
|
||||
// Only debounce the fetching of extensions if we have a search
|
||||
// query.
|
||||
//
|
||||
// If the search was just cleared then we can just reload the list
|
||||
// of extensions without a debounce, which allows us to avoid seeing
|
||||
// an intermittent flash of a "no extensions" state.
|
||||
if debounce == FetchDebounce::WhenSearching && search.is_some() {
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(250))
|
||||
.await;
|
||||
}
|
||||
|
||||
let dev_extensions = extension_store
|
||||
.read(cx)
|
||||
.dev_extensions()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let remote_extensions =
|
||||
if let Some(id) = search.as_ref().and_then(|s| s.strip_prefix("id:")) {
|
||||
let versions =
|
||||
extension_store.update(cx, |store, cx| store.fetch_extension_versions(id, cx));
|
||||
cx.foreground_executor().spawn(async move {
|
||||
let versions = versions.await?;
|
||||
let latest = versions
|
||||
.into_iter()
|
||||
.max_by_key(|v| v.published_at)
|
||||
.context("no extension found")?;
|
||||
Ok(vec![latest])
|
||||
})
|
||||
} else {
|
||||
extension_store.update(cx, |store, cx| {
|
||||
store.fetch_extensions(search.as_deref(), provides_filter.as_ref(), cx)
|
||||
})
|
||||
let Ok(remote_extensions) = this.update(cx, |this, cx| {
|
||||
let extension_store = &this.extension_store;
|
||||
if let Some(id) = search
|
||||
.as_deref()
|
||||
.and_then(|search| search.strip_prefix("id:"))
|
||||
{
|
||||
let versions = extension_store
|
||||
.update(cx, |store, cx| store.fetch_extension_versions(id, cx));
|
||||
cx.foreground_executor().spawn(async move {
|
||||
let versions = versions.await?;
|
||||
let latest = versions
|
||||
.into_iter()
|
||||
.max_by_key(|version| version.published_at)
|
||||
.context("no extension found")?;
|
||||
Ok(vec![latest])
|
||||
})
|
||||
} else {
|
||||
extension_store.update(cx, |store, cx| {
|
||||
store.fetch_extensions(search.as_deref(), Some(&provides_filter), cx)
|
||||
})
|
||||
}
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
let dev_extensions = if let Some(search) = search {
|
||||
let match_candidates = dev_extensions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(ix, manifest)| StringMatchCandidate::new(ix, &manifest.name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let matches = match_strings(
|
||||
&match_candidates,
|
||||
&search,
|
||||
false,
|
||||
true,
|
||||
match_candidates.len(),
|
||||
&Default::default(),
|
||||
cx.background_executor().clone(),
|
||||
)
|
||||
.await;
|
||||
matches
|
||||
.into_iter()
|
||||
.map(|mat| dev_extensions[mat.candidate_id].clone())
|
||||
.collect()
|
||||
} else {
|
||||
dev_extensions
|
||||
};
|
||||
|
||||
let fetch_result = remote_extensions.await;
|
||||
|
||||
let result = this.update(cx, |this, cx| {
|
||||
cx.notify();
|
||||
this.dev_extension_entries = dev_extensions;
|
||||
this.is_fetching_extensions = false;
|
||||
|
||||
this.update(cx, |this, cx| {
|
||||
match fetch_result {
|
||||
Ok(extensions) => {
|
||||
this.fetch_failed = false;
|
||||
this.remote_extension_entries = extensions;
|
||||
this.filter_extension_entries(cx);
|
||||
if let Some(callback) = on_complete {
|
||||
callback(this, cx);
|
||||
}
|
||||
Ok(())
|
||||
Ok(remote_extensions) => {
|
||||
this.fetch_state = ExtensionFetchState::Succeeded;
|
||||
this.remote_extensions = remote_extensions;
|
||||
}
|
||||
Err(err) => {
|
||||
this.fetch_failed = true;
|
||||
this.filter_extension_entries(cx);
|
||||
Err(err)
|
||||
Err(error) => {
|
||||
log::error!("failed to fetch extensions: {error:#}");
|
||||
this.fetch_state = ExtensionFetchState::Failed;
|
||||
this.remote_extensions.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
result?
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
this.rebuild_displayed_extensions(cx);
|
||||
if this.fetch_state == ExtensionFetchState::Succeeded
|
||||
&& let Some(on_complete) = on_complete
|
||||
{
|
||||
on_complete(this, cx);
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
|
||||
fn render_extensions(
|
||||
@@ -659,71 +730,95 @@ impl ExtensionsPage {
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Vec<ExtensionCard> {
|
||||
let dev_extension_entries_len = if self.filter.include_dev_extensions() {
|
||||
self.filtered_dev_extension_indices.len()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let extension_store = self.extension_store.read(cx);
|
||||
range
|
||||
.map(|ix| {
|
||||
if ix < dev_extension_entries_len {
|
||||
let dev_ix = self.filtered_dev_extension_indices[ix];
|
||||
let extension = &self.dev_extension_entries[dev_ix];
|
||||
let repository_icon = extension
|
||||
.repository
|
||||
.as_deref()
|
||||
.map(|url| self.get_repository_icon(url));
|
||||
let card = ExtensionCard::for_dev(extension.clone(), cx);
|
||||
if let Some(icon) = repository_icon {
|
||||
card.repository_icon(icon)
|
||||
} else {
|
||||
card
|
||||
}
|
||||
} else {
|
||||
let extension_ix =
|
||||
self.filtered_remote_extension_indices[ix - dev_extension_entries_len];
|
||||
let extension = &self.remote_extension_entries[extension_ix];
|
||||
self.render_remote_extension(extension, cx)
|
||||
}
|
||||
.filter_map(|index| {
|
||||
let row = *self.displayed_extensions.get(index)?;
|
||||
self.render_extension(row, extension_store, cx)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn render_remote_extension(
|
||||
fn render_extension(
|
||||
&self,
|
||||
extension: &ExtensionMetadata,
|
||||
cx: &mut Context<Self>,
|
||||
) -> ExtensionCard {
|
||||
let repository_icon = self.get_repository_icon(&extension.manifest.repository);
|
||||
let card = ExtensionCard::for_remote(extension, cx).repository_icon(repository_icon);
|
||||
let this = cx.weak_entity();
|
||||
row: DisplayedExtension,
|
||||
extension_store: &ExtensionStore,
|
||||
cx: &Context<Self>,
|
||||
) -> Option<ExtensionCard> {
|
||||
let remote_index = match row {
|
||||
DisplayedExtension::Installed {
|
||||
index,
|
||||
remote_index: None,
|
||||
} => {
|
||||
let extension = self.installed_search_results.get(index)?;
|
||||
let manifest = extension.manifest.clone();
|
||||
let repository_icon = manifest
|
||||
.repository
|
||||
.as_deref()
|
||||
.map(|url| self.get_repository_icon(url));
|
||||
let card = if extension.dev {
|
||||
ExtensionCard::for_dev(manifest, extension_store)
|
||||
} else {
|
||||
ExtensionCard::for_installed(manifest, extension_store)
|
||||
};
|
||||
return Some(match repository_icon {
|
||||
Some(icon) => card.repository_icon(icon),
|
||||
None => card,
|
||||
});
|
||||
}
|
||||
DisplayedExtension::Installed {
|
||||
remote_index: Some(remote_index),
|
||||
..
|
||||
}
|
||||
| DisplayedExtension::Remote(remote_index) => remote_index,
|
||||
};
|
||||
|
||||
card.context_menu(move |extension_id, authors, window, cx| {
|
||||
let this = this.upgrade()?;
|
||||
Some(ContextMenu::build(window, cx, |context_menu, window, _| {
|
||||
context_menu
|
||||
.entry(
|
||||
"Install Another Version...",
|
||||
None,
|
||||
window.handler_for(&this, {
|
||||
let extension_id = extension_id.clone();
|
||||
move |this, window, cx| {
|
||||
this.show_extension_version_list(extension_id.clone(), window, cx)
|
||||
}
|
||||
}),
|
||||
)
|
||||
.entry("Copy Extension ID", None, {
|
||||
let extension = self.remote_extensions.get(remote_index)?;
|
||||
let weak_self = cx.weak_entity();
|
||||
Some(
|
||||
ExtensionCard::for_remote(extension, extension_store, cx)
|
||||
.repository_icon(self.get_repository_icon(&extension.manifest.repository))
|
||||
.context_menu(move |extension_id, authors, window, cx| {
|
||||
let this = weak_self.upgrade()?;
|
||||
Some(Self::render_remote_extension_context_menu(
|
||||
&this,
|
||||
extension_id,
|
||||
authors,
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_remote_extension_context_menu(
|
||||
this: &Entity<Self>,
|
||||
extension_id: Arc<str>,
|
||||
authors: SharedString,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Entity<ContextMenu> {
|
||||
ContextMenu::build(window, cx, |context_menu, window, _| {
|
||||
context_menu
|
||||
.entry(
|
||||
"Install Another Version...",
|
||||
None,
|
||||
window.handler_for(this, {
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(
|
||||
extension_id.to_string(),
|
||||
));
|
||||
move |this, window, cx| {
|
||||
this.show_extension_version_list(extension_id.clone(), window, cx)
|
||||
}
|
||||
})
|
||||
.entry("Copy Author Info", None, move |_, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(authors.to_string()));
|
||||
})
|
||||
}))
|
||||
}),
|
||||
)
|
||||
.entry("Copy Extension ID", None, {
|
||||
let extension_id = extension_id.clone();
|
||||
move |_, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(extension_id.to_string()));
|
||||
}
|
||||
})
|
||||
.entry("Copy Author Info", None, move |_, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(authors.to_string()));
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -738,10 +833,8 @@ impl ExtensionsPage {
|
||||
};
|
||||
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
let extension_versions_task = this.update(cx, |_, cx| {
|
||||
let extension_store = ExtensionStore::global(cx);
|
||||
|
||||
extension_store.update(cx, |store, cx| {
|
||||
let extension_versions_task = this.update(cx, |this, cx| {
|
||||
this.extension_store.update(cx, |store, cx| {
|
||||
store.fetch_extension_versions(&extension_id, cx)
|
||||
})
|
||||
})?;
|
||||
@@ -788,7 +881,27 @@ impl ExtensionsPage {
|
||||
.border_color(editor_border)
|
||||
.rounded_md()
|
||||
.child(Icon::new(IconName::MagnifyingGlass).color(Color::Muted))
|
||||
.child(self.render_text_input(&self.query_editor, cx))
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.child(self.render_text_input(&self.query_editor, cx)),
|
||||
)
|
||||
.when(self.fetch_state == ExtensionFetchState::Fetching, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::LoadCircle)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Muted)
|
||||
.with_rotate_animation(2),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn retry_button(&self, cx: &mut Context<Self>) -> Button {
|
||||
Button::new("retry-fetch-extensions", "Retry")
|
||||
.style(ButtonStyle::Outlined)
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.fetch_extensions(FetchDebounce::Immediate, None, cx);
|
||||
}))
|
||||
}
|
||||
|
||||
fn render_text_input(
|
||||
@@ -836,7 +949,9 @@ impl ExtensionsPage {
|
||||
}
|
||||
|
||||
fn refresh_search(&mut self, cx: &mut Context<Self>) {
|
||||
self.fetch_extensions_debounced(
|
||||
self.update_local_search_results(cx);
|
||||
self.fetch_extensions(
|
||||
FetchDebounce::WhenSearching,
|
||||
Some(Box::new(|this, cx| {
|
||||
this.scroll_to_top(cx);
|
||||
})),
|
||||
@@ -861,41 +976,6 @@ impl ExtensionsPage {
|
||||
self.refresh_search(cx);
|
||||
}
|
||||
|
||||
fn fetch_extensions_debounced(
|
||||
&mut self,
|
||||
on_complete: Option<Box<dyn FnOnce(&mut Self, &mut Context<Self>) + Send>>,
|
||||
cx: &mut Context<ExtensionsPage>,
|
||||
) {
|
||||
self.extension_fetch_task = Some(cx.spawn(async move |this, cx| {
|
||||
let search = this
|
||||
.update(cx, |this, cx| this.search_query(cx))
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
// Only debounce the fetching of extensions if we have a search
|
||||
// query.
|
||||
//
|
||||
// If the search was just cleared then we can just reload the list
|
||||
// of extensions without a debounce, which allows us to avoid seeing
|
||||
// an intermittent flash of a "no extensions" state.
|
||||
if search.is_some() {
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(250))
|
||||
.await;
|
||||
};
|
||||
|
||||
this.update(cx, |this, cx| {
|
||||
this.fetch_extensions(
|
||||
search,
|
||||
Some(BTreeSet::from_iter(this.provides_filter)),
|
||||
on_complete,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn search_query(&self, cx: &mut App) -> Option<String> {
|
||||
let search = self.query_editor.read(cx).text(cx);
|
||||
if search.trim().is_empty() {
|
||||
@@ -908,9 +988,15 @@ impl ExtensionsPage {
|
||||
fn render_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let has_search = self.search_query(cx).is_some();
|
||||
|
||||
let message = if self.is_fetching_extensions {
|
||||
// The `Installed` filter is fully local, so fetch progress and failure are
|
||||
// only relevant to the other filters.
|
||||
let fetch_is_relevant = self.filter != ExtensionFilter::Installed;
|
||||
let fetch_failure_is_relevant =
|
||||
self.fetch_state == ExtensionFetchState::Failed && fetch_is_relevant;
|
||||
let is_loading = self.fetch_state == ExtensionFetchState::Fetching && fetch_is_relevant;
|
||||
let message = if is_loading {
|
||||
"Loading extensions…"
|
||||
} else if self.fetch_failed {
|
||||
} else if fetch_failure_is_relevant {
|
||||
"Failed to load extensions. Please check your connection and try again."
|
||||
} else {
|
||||
match self.filter {
|
||||
@@ -938,23 +1024,39 @@ impl ExtensionsPage {
|
||||
}
|
||||
};
|
||||
|
||||
h_flex()
|
||||
.py_4()
|
||||
.gap_1p5()
|
||||
.when(self.fetch_failed, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::Warning)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Warning),
|
||||
)
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap_3()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1p5()
|
||||
.when(is_loading, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::LoadCircle)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Accent)
|
||||
.with_rotate_animation(3),
|
||||
)
|
||||
})
|
||||
.when(fetch_failure_is_relevant, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::Warning)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Warning),
|
||||
)
|
||||
})
|
||||
.child(Label::new(message)),
|
||||
)
|
||||
.when(fetch_failure_is_relevant, |this| {
|
||||
this.child(self.retry_button(cx))
|
||||
})
|
||||
.child(Label::new(message))
|
||||
}
|
||||
|
||||
fn update_settings(
|
||||
&mut self,
|
||||
selection: &ToggleState,
|
||||
|
||||
cx: &mut Context<Self>,
|
||||
callback: impl 'static + Send + Fn(&mut SettingsContent, bool),
|
||||
) {
|
||||
@@ -1408,7 +1510,7 @@ impl Render for ExtensionsPage {
|
||||
"All",
|
||||
cx.listener(|this, _event, _, cx| {
|
||||
this.filter = ExtensionFilter::All;
|
||||
this.filter_extension_entries(cx);
|
||||
this.rebuild_displayed_extensions(cx);
|
||||
this.scroll_to_top(cx);
|
||||
}),
|
||||
),
|
||||
@@ -1416,7 +1518,7 @@ impl Render for ExtensionsPage {
|
||||
"Installed",
|
||||
cx.listener(|this, _event, _, cx| {
|
||||
this.filter = ExtensionFilter::Installed;
|
||||
this.filter_extension_entries(cx);
|
||||
this.rebuild_displayed_extensions(cx);
|
||||
this.scroll_to_top(cx);
|
||||
}),
|
||||
),
|
||||
@@ -1424,7 +1526,7 @@ impl Render for ExtensionsPage {
|
||||
"Not Installed",
|
||||
cx.listener(|this, _event, _, cx| {
|
||||
this.filter = ExtensionFilter::NotInstalled;
|
||||
this.filter_extension_entries(cx);
|
||||
this.rebuild_displayed_extensions(cx);
|
||||
this.scroll_to_top(cx);
|
||||
}),
|
||||
),
|
||||
@@ -1497,16 +1599,32 @@ impl Render for ExtensionsPage {
|
||||
)
|
||||
.child(self.render_feature_upsells(cx))
|
||||
.child(v_flex().px_4().size_full().overflow_y_hidden().map(|this| {
|
||||
let mut count = self.filtered_remote_extension_indices.len();
|
||||
if self.filter.include_dev_extensions() {
|
||||
count += self.filtered_dev_extension_indices.len();
|
||||
}
|
||||
let count = self.displayed_extensions.len();
|
||||
|
||||
if count == 0 {
|
||||
this.child(self.render_empty_state(cx)).into_any_element()
|
||||
} else {
|
||||
let scroll_handle = &self.list;
|
||||
this.child(
|
||||
this.when(
|
||||
self.fetch_state == ExtensionFetchState::Failed
|
||||
&& self.filter == ExtensionFilter::All,
|
||||
|this| {
|
||||
this.child(
|
||||
div().pt_4().child(
|
||||
Banner::new()
|
||||
.severity(Severity::Warning)
|
||||
.child(
|
||||
Label::new(
|
||||
"Failed to load extensions. Showing installed extensions only.",
|
||||
)
|
||||
.mt_0p5(),
|
||||
)
|
||||
.action_slot(self.retry_button(cx)),
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
.child(
|
||||
uniform_list("entries", count, cx.processor(Self::render_extensions))
|
||||
.flex_grow_1()
|
||||
.pb_4()
|
||||
|
||||
Reference in New Issue
Block a user