Fix for toggles on the Welcome page (#8159)

Uladzislau Kaminski , Thorsten Ball , and Marshall created

Release Notes:

The issue is that when welcome page appears settings.json file is not
created yet. So the idea of this fix is to create the file in case it is
not there yet.

- Fixed the toggles on the welcome screen not working if no settings
file exists yet.
([#8153](https://github.com/zed-industries/zed/issues/8153)).

---------

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Marshall <marshall@zed.dev>

Change summary

crates/settings/src/settings_file.rs | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

Detailed changes

crates/settings/src/settings_file.rs 🔗

@@ -116,13 +116,20 @@ pub fn update_settings_file<T: Settings>(
             store.new_text_for_update::<T>(old_text, update)
         })?;
         let initial_path = paths::SETTINGS.as_path();
-        let resolved_path = fs
-            .canonicalize(initial_path)
-            .await
-            .with_context(|| format!("Failed to canonicalize settings path {:?}", initial_path))?;
-        fs.atomic_write(resolved_path.clone(), new_text)
-            .await
-            .with_context(|| format!("Failed to write settings to file {:?}", resolved_path))?;
+        if !fs.is_file(initial_path).await {
+            fs.atomic_write(initial_path.to_path_buf(), new_text)
+                .await
+                .with_context(|| format!("Failed to write settings to file {:?}", initial_path))?;
+        } else {
+            let resolved_path = fs.canonicalize(initial_path).await.with_context(|| {
+                format!("Failed to canonicalize settings path {:?}", initial_path)
+            })?;
+
+            fs.atomic_write(resolved_path.clone(), new_text)
+                .await
+                .with_context(|| format!("Failed to write settings to file {:?}", resolved_path))?;
+        }
+
         anyhow::Ok(())
     })
     .detach_and_log_err(cx);