Delete theme files more selectively when regenerating them

Max Brunsfeld created

Avoid deleting files that will be rewritten later, so that Zed
won't observe states where themes are missing if two zed
processes are running at once.

Change summary

crates/zed/src/main.rs    | 2 +-
styles/src/buildThemes.ts | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)

Detailed changes

crates/zed/src/main.rs 🔗

@@ -449,7 +449,7 @@ async fn watch_themes(
     mut cx: AsyncAppContext,
 ) -> Option<()> {
     let mut events = fs
-        .watch("styles/src".as_ref(), Duration::from_millis(250))
+        .watch("styles/src".as_ref(), Duration::from_millis(100))
         .await;
     while let Some(_) = events.next().await {
         let output = Command::new("npm")

styles/src/buildThemes.ts 🔗

@@ -11,7 +11,10 @@ const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), 'build-themes'));
 // Clear existing themes
 for (const file of fs.readdirSync(themeDirectory)) {
   if (file.endsWith('.json')) {
-    fs.unlinkSync(path.join(themeDirectory, file));
+    const name = file.replace(/\.json$/, '');
+    if (!themes.find(theme => theme.name === name)) {
+      fs.unlinkSync(path.join(themeDirectory, file));
+    }
   }
 }