Merge MutableAppContext into AppContext

There may have been a good reason for the difference at some point, or I was
still learning Rust. But now it's just &mut AppContext vs &AppContext.
This commit is contained in:
Nathan Sobo
2023-04-06 15:49:03 -06:00
parent dd00966cc6
commit de9bf6dfbd
112 changed files with 882 additions and 1041 deletions
+4 -4
View File
@@ -2,7 +2,7 @@ use crate::{parse_json_with_comments, Settings};
use anyhow::{Context, Result};
use assets::Assets;
use collections::BTreeMap;
use gpui::{keymap_matcher::Binding, MutableAppContext};
use gpui::{keymap_matcher::Binding, AppContext};
use schemars::{
gen::{SchemaGenerator, SchemaSettings},
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation},
@@ -41,7 +41,7 @@ impl JsonSchema for KeymapAction {
struct ActionWithData(Box<str>, Box<RawValue>);
impl KeymapFileContent {
pub fn load_defaults(cx: &mut MutableAppContext) {
pub fn load_defaults(cx: &mut AppContext) {
for path in ["keymaps/default.json", "keymaps/vim.json"] {
Self::load(path, cx).unwrap();
}
@@ -51,13 +51,13 @@ impl KeymapFileContent {
}
}
pub fn load(asset_path: &str, cx: &mut MutableAppContext) -> Result<()> {
pub fn load(asset_path: &str, cx: &mut AppContext) -> Result<()> {
let content = Assets::get(asset_path).unwrap().data;
let content_str = std::str::from_utf8(content.as_ref()).unwrap();
parse_json_with_comments::<Self>(content_str)?.add_to_cx(cx)
}
pub fn add_to_cx(self, cx: &mut MutableAppContext) -> Result<()> {
pub fn add_to_cx(self, cx: &mut AppContext) -> Result<()> {
for KeymapBlock { context, bindings } in self.0 {
let bindings = bindings
.into_iter()
+3 -3
View File
@@ -2,7 +2,7 @@ use crate::{update_settings_file, watched_json::WatchedJsonFile, SettingsFileCon
use anyhow::Result;
use assets::Assets;
use fs::Fs;
use gpui::{AssetSource, MutableAppContext};
use gpui::{AppContext, AssetSource};
use std::{io::ErrorKind, path::Path, sync::Arc};
// TODO: Switch SettingsFile to open a worktree and buffer for synchronization
@@ -49,7 +49,7 @@ impl SettingsFile {
}
pub fn update(
cx: &mut MutableAppContext,
cx: &mut AppContext,
update: impl 'static + Send + FnOnce(&mut SettingsFileContent),
) {
let this = cx.global::<SettingsFile>();
@@ -211,7 +211,7 @@ mod tests {
}
fn assert_key_bindings_for<'a>(
cx: &mut MutableAppContext,
cx: &mut AppContext,
actions: Vec<(&'static str, &'a dyn Action)>,
line: u32,
) {
+6 -6
View File
@@ -1,6 +1,6 @@
use fs::Fs;
use futures::StreamExt;
use gpui::{executor, MutableAppContext};
use gpui::{executor, AppContext};
use postage::sink::Sink as _;
use postage::{prelude::Stream, watch};
use serde::Deserialize;
@@ -67,7 +67,7 @@ pub fn watch_files(
settings_file: WatchedJsonFile<SettingsFileContent>,
theme_registry: Arc<ThemeRegistry>,
keymap_file: WatchedJsonFile<KeymapFileContent>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
watch_settings_file(defaults, settings_file, theme_registry, cx);
watch_keymap_file(keymap_file, cx);
@@ -77,7 +77,7 @@ pub(crate) fn watch_settings_file(
defaults: Settings,
mut file: WatchedJsonFile<SettingsFileContent>,
theme_registry: Arc<ThemeRegistry>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
settings_updated(&defaults, file.0.borrow().clone(), &theme_registry, cx);
cx.spawn(|mut cx| async move {
@@ -88,7 +88,7 @@ pub(crate) fn watch_settings_file(
.detach();
}
fn keymap_updated(content: KeymapFileContent, cx: &mut MutableAppContext) {
fn keymap_updated(content: KeymapFileContent, cx: &mut AppContext) {
cx.clear_bindings();
KeymapFileContent::load_defaults(cx);
content.add_to_cx(cx).log_err();
@@ -98,7 +98,7 @@ fn settings_updated(
defaults: &Settings,
content: SettingsFileContent,
theme_registry: &Arc<ThemeRegistry>,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) {
let mut settings = defaults.clone();
settings.set_user_settings(content, theme_registry, cx.font_cache());
@@ -106,7 +106,7 @@ fn settings_updated(
cx.refresh_windows();
}
fn watch_keymap_file(mut file: WatchedJsonFile<KeymapFileContent>, cx: &mut MutableAppContext) {
fn watch_keymap_file(mut file: WatchedJsonFile<KeymapFileContent>, cx: &mut AppContext) {
cx.spawn(|mut cx| async move {
let mut settings_subscription = None;
while let Some(content) = file.0.recv().await {