From fbacc126727a9dbbae621ee966399d857d897277 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 18 May 2022 14:17:26 -0700 Subject: [PATCH] Delete theme files more selectively when regenerating them 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. --- crates/zed/src/main.rs | 2 +- styles/src/buildThemes.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 8531525891255b098b62cb01e4d1c4f1d19fbbad..54691f2254a7b5d0fed4b0efe25a936bc866754a 100644 --- a/crates/zed/src/main.rs +++ b/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") diff --git a/styles/src/buildThemes.ts b/styles/src/buildThemes.ts index dad56046a9fba08dae0fa5c2a6c5e30022479542..c43be067a869f37e7b39bda62cbe0dd7d6f81fd3 100644 --- a/styles/src/buildThemes.ts +++ b/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)); + } } }