Undid change to paths variables and cleaned up leftovers

Mikayla Maki created

Change summary

Cargo.lock                                  | 11 --
constellation.txt                           | 10 --
crates/paths/Cargo.toml                     | 12 ---
crates/theme_selector/Cargo.toml            |  1 
crates/theme_selector/src/theme_selector.rs | 92 ----------------------
crates/zed/Cargo.toml                       |  2 
crates/zed/src/main.rs                      | 39 +++++----
crates/zed/src/paths.rs                     |  0 
crates/zed/src/zed.rs                       |  1 
9 files changed, 27 insertions(+), 141 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -3738,14 +3738,6 @@ dependencies = [
  "rustc_version",
 ]
 
-[[package]]
-name = "paths"
-version = "0.1.0"
-dependencies = [
- "dirs 3.0.2",
- "lazy_static",
-]
-
 [[package]]
 name = "pbkdf2"
 version = "0.8.0"
@@ -5637,7 +5629,6 @@ dependencies = [
  "gpui",
  "log",
  "parking_lot 0.11.2",
- "paths",
  "picker",
  "postage",
  "settings",
@@ -7263,6 +7254,7 @@ dependencies = [
  "context_menu",
  "ctor",
  "diagnostics",
+ "dirs 3.0.2",
  "easy-parallel",
  "editor",
  "env_logger",
@@ -7285,7 +7277,6 @@ dependencies = [
  "num_cpus",
  "outline",
  "parking_lot 0.11.2",
- "paths",
  "plugin_runtime",
  "postage",
  "project",

constellation.txt 🔗

@@ -1,10 +0,0 @@
-Burn down pain points constellation
-
----------------------
-|                   | 
-|             *     | Mikayla
-|     *             | Julia
-|                   |
-|              *    | Kay
-|                   |
----------------------

crates/paths/Cargo.toml 🔗

@@ -1,12 +0,0 @@
-[package]
-name = "paths"
-version = "0.1.0"
-edition = "2021"
-
-[lib]
-path = "src/paths.rs"
-
-[dependencies]
-lazy_static = "1.4.0"
-dirs = "3.0"
-

crates/theme_selector/Cargo.toml 🔗

@@ -14,7 +14,6 @@ gpui = { path = "../gpui" }
 picker = { path = "../picker" }
 theme = { path = "../theme" }
 settings = { path = "../settings" }
-paths = { path = "../paths" }
 workspace = { path = "../workspace" }
 log = { version = "0.4.16", features = ["kv_unstable_serde"] }
 parking_lot = "0.11.1"

crates/theme_selector/src/theme_selector.rs 🔗

@@ -1,12 +1,10 @@
 use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
 use gpui::{
-    actions, anyhow::Result, elements::*, AnyViewHandle, AppContext, Element, ElementBox, Entity,
-    MouseState, MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
+    actions, elements::*, AnyViewHandle, AppContext, Element, ElementBox, Entity, MouseState,
+    MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
 };
-use paths::SETTINGS;
 use picker::{Picker, PickerDelegate};
-use settings::{write_theme, Settings};
-use smol::{fs::read_to_string, io::AsyncWriteExt};
+use settings::Settings;
 use std::sync::Arc;
 use theme::{Theme, ThemeMeta, ThemeRegistry};
 use workspace::{AppState, Workspace};
@@ -111,75 +109,6 @@ impl ThemeSelector {
             match self.registry.get(&mat.string) {
                 Ok(theme) => {
                     Self::set_theme(theme, cx);
-
-                    let theme_name = mat.string.clone();
-
-                    // cx.global::<SettingsLock()>
-                    // cx.global::<SettingsFile>() // lock
-
-                    // 1) Truncation can cause data loss, make it atomic by creating tmp file and moving
-                    // 2) Maybe firing too often? Conceptually want to commit
-                    // Having a lock on the settings file
-
-                    //    -
-                    //   | |
-                    // FS _
-
-                    // General problem: whenever we want to persist stuff
-                    // In memory representation -> File on disk
-                    // Write font size,
-                    // Write theme to disk
-                    // Write -> See your own write -> Another Write
-
-                    // Memory Write 1 -> Write To Disk 1, | Memory Write 2,
-                    //                                    Blocking ->>>>>> | Read From Disk 1,
-                    //                                    Discard          | Read WHATEVER is from disk |
-
-                    // Blocking lock ->
-
-                    // Whenever we update the settings in memory, we enqueue a write to disk
-                    // When we receive a file system event, we only honor it if all pending disk writes are complete.
-
-                    // When the settings become dirty in memory, schedule a write to disk
-                    // When we are sure the write is completed, consider the settings clean
-                    // Only read settings from disk into memory when in memory settings are clean
-                    // read settings just does not happen, if the settings are dirty
-
-                    // 10 settings queued up:
-                    // lock() -> Only needs to be on the file
-                    // How to set a setting:
-                    // write to memory
-                    // Read the whole file from disk
-                    // Surgically inject the setting string
-                    // Write to disk
-                    // unlock()
-
-                    // Write 10 x change font size
-                    // Read-open-write font size
-                    // Read-open-write font size
-                    // Read-open-write font size
-                    // Read-open-write font size
-                    // Read-open-write font size
-                    // ..
-                    // Read from file system, only gets the latest font size and uselessly sets font size
-
-                    // `SettingsFile`
-                    // You can non-blocking, write to it as much as you need
-                    // Debounces your changes, waits for you to be done, and then flushes them all to the file system
-                    // And blocks the read
-
-                    // Read and write to memory. ^ up from the file system
-
-                    // If there's pendings writes, we need to wait until this whole thing is done'
-
-                    cx.background()
-                        .spawn(async move {
-                            match write_theme_name(theme_name).await {
-                                Ok(_) => {}
-                                Err(_) => return, //TODO Pop toast
-                            }
-                        })
-                        .detach()
                 }
                 Err(error) => {
                     log::error!("error loading theme {}: {}", mat.string, error)
@@ -337,18 +266,3 @@ impl View for ThemeSelector {
         }
     }
 }
-
-async fn write_theme_name(theme_name: String) -> Result<()> {
-    let mut settings = read_to_string(SETTINGS.as_path()).await?;
-    settings = write_theme(settings, &theme_name);
-
-    let mut file = smol::fs::OpenOptions::new()
-        .truncate(true)
-        .write(true)
-        .open(SETTINGS.as_path())
-        .await?;
-
-    file.write_all(settings.as_bytes()).await?;
-
-    Ok(())
-}

crates/zed/Cargo.toml 🔗

@@ -40,7 +40,6 @@ journal = { path = "../journal" }
 language = { path = "../language" }
 lsp = { path = "../lsp" }
 outline = { path = "../outline" }
-paths = { path = "../paths" }
 plugin_runtime = { path = "../plugin_runtime" }
 project = { path = "../project" }
 project_panel = { path = "../project_panel" }
@@ -62,6 +61,7 @@ async-trait = "0.1"
 backtrace = "0.3"
 chrono = "0.4"
 ctor = "0.1.20"
+dirs = "3.0"
 easy-parallel = "3.1.0"
 env_logger = "0.9"
 futures = "0.3"

crates/zed/src/main.rs 🔗

@@ -53,7 +53,7 @@ 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::open(&*paths::DB)
+        project::Db::open(&*zed::paths::DB)
             .log_err()
             .unwrap_or_else(project::Db::null)
     });
@@ -90,7 +90,7 @@ fn main() {
     app.run(move |cx| {
         let client = client::Client::new(http.clone(), cx);
         let mut languages = LanguageRegistry::new(login_shell_env_loaded);
-        languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
+        languages.set_language_server_download_dir(zed::paths::LANGUAGES_DIR.clone());
         let languages = Arc::new(languages);
         let init_languages = cx
             .background()
@@ -200,21 +200,23 @@ fn main() {
 }
 
 fn init_paths() {
-    fs::create_dir_all(&*paths::CONFIG_DIR).expect("could not create config path");
-    fs::create_dir_all(&*paths::LANGUAGES_DIR).expect("could not create languages path");
-    fs::create_dir_all(&*paths::DB_DIR).expect("could not create database path");
-    fs::create_dir_all(&*paths::LOGS_DIR).expect("could not create logs path");
+    fs::create_dir_all(&*zed::paths::CONFIG_DIR).expect("could not create config path");
+    fs::create_dir_all(&*zed::paths::LANGUAGES_DIR).expect("could not create languages path");
+    fs::create_dir_all(&*zed::paths::DB_DIR).expect("could not create database path");
+    fs::create_dir_all(&*zed::paths::LOGS_DIR).expect("could not create logs path");
 
     // Copy setting files from legacy locations. TODO: remove this after a few releases.
     thread::spawn(|| {
-        if fs::metadata(&*paths::legacy::SETTINGS).is_ok()
-            && fs::metadata(&*paths::SETTINGS).is_err()
+        if fs::metadata(&*zed::paths::legacy::SETTINGS).is_ok()
+            && fs::metadata(&*zed::paths::SETTINGS).is_err()
         {
-            fs::copy(&*paths::legacy::SETTINGS, &*paths::SETTINGS).log_err();
+            fs::copy(&*zed::paths::legacy::SETTINGS, &*zed::paths::SETTINGS).log_err();
         }
 
-        if fs::metadata(&*paths::legacy::KEYMAP).is_ok() && fs::metadata(&*paths::KEYMAP).is_err() {
-            fs::copy(&*paths::legacy::KEYMAP, &*paths::KEYMAP).log_err();
+        if fs::metadata(&*zed::paths::legacy::KEYMAP).is_ok()
+            && fs::metadata(&*zed::paths::KEYMAP).is_err()
+        {
+            fs::copy(&*zed::paths::legacy::KEYMAP, &*zed::paths::KEYMAP).log_err();
         }
     });
 }
@@ -229,14 +231,15 @@ fn init_logger() {
         const KIB: u64 = 1024;
         const MIB: u64 = 1024 * KIB;
         const MAX_LOG_BYTES: u64 = MIB;
-        if fs::metadata(&*paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES) {
-            let _ = fs::rename(&*paths::LOG, &*paths::OLD_LOG);
+        if fs::metadata(&*zed::paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES)
+        {
+            let _ = fs::rename(&*zed::paths::LOG, &*zed::paths::OLD_LOG);
         }
 
         let log_file = OpenOptions::new()
             .create(true)
             .append(true)
-            .open(&*paths::LOG)
+            .open(&*zed::paths::LOG)
             .expect("could not open logfile");
         simplelog::WriteLogger::init(level, simplelog::Config::default(), log_file)
             .expect("could not initialize logger");
@@ -248,7 +251,7 @@ fn init_panic_hook(app_version: String, http: Arc<dyn HttpClient>, background: A
         .spawn({
             async move {
                 let panic_report_url = format!("{}/api/panic", &*client::ZED_SERVER_URL);
-                let mut children = smol::fs::read_dir(&*paths::LOGS_DIR).await?;
+                let mut children = smol::fs::read_dir(&*zed::paths::LOGS_DIR).await?;
                 while let Some(child) = children.next().await {
                     let child = child?;
                     let child_path = child.path();
@@ -336,7 +339,7 @@ fn init_panic_hook(app_version: String, http: Arc<dyn HttpClient>, background: A
 
         let panic_filename = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
         fs::write(
-            paths::LOGS_DIR.join(format!("zed-{}-{}.panic", app_version, panic_filename)),
+            zed::paths::LOGS_DIR.join(format!("zed-{}-{}.panic", app_version, panic_filename)),
             &message,
         )
         .context("error writing panic to disk")
@@ -470,8 +473,8 @@ fn load_config_files(
         .clone()
         .spawn(async move {
             let settings_file =
-                WatchedJsonFile::new(fs.clone(), &executor, paths::SETTINGS.clone()).await;
-            let keymap_file = WatchedJsonFile::new(fs, &executor, paths::KEYMAP.clone()).await;
+                WatchedJsonFile::new(fs.clone(), &executor, zed::paths::SETTINGS.clone()).await;
+            let keymap_file = WatchedJsonFile::new(fs, &executor, zed::paths::KEYMAP.clone()).await;
             tx.send((settings_file, keymap_file)).ok()
         })
         .detach();

crates/zed/src/zed.rs 🔗

@@ -2,6 +2,7 @@ mod feedback;
 pub mod languages;
 pub mod menus;
 pub mod settings_file;
+pub mod paths;
 #[cfg(any(test, feature = "test-support"))]
 pub mod test;