From 03bd6d6c333c76d806f36075155eab866174525f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 24 Nov 2021 16:04:24 +0100 Subject: [PATCH] Pull up diagnostic and cursor position status bar items creation --- crates/workspace/Cargo.toml | 1 + crates/workspace/src/lib.rs | 19 +++++++------------ crates/zed/src/lib.rs | 10 ++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index a96eb23aaf..9368f822ae 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -27,6 +27,7 @@ tree-sitter-rust = { version = "0.19.0", optional = true } [dev-dependencies] client = { path = "../client", features = ["test-support"] } +gpui = { path = "../gpui", features = ["test-support"] } project = { path = "../project", features = ["test-support"] } serde_json = { version = "1.0.64", features = ["preserve_order"] } tree-sitter = "0.19.5" diff --git a/crates/workspace/src/lib.rs b/crates/workspace/src/lib.rs index 1073ea96a5..d98d07a75e 100644 --- a/crates/workspace/src/lib.rs +++ b/crates/workspace/src/lib.rs @@ -1,4 +1,4 @@ -mod items; +pub mod items; pub mod pane; pub mod pane_group; pub mod settings; @@ -20,6 +20,7 @@ use postage::{prelude::Stream, watch}; use project::{Fs, Project, ProjectPath, Worktree}; pub use settings::Settings; use sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus}; +use status_bar::StatusBar; use std::{ collections::{hash_map::Entry, HashMap}, future::Future, @@ -27,8 +28,6 @@ use std::{ sync::Arc, }; -use crate::status_bar::StatusBar; - action!(OpenNew, WorkspaceParams); action!(Save); action!(DebugElements); @@ -382,15 +381,7 @@ impl Workspace { .detach(); cx.focus(&pane); - let cursor_position = cx.add_view(|_| items::CursorPosition::new(params.settings.clone())); - let diagnostic = cx.add_view(|_| items::DiagnosticMessage::new(params.settings.clone())); - let status_bar = cx.add_view(|cx| { - let mut status_bar = StatusBar::new(&pane, params.settings.clone(), cx); - status_bar.add_left_item(diagnostic, cx); - status_bar.add_right_item(cursor_position, cx); - status_bar - }); - + let status_bar = cx.add_view(|cx| StatusBar::new(&pane, params.settings.clone(), cx)); let mut current_user = params.user_store.read(cx).watch_current_user().clone(); let mut connection_status = params.client.status().clone(); let _observe_current_user = cx.spawn_weak(|this, mut cx| async move { @@ -436,6 +427,10 @@ impl Workspace { &mut self.right_sidebar } + pub fn status_bar(&self) -> &ViewHandle { + &self.status_bar + } + pub fn project(&self) -> &ModelHandle { &self.project } diff --git a/crates/zed/src/lib.rs b/crates/zed/src/lib.rs index cbc8ef803d..d3fed8c524 100644 --- a/crates/zed/src/lib.rs +++ b/crates/zed/src/lib.rs @@ -161,6 +161,16 @@ fn build_workspace(params: &WorkspaceParams, cx: &mut ViewContext) -> }) .into(), ); + + let diagnostic = + cx.add_view(|_| workspace::items::DiagnosticMessage::new(params.settings.clone())); + let cursor_position = + cx.add_view(|_| workspace::items::CursorPosition::new(params.settings.clone())); + workspace.status_bar().update(cx, |status_bar, cx| { + status_bar.add_left_item(diagnostic, cx); + status_bar.add_right_item(cursor_position, cx); + }); + workspace }