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
+2 -2
View File
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;
use collections::HashMap;
use futures::{future::BoxFuture, FutureExt, StreamExt};
use gpui::MutableAppContext;
use gpui::AppContext;
use language::{LanguageRegistry, LanguageServerBinary, LanguageServerName, LspAdapter};
use node_runtime::NodeRuntime;
use serde_json::json;
@@ -125,7 +125,7 @@ impl LspAdapter for JsonLspAdapter {
fn workspace_configuration(
&self,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<BoxFuture<'static, serde_json::Value>> {
let action_names = cx.all_action_names().collect::<Vec<_>>();
let theme_names = self
+2 -2
View File
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use futures::{future::BoxFuture, FutureExt, StreamExt};
use gpui::MutableAppContext;
use gpui::AppContext;
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
use node_runtime::NodeRuntime;
use serde_json::Value;
@@ -101,7 +101,7 @@ impl LspAdapter for YamlLspAdapter {
fn workspace_configuration(
&self,
cx: &mut MutableAppContext,
cx: &mut AppContext,
) -> Option<BoxFuture<'static, Value>> {
let settings = cx.global::<Settings>();
Some(
+2 -2
View File
@@ -14,7 +14,7 @@ use futures::{
channel::{mpsc, oneshot},
FutureExt, SinkExt, StreamExt,
};
use gpui::{Action, App, AssetSource, AsyncAppContext, MutableAppContext, Task, ViewContext};
use gpui::{Action, App, AppContext, AssetSource, AsyncAppContext, Task, ViewContext};
use isahc::{config::Configurable, Request};
use language::LanguageRegistry;
use log::LevelFilter;
@@ -370,7 +370,7 @@ fn init_panic_hook(app_version: String) {
}));
}
fn upload_previous_panics(http: Arc<dyn HttpClient>, cx: &mut MutableAppContext) {
fn upload_previous_panics(http: Arc<dyn HttpClient>, cx: &mut AppContext) {
let diagnostics_telemetry = cx.global::<Settings>().telemetry_diagnostics();
cx.background()
+38 -21
View File
@@ -72,16 +72,16 @@ actions!(
const MIN_FONT_SIZE: f32 = 6.0;
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
terminal_button::init(cx);
cx.add_action(about);
cx.add_global_action(|_: &Hide, cx: &mut gpui::MutableAppContext| {
cx.add_global_action(|_: &Hide, cx: &mut gpui::AppContext| {
cx.platform().hide();
});
cx.add_global_action(|_: &HideOthers, cx: &mut gpui::MutableAppContext| {
cx.add_global_action(|_: &HideOthers, cx: &mut gpui::AppContext| {
cx.platform().hide_other_apps();
});
cx.add_global_action(|_: &ShowAll, cx: &mut gpui::MutableAppContext| {
cx.add_global_action(|_: &ShowAll, cx: &mut gpui::AppContext| {
cx.platform().unhide_other_apps();
});
cx.add_action(
@@ -367,10 +367,10 @@ pub fn build_window_options(
}
}
fn restart(_: &Restart, cx: &mut gpui::MutableAppContext) {
fn restart(_: &Restart, cx: &mut gpui::AppContext) {
let mut workspaces = cx
.window_ids()
.filter_map(|window_id| cx.root_view::<Workspace>(window_id))
.filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>())
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
@@ -411,10 +411,10 @@ fn restart(_: &Restart, cx: &mut gpui::MutableAppContext) {
.detach_and_log_err(cx);
}
fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
fn quit(_: &Quit, cx: &mut gpui::AppContext) {
let mut workspaces = cx
.window_ids()
.filter_map(|window_id| cx.root_view::<Workspace>(window_id))
.filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>())
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
@@ -656,9 +656,7 @@ mod tests {
use super::*;
use assets::Assets;
use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor};
use gpui::{
executor::Deterministic, AssetSource, MutableAppContext, TestAppContext, ViewHandle,
};
use gpui::{executor::Deterministic, AppContext, AssetSource, TestAppContext, ViewHandle};
use language::LanguageRegistry;
use node_runtime::NodeRuntime;
use project::{Project, ProjectPath};
@@ -717,7 +715,11 @@ mod tests {
cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, None, cx))
.await;
assert_eq!(cx.window_ids().len(), 1);
let workspace_1 = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap();
let workspace_1 = cx
.root_view(cx.window_ids()[0])
.unwrap()
.downcast::<Workspace>()
.unwrap();
workspace_1.update(cx, |workspace, cx| {
assert_eq!(workspace.worktrees(cx).count(), 2);
assert!(workspace.left_sidebar().read(cx).is_open());
@@ -747,7 +749,12 @@ mod tests {
})
.await;
assert_eq!(cx.window_ids().len(), 2);
let workspace_1 = cx.root_view::<Workspace>(window_id).unwrap();
let workspace_1 = cx
.root_view(window_id)
.unwrap()
.clone()
.downcast::<Workspace>()
.unwrap();
workspace_1.read_with(cx, |workspace, cx| {
assert_eq!(
workspace
@@ -775,7 +782,12 @@ mod tests {
assert_eq!(cx.window_ids().len(), 1);
// When opening the workspace, the window is not in a edited state.
let workspace = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap();
let workspace = cx
.root_view(cx.window_ids()[0])
.unwrap()
.clone()
.downcast::<Workspace>()
.unwrap();
let editor = workspace.read_with(cx, |workspace, cx| {
workspace
.active_item(cx)
@@ -842,7 +854,12 @@ mod tests {
.await;
let window_id = *cx.window_ids().first().unwrap();
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
let workspace = cx
.root_view(window_id)
.unwrap()
.clone()
.downcast::<Workspace>()
.unwrap();
let editor = workspace.update(cx, |workspace, cx| {
workspace
.active_item(cx)
@@ -950,7 +967,7 @@ mod tests {
.read(cx)
.active_item()
.unwrap()
.project_path(cx.as_ref()),
.project_path(cx),
Some(file2.clone())
);
});
@@ -1251,7 +1268,7 @@ mod tests {
// Edit the file and save it again. This time, there is no filename prompt.
editor.update(cx, |editor, cx| {
editor.handle_input(" there", cx);
assert!(editor.is_dirty(cx.as_ref()));
assert!(editor.is_dirty(cx));
});
let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(false, cx));
save_task.await.unwrap();
@@ -1311,7 +1328,7 @@ mod tests {
&languages::PLAIN_TEXT
));
editor.handle_input("hi", cx);
assert!(editor.is_dirty(cx.as_ref()));
assert!(editor.is_dirty(cx));
});
// Save the buffer. This prompts for a filename.
@@ -1374,7 +1391,7 @@ mod tests {
assert_ne!(pane_1, pane_2);
let pane2_item = pane_2.read(cx).active_item().unwrap();
assert_eq!(pane2_item.project_path(cx.as_ref()), Some(file1.clone()));
assert_eq!(pane2_item.project_path(cx), Some(file1.clone()));
pane2_item.downcast::<Editor>().unwrap().downgrade()
});
@@ -1819,7 +1836,7 @@ mod tests {
}
#[gpui::test]
fn test_bundled_settings_and_themes(cx: &mut MutableAppContext) {
fn test_bundled_settings_and_themes(cx: &mut AppContext) {
cx.platform()
.fonts()
.add_fonts(&[
@@ -1850,7 +1867,7 @@ mod tests {
}
#[gpui::test]
fn test_bundled_languages(cx: &mut MutableAppContext) {
fn test_bundled_languages(cx: &mut AppContext) {
let mut languages = LanguageRegistry::test();
languages.set_executor(cx.background().clone());
let languages = Arc::new(languages);