Show message indicating when we're downloading language servers

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-02-21 17:25:52 +01:00
parent d2c83a7097
commit aee479d615
16 changed files with 214 additions and 93 deletions

View file

@ -0,0 +1,65 @@
use crate::{ItemViewHandle, Settings, StatusItemView};
use futures::StreamExt;
use gpui::{elements::*, Entity, RenderContext, View, ViewContext};
use language::LanguageRegistry;
use postage::watch;
use std::sync::Arc;
pub struct LspStatus {
pending_lsp_binaries: usize,
settings_rx: watch::Receiver<Settings>,
}
impl LspStatus {
pub fn new(
languages: Arc<LanguageRegistry>,
settings_rx: watch::Receiver<Settings>,
cx: &mut ViewContext<Self>,
) -> Self {
let mut pending_lsp_binaries = languages.pending_lsp_binaries();
cx.spawn_weak(|this, mut cx| async move {
while let Some(pending_lsp_binaries) = pending_lsp_binaries.next().await {
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| {
this.pending_lsp_binaries = pending_lsp_binaries;
cx.notify();
});
} else {
break;
}
}
})
.detach();
Self {
pending_lsp_binaries: 0,
settings_rx,
}
}
}
impl Entity for LspStatus {
type Event = ();
}
impl View for LspStatus {
fn ui_name() -> &'static str {
"LspStatus"
}
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
if self.pending_lsp_binaries == 0 {
Empty::new().boxed()
} else {
let theme = &self.settings_rx.borrow().theme;
Label::new(
"Downloading language servers...".to_string(),
theme.workspace.status_bar.lsp_message.clone(),
)
.boxed()
}
}
}
impl StatusItemView for LspStatus {
fn set_active_pane_item(&mut self, _: Option<&dyn ItemViewHandle>, _: &mut ViewContext<Self>) {}
}

View file

@ -42,17 +42,21 @@ impl View for StatusBar {
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
let theme = &self.settings.borrow().theme.workspace.status_bar;
Flex::row()
.with_children(
self.left_items
.iter()
.map(|i| ChildView::new(i.as_ref()).aligned().boxed()),
)
.with_children(self.left_items.iter().map(|i| {
ChildView::new(i.as_ref())
.aligned()
.contained()
.with_margin_right(theme.item_spacing)
.boxed()
}))
.with_child(Empty::new().flexible(1., true).boxed())
.with_children(
self.right_items
.iter()
.map(|i| ChildView::new(i.as_ref()).aligned().boxed()),
)
.with_children(self.right_items.iter().map(|i| {
ChildView::new(i.as_ref())
.aligned()
.contained()
.with_margin_left(theme.item_spacing)
.boxed()
}))
.contained()
.with_style(theme.container)
.constrained()

View file

@ -1,3 +1,4 @@
pub mod lsp_status;
pub mod menu;
pub mod pane;
pub mod pane_group;