Show LSP status and auto update status in one status bar indicator
This commit is contained in:
parent
87124b959d
commit
ae61a24ad3
6 changed files with 165 additions and 175 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -2,6 +2,22 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "activity_indicator"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"auto_update",
|
||||||
|
"editor",
|
||||||
|
"futures",
|
||||||
|
"gpui",
|
||||||
|
"language",
|
||||||
|
"project",
|
||||||
|
"settings",
|
||||||
|
"smallvec",
|
||||||
|
"util",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
version = "0.17.0"
|
version = "0.17.0"
|
||||||
|
@ -2566,21 +2582,6 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lsp_status"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"editor",
|
|
||||||
"futures",
|
|
||||||
"gpui",
|
|
||||||
"language",
|
|
||||||
"project",
|
|
||||||
"settings",
|
|
||||||
"smallvec",
|
|
||||||
"util",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "malloc_buf"
|
name = "malloc_buf"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
|
@ -5971,6 +5972,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.42.0"
|
version = "0.42.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"activity_indicator",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assets",
|
"assets",
|
||||||
"async-compression",
|
"async-compression",
|
||||||
|
@ -6011,7 +6013,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"lsp",
|
"lsp",
|
||||||
"lsp_status",
|
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"outline",
|
"outline",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lsp_status"
|
name = "activity_indicator"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "src/lsp_status.rs"
|
path = "src/activity_indicator.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
auto_update = { path = "../auto_update" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
|
@ -1,7 +1,8 @@
|
||||||
|
use auto_update::{AutoUpdateStatus, AutoUpdater, DismissErrorMessage};
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::*, platform::CursorStyle, AppContext, Entity, EventContext, ModelHandle,
|
actions, elements::*, platform::CursorStyle, Action, AppContext, Entity, ModelHandle,
|
||||||
MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
|
MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
|
||||||
};
|
};
|
||||||
use language::{LanguageRegistry, LanguageServerBinaryStatus};
|
use language::{LanguageRegistry, LanguageServerBinaryStatus};
|
||||||
|
@ -14,13 +15,18 @@ use workspace::{ItemHandle, StatusItemView, Workspace};
|
||||||
|
|
||||||
actions!(lsp_status, [ShowErrorMessage]);
|
actions!(lsp_status, [ShowErrorMessage]);
|
||||||
|
|
||||||
|
const DOWNLOAD_ICON: &'static str = "icons/download-solid-14.svg";
|
||||||
|
const WARNING_ICON: &'static str = "icons/warning-solid-14.svg";
|
||||||
|
const DONE_ICON: &'static str = "icons/accept.svg";
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
ShowError { lsp_name: Arc<str>, error: String },
|
ShowError { lsp_name: Arc<str>, error: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LspStatusItem {
|
pub struct ActivityIndicator {
|
||||||
statuses: Vec<LspStatus>,
|
statuses: Vec<LspStatus>,
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
|
auto_updater: Option<ModelHandle<AutoUpdater>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LspStatus {
|
struct LspStatus {
|
||||||
|
@ -29,15 +35,16 @@ struct LspStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(LspStatusItem::show_error_message);
|
cx.add_action(ActivityIndicator::show_error_message);
|
||||||
|
cx.add_action(ActivityIndicator::dismiss_error_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LspStatusItem {
|
impl ActivityIndicator {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) -> ViewHandle<LspStatusItem> {
|
) -> ViewHandle<ActivityIndicator> {
|
||||||
let project = workspace.project().clone();
|
let project = workspace.project().clone();
|
||||||
let this = cx.add_view(|cx: &mut ViewContext<Self>| {
|
let this = cx.add_view(|cx: &mut ViewContext<Self>| {
|
||||||
let mut status_events = languages.language_server_binary_statuses();
|
let mut status_events = languages.language_server_binary_statuses();
|
||||||
|
@ -63,6 +70,7 @@ impl LspStatusItem {
|
||||||
Self {
|
Self {
|
||||||
statuses: Default::default(),
|
statuses: Default::default(),
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
|
auto_updater: AutoUpdater::get(cx),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cx.subscribe(&this, move |workspace, _, event, cx| match event {
|
cx.subscribe(&this, move |workspace, _, event, cx| match event {
|
||||||
|
@ -106,6 +114,15 @@ impl LspStatusItem {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dismiss_error_message(&mut self, _: &DismissErrorMessage, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(updater) = &self.auto_updater {
|
||||||
|
updater.update(cx, |updater, cx| {
|
||||||
|
updater.dismiss_error(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
fn pending_language_server_work<'a>(
|
fn pending_language_server_work<'a>(
|
||||||
&self,
|
&self,
|
||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
|
@ -129,25 +146,15 @@ impl LspStatusItem {
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Entity for LspStatusItem {
|
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl View for LspStatusItem {
|
|
||||||
fn ui_name() -> &'static str {
|
|
||||||
"LspStatus"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
|
||||||
let mut message;
|
|
||||||
let mut icon = None;
|
|
||||||
let mut handler = None;
|
|
||||||
|
|
||||||
|
fn content_to_render(
|
||||||
|
&mut self,
|
||||||
|
cx: &mut RenderContext<Self>,
|
||||||
|
) -> (Option<&'static str>, String, Option<Box<dyn Action>>) {
|
||||||
|
// Show any language server has pending activity.
|
||||||
let mut pending_work = self.pending_language_server_work(cx);
|
let mut pending_work = self.pending_language_server_work(cx);
|
||||||
if let Some((lang_server_name, progress_token, progress)) = pending_work.next() {
|
if let Some((lang_server_name, progress_token, progress)) = pending_work.next() {
|
||||||
message = lang_server_name.to_string();
|
let mut message = lang_server_name.to_string();
|
||||||
|
|
||||||
message.push_str(": ");
|
message.push_str(": ");
|
||||||
if let Some(progress_message) = progress.message.as_ref() {
|
if let Some(progress_message) = progress.message.as_ref() {
|
||||||
|
@ -164,38 +171,43 @@ impl View for LspStatusItem {
|
||||||
if additional_work_count > 0 {
|
if additional_work_count > 0 {
|
||||||
write!(&mut message, " + {} more", additional_work_count).unwrap();
|
write!(&mut message, " + {} more", additional_work_count).unwrap();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
drop(pending_work);
|
|
||||||
|
|
||||||
let mut downloading = SmallVec::<[_; 3]>::new();
|
return (None, message, None);
|
||||||
let mut checking_for_update = SmallVec::<[_; 3]>::new();
|
}
|
||||||
let mut failed = SmallVec::<[_; 3]>::new();
|
|
||||||
for status in &self.statuses {
|
// Show any language server installation info.
|
||||||
match status.status {
|
let mut downloading = SmallVec::<[_; 3]>::new();
|
||||||
LanguageServerBinaryStatus::CheckingForUpdate => {
|
let mut checking_for_update = SmallVec::<[_; 3]>::new();
|
||||||
checking_for_update.push(status.name.clone());
|
let mut failed = SmallVec::<[_; 3]>::new();
|
||||||
}
|
for status in &self.statuses {
|
||||||
LanguageServerBinaryStatus::Downloading => {
|
match status.status {
|
||||||
downloading.push(status.name.clone());
|
LanguageServerBinaryStatus::CheckingForUpdate => {
|
||||||
}
|
checking_for_update.push(status.name.clone());
|
||||||
LanguageServerBinaryStatus::Failed { .. } => {
|
|
||||||
failed.push(status.name.clone());
|
|
||||||
}
|
|
||||||
LanguageServerBinaryStatus::Downloaded | LanguageServerBinaryStatus::Cached => {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
LanguageServerBinaryStatus::Downloading => {
|
||||||
|
downloading.push(status.name.clone());
|
||||||
|
}
|
||||||
|
LanguageServerBinaryStatus::Failed { .. } => {
|
||||||
|
failed.push(status.name.clone());
|
||||||
|
}
|
||||||
|
LanguageServerBinaryStatus::Downloaded | LanguageServerBinaryStatus::Cached => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !downloading.is_empty() {
|
if !downloading.is_empty() {
|
||||||
icon = Some("icons/download-solid-14.svg");
|
return (
|
||||||
message = format!(
|
Some(DOWNLOAD_ICON),
|
||||||
|
format!(
|
||||||
"Downloading {} language server{}...",
|
"Downloading {} language server{}...",
|
||||||
downloading.join(", "),
|
downloading.join(", "),
|
||||||
if downloading.len() > 1 { "s" } else { "" }
|
if downloading.len() > 1 { "s" } else { "" }
|
||||||
);
|
),
|
||||||
} else if !checking_for_update.is_empty() {
|
None,
|
||||||
icon = Some("icons/download-solid-14.svg");
|
);
|
||||||
message = format!(
|
} else if !checking_for_update.is_empty() {
|
||||||
|
return (
|
||||||
|
Some(DOWNLOAD_ICON),
|
||||||
|
format!(
|
||||||
"Checking for updates to {} language server{}...",
|
"Checking for updates to {} language server{}...",
|
||||||
checking_for_update.join(", "),
|
checking_for_update.join(", "),
|
||||||
if checking_for_update.len() > 1 {
|
if checking_for_update.len() > 1 {
|
||||||
|
@ -203,20 +215,68 @@ impl View for LspStatusItem {
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
);
|
),
|
||||||
} else if !failed.is_empty() {
|
None,
|
||||||
icon = Some("icons/warning-solid-14.svg");
|
);
|
||||||
message = format!(
|
} else if !failed.is_empty() {
|
||||||
|
return (
|
||||||
|
Some(WARNING_ICON),
|
||||||
|
format!(
|
||||||
"Failed to download {} language server{}. Click to show error.",
|
"Failed to download {} language server{}. Click to show error.",
|
||||||
failed.join(", "),
|
failed.join(", "),
|
||||||
if failed.len() > 1 { "s" } else { "" }
|
if failed.len() > 1 { "s" } else { "" }
|
||||||
);
|
),
|
||||||
handler = Some(|_, _, cx: &mut EventContext| cx.dispatch_action(ShowErrorMessage));
|
Some(Box::new(ShowErrorMessage)),
|
||||||
} else {
|
);
|
||||||
return Empty::new().boxed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show any application auto-update info.
|
||||||
|
if let Some(updater) = &self.auto_updater {
|
||||||
|
// let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||||
|
match &updater.read(cx).status() {
|
||||||
|
AutoUpdateStatus::Checking => (
|
||||||
|
Some(DOWNLOAD_ICON),
|
||||||
|
"Checking for Zed updates…".to_string(),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
AutoUpdateStatus::Downloading => (
|
||||||
|
Some(DOWNLOAD_ICON),
|
||||||
|
"Downloading Zed update…".to_string(),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
AutoUpdateStatus::Installing => (
|
||||||
|
Some(DOWNLOAD_ICON),
|
||||||
|
"Installing Zed update…".to_string(),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
AutoUpdateStatus::Updated => {
|
||||||
|
(Some(DONE_ICON), "Restart to update Zed".to_string(), None)
|
||||||
|
}
|
||||||
|
AutoUpdateStatus::Errored => (
|
||||||
|
Some(WARNING_ICON),
|
||||||
|
"Auto update failed".to_string(),
|
||||||
|
Some(Box::new(DismissErrorMessage)),
|
||||||
|
),
|
||||||
|
AutoUpdateStatus::Idle => Default::default(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for ActivityIndicator {
|
||||||
|
type Event = Event;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl View for ActivityIndicator {
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"ActivityIndicator"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
|
let (icon, message, action) = self.content_to_render(cx);
|
||||||
|
|
||||||
let mut element = MouseEventHandler::new::<Self, _, _>(0, cx, |state, cx| {
|
let mut element = MouseEventHandler::new::<Self, _, _>(0, cx, |state, cx| {
|
||||||
let theme = &cx
|
let theme = &cx
|
||||||
.global::<Settings>()
|
.global::<Settings>()
|
||||||
|
@ -224,7 +284,7 @@ impl View for LspStatusItem {
|
||||||
.workspace
|
.workspace
|
||||||
.status_bar
|
.status_bar
|
||||||
.lsp_status;
|
.lsp_status;
|
||||||
let style = if state.hovered && handler.is_some() {
|
let style = if state.hovered && action.is_some() {
|
||||||
theme.hover.as_ref().unwrap_or(&theme.default)
|
theme.hover.as_ref().unwrap_or(&theme.default)
|
||||||
} else {
|
} else {
|
||||||
&theme.default
|
&theme.default
|
||||||
|
@ -238,9 +298,14 @@ impl View for LspStatusItem {
|
||||||
.contained()
|
.contained()
|
||||||
.with_margin_right(style.icon_spacing)
|
.with_margin_right(style.icon_spacing)
|
||||||
.aligned()
|
.aligned()
|
||||||
.named("warning-icon")
|
.named("activity-icon")
|
||||||
}))
|
}))
|
||||||
.with_child(Label::new(message, style.message.clone()).aligned().boxed())
|
.with_child(
|
||||||
|
Text::new(message, style.message.clone())
|
||||||
|
.with_soft_wrap(false)
|
||||||
|
.aligned()
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(style.height)
|
.with_height(style.height)
|
||||||
.contained()
|
.contained()
|
||||||
|
@ -249,16 +314,16 @@ impl View for LspStatusItem {
|
||||||
.boxed()
|
.boxed()
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(handler) = handler {
|
if let Some(action) = action {
|
||||||
element = element
|
element = element
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(handler);
|
.on_click(move |_, _, cx| cx.dispatch_any_action(action.boxed_clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
element.boxed()
|
element.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatusItemView for LspStatusItem {
|
impl StatusItemView for ActivityIndicator {
|
||||||
fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext<Self>) {}
|
fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext<Self>) {}
|
||||||
}
|
}
|
|
@ -3,19 +3,15 @@ mod update_notification;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN};
|
use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
|
||||||
elements::{Empty, MouseEventHandler, Text},
|
MutableAppContext, Task, WeakViewHandle,
|
||||||
platform::AppVersion,
|
|
||||||
AppContext, AsyncAppContext, Element, Entity, ModelContext, ModelHandle, MutableAppContext,
|
|
||||||
Task, View, ViewContext, WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use settings::Settings;
|
|
||||||
use smol::{fs::File, io::AsyncReadExt, process::Command};
|
use smol::{fs::File, io::AsyncReadExt, process::Command};
|
||||||
use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration};
|
use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use update_notification::UpdateNotification;
|
use update_notification::UpdateNotification;
|
||||||
use workspace::{ItemHandle, StatusItemView, Workspace};
|
use workspace::Workspace;
|
||||||
|
|
||||||
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &'static str =
|
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &'static str =
|
||||||
"auto-updater-should-show-updated-notification";
|
"auto-updater-should-show-updated-notification";
|
||||||
|
@ -30,7 +26,7 @@ lazy_static! {
|
||||||
|
|
||||||
actions!(auto_update, [Check, DismissErrorMessage, ViewReleaseNotes]);
|
actions!(auto_update, [Check, DismissErrorMessage, ViewReleaseNotes]);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum AutoUpdateStatus {
|
pub enum AutoUpdateStatus {
|
||||||
Idle,
|
Idle,
|
||||||
Checking,
|
Checking,
|
||||||
|
@ -49,10 +45,6 @@ pub struct AutoUpdater {
|
||||||
server_url: String,
|
server_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AutoUpdateIndicator {
|
|
||||||
updater: Option<ModelHandle<AutoUpdater>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct JsonRelease {
|
struct JsonRelease {
|
||||||
version: String,
|
version: String,
|
||||||
|
@ -84,7 +76,6 @@ pub fn init(
|
||||||
cx.add_global_action(move |_: &ViewReleaseNotes, cx| {
|
cx.add_global_action(move |_: &ViewReleaseNotes, cx| {
|
||||||
cx.platform().open_url(&format!("{server_url}/releases"));
|
cx.platform().open_url(&format!("{server_url}/releases"));
|
||||||
});
|
});
|
||||||
cx.add_action(AutoUpdateIndicator::dismiss_error_message);
|
|
||||||
cx.add_action(UpdateNotification::dismiss);
|
cx.add_action(UpdateNotification::dismiss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +111,7 @@ pub fn notify_of_any_new_update(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AutoUpdater {
|
impl AutoUpdater {
|
||||||
fn get(cx: &mut MutableAppContext) -> Option<ModelHandle<Self>> {
|
pub fn get(cx: &mut MutableAppContext) -> Option<ModelHandle<Self>> {
|
||||||
cx.default_global::<Option<ModelHandle<Self>>>().clone()
|
cx.default_global::<Option<ModelHandle<Self>>>().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +161,15 @@ impl AutoUpdater {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn status(&self) -> AutoUpdateStatus {
|
||||||
|
self.status
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dismiss_error(&mut self, cx: &mut ModelContext<Self>) {
|
||||||
|
self.status = AutoUpdateStatus::Idle;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
async fn update(this: ModelHandle<Self>, mut cx: AsyncAppContext) -> Result<()> {
|
async fn update(this: ModelHandle<Self>, mut cx: AsyncAppContext) -> Result<()> {
|
||||||
let (client, server_url, current_version) = this.read_with(&cx, |this, _| {
|
let (client, server_url, current_version) = this.read_with(&cx, |this, _| {
|
||||||
(
|
(
|
||||||
|
@ -299,79 +299,3 @@ impl AutoUpdater {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for AutoUpdateIndicator {
|
|
||||||
type Event = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl View for AutoUpdateIndicator {
|
|
||||||
fn ui_name() -> &'static str {
|
|
||||||
"AutoUpdateIndicator"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
|
|
||||||
if let Some(updater) = &self.updater {
|
|
||||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
|
||||||
match &updater.read(cx).status {
|
|
||||||
AutoUpdateStatus::Checking => Text::new(
|
|
||||||
"Checking for updates…".to_string(),
|
|
||||||
theme.auto_update_progress_message.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
AutoUpdateStatus::Downloading => Text::new(
|
|
||||||
"Downloading update…".to_string(),
|
|
||||||
theme.auto_update_progress_message.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
AutoUpdateStatus::Installing => Text::new(
|
|
||||||
"Installing update…".to_string(),
|
|
||||||
theme.auto_update_progress_message.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
AutoUpdateStatus::Updated => Text::new(
|
|
||||||
"Restart to update Zed".to_string(),
|
|
||||||
theme.auto_update_done_message.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
AutoUpdateStatus::Errored => {
|
|
||||||
MouseEventHandler::new::<Self, _, _>(0, cx, |_, cx| {
|
|
||||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
|
||||||
Text::new(
|
|
||||||
"Auto update failed".to_string(),
|
|
||||||
theme.auto_update_done_message.clone(),
|
|
||||||
)
|
|
||||||
.boxed()
|
|
||||||
})
|
|
||||||
.on_click(|_, _, cx| cx.dispatch_action(DismissErrorMessage))
|
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
AutoUpdateStatus::Idle => Empty::new().boxed(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Empty::new().boxed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatusItemView for AutoUpdateIndicator {
|
|
||||||
fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext<Self>) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AutoUpdateIndicator {
|
|
||||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
|
||||||
let updater = AutoUpdater::get(cx);
|
|
||||||
if let Some(updater) = &updater {
|
|
||||||
cx.observe(updater, |_, _, cx| cx.notify()).detach();
|
|
||||||
}
|
|
||||||
Self { updater }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dismiss_error_message(&mut self, _: &DismissErrorMessage, cx: &mut ViewContext<Self>) {
|
|
||||||
if let Some(updater) = &self.updater {
|
|
||||||
updater.update(cx, |updater, cx| {
|
|
||||||
updater.status = AutoUpdateStatus::Idle;
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ name = "Zed"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
activity_indicator = { path = "../activity_indicator" }
|
||||||
assets = { path = "../assets" }
|
assets = { path = "../assets" }
|
||||||
auto_update = { path = "../auto_update" }
|
auto_update = { path = "../auto_update" }
|
||||||
breadcrumbs = { path = "../breadcrumbs" }
|
breadcrumbs = { path = "../breadcrumbs" }
|
||||||
|
@ -37,7 +38,6 @@ gpui = { path = "../gpui" }
|
||||||
journal = { path = "../journal" }
|
journal = { path = "../journal" }
|
||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
lsp = { path = "../lsp" }
|
lsp = { path = "../lsp" }
|
||||||
lsp_status = { path = "../lsp_status" }
|
|
||||||
outline = { path = "../outline" }
|
outline = { path = "../outline" }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
project_panel = { path = "../project_panel" }
|
project_panel = { path = "../project_panel" }
|
||||||
|
|
|
@ -139,7 +139,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
lsp_status::init(cx);
|
activity_indicator::init(cx);
|
||||||
settings::KeymapFileContent::load_defaults(cx);
|
settings::KeymapFileContent::load_defaults(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,15 +222,14 @@ pub fn initialize_workspace(
|
||||||
|
|
||||||
let diagnostic_summary =
|
let diagnostic_summary =
|
||||||
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));
|
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));
|
||||||
let lsp_status = lsp_status::LspStatusItem::new(workspace, app_state.languages.clone(), cx);
|
let activity_indicator =
|
||||||
|
activity_indicator::ActivityIndicator::new(workspace, app_state.languages.clone(), cx);
|
||||||
let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
|
let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
|
||||||
let auto_update = cx.add_view(|cx| auto_update::AutoUpdateIndicator::new(cx));
|
|
||||||
let feedback_link = cx.add_view(|_| feedback::FeedbackLink);
|
let feedback_link = cx.add_view(|_| feedback::FeedbackLink);
|
||||||
workspace.status_bar().update(cx, |status_bar, cx| {
|
workspace.status_bar().update(cx, |status_bar, cx| {
|
||||||
status_bar.add_left_item(diagnostic_summary, cx);
|
status_bar.add_left_item(diagnostic_summary, cx);
|
||||||
status_bar.add_left_item(lsp_status, cx);
|
status_bar.add_left_item(activity_indicator, cx);
|
||||||
status_bar.add_right_item(cursor_position, cx);
|
status_bar.add_right_item(cursor_position, cx);
|
||||||
status_bar.add_right_item(auto_update, cx);
|
|
||||||
status_bar.add_right_item(feedback_link, cx);
|
status_bar.add_right_item(feedback_link, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue