Distributed database pattern built.

Co-Authored-By: kay@zed.dev
This commit is contained in:
Mikayla Maki 2022-11-14 13:18:44 -08:00
parent 2a5565ca93
commit 4798161118
28 changed files with 893 additions and 937 deletions

View file

@ -23,7 +23,7 @@ use isahc::{config::Configurable, Request};
use language::LanguageRegistry;
use log::LevelFilter;
use parking_lot::Mutex;
use project::{Db, Fs, HomeDir, ProjectStore};
use project::{Fs, HomeDir, ProjectStore};
use serde_json::json;
use settings::{
self, settings_file::SettingsFile, KeymapFileContent, Settings, SettingsFileContent,
@ -37,12 +37,9 @@ use terminal::terminal_container_view::{get_working_directory, TerminalContainer
use fs::RealFs;
use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile};
use theme::ThemeRegistry;
use util::{paths, ResultExt, TryFutureExt};
use util::{channel::RELEASE_CHANNEL, paths, ResultExt, TryFutureExt};
use workspace::{self, AppState, ItemHandle, NewFile, OpenPaths, Workspace};
use zed::{
self, build_window_options, initialize_workspace, languages, menus, RELEASE_CHANNEL,
RELEASE_CHANNEL_NAME,
};
use zed::{self, build_window_options, initialize_workspace, languages, menus};
fn main() {
let http = http::client();
@ -56,10 +53,6 @@ fn main() {
.map_or("dev".to_string(), |v| v.to_string());
init_panic_hook(app_version, http.clone(), app.background());
let db = app.background().spawn(async move {
project::Db::<project::KeyValue>::open(&*paths::DB_DIR, RELEASE_CHANNEL_NAME.as_str())
});
load_embedded_fonts(&app);
let fs = Arc::new(RealFs);
@ -147,10 +140,8 @@ fn main() {
.detach();
let project_store = cx.add_model(|_| ProjectStore::new());
let db = cx.background().block(db);
cx.set_global(db);
client.start_telemetry(cx.global::<Db<project::KeyValue>>().clone());
client.start_telemetry();
client.report_event("start app", Default::default());
let app_state = Arc::new(AppState {
@ -164,16 +155,9 @@ fn main() {
initialize_workspace,
default_item_factory,
});
auto_update::init(
cx.global::<Db<project::KeyValue>>().clone(),
http,
client::ZED_SERVER_URL.clone(),
cx,
);
auto_update::init(http, client::ZED_SERVER_URL.clone(), cx);
let workspace_db = cx.global::<Db<project::KeyValue>>().open_as::<Workspace>();
workspace::init(app_state.clone(), cx, workspace_db);
workspace::init(app_state.clone(), cx);
journal::init(app_state.clone(), cx);
theme_selector::init(app_state.clone(), cx);

View file

@ -12,7 +12,6 @@ use collab_ui::{CollabTitlebarItem, ToggleCollaborationMenu};
use collections::VecDeque;
pub use editor;
use editor::{Editor, MultiBuffer};
use lazy_static::lazy_static;
use gpui::{
actions,
@ -28,9 +27,9 @@ use project_panel::ProjectPanel;
use search::{BufferSearchBar, ProjectSearchBar};
use serde::Deserialize;
use serde_json::to_string_pretty;
use settings::{keymap_file_json_schema, settings_file_json_schema, ReleaseChannel, Settings};
use settings::{keymap_file_json_schema, settings_file_json_schema, Settings};
use std::{env, path::Path, str, sync::Arc};
use util::{paths, ResultExt};
use util::{channel::ReleaseChannel, paths, ResultExt};
pub use workspace;
use workspace::{sidebar::SidebarSide, AppState, Workspace};
@ -69,17 +68,6 @@ actions!(
const MIN_FONT_SIZE: f32 = 6.0;
lazy_static! {
pub static ref RELEASE_CHANNEL_NAME: String =
env::var("ZED_RELEASE_CHANNEL").unwrap_or(include_str!("../RELEASE_CHANNEL").to_string());
pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str() {
"dev" => ReleaseChannel::Dev,
"preview" => ReleaseChannel::Preview,
"stable" => ReleaseChannel::Stable,
_ => panic!("invalid release channel {}", *RELEASE_CHANNEL_NAME),
};
}
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_action(about);
cx.add_global_action(|_: &Hide, cx: &mut gpui::MutableAppContext| {
@ -629,7 +617,7 @@ mod tests {
use gpui::{
executor::Deterministic, AssetSource, MutableAppContext, TestAppContext, ViewHandle,
};
use project::{Db, Project, ProjectPath};
use project::{Project, ProjectPath};
use serde_json::json;
use std::{
collections::HashSet,
@ -774,6 +762,8 @@ mod tests {
async fn test_new_empty_workspace(cx: &mut TestAppContext) {
let app_state = init(cx);
cx.dispatch_global_action(workspace::NewFile);
cx.foreground().run_until_parked();
let window_id = *cx.window_ids().first().unwrap();
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
let editor = workspace.update(cx, |workspace, cx| {
@ -1816,7 +1806,7 @@ mod tests {
state.initialize_workspace = initialize_workspace;
state.build_window_options = build_window_options;
call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
workspace::init(app_state.clone(), cx, Db::open_in_memory("test"));
workspace::init(app_state.clone(), cx);
editor::init(cx);
pane::init(cx);
app_state