zed: Fix formatting in workspace initialization (#22152)
This PR fixes some formatting issues in the workspace initialization code that stemmed from certain constructs causing `rustfmt` to bail out of the formatting. The bulk of the content of `initialize_workspace` has been factored out into functions, as having nested closures within closures seems to be the primary cause of `rustfmt` being unhappy. Release Notes: - N/A
This commit is contained in:
parent
fa1b1c6aff
commit
e1ca5ed836
1 changed files with 483 additions and 424 deletions
|
@ -153,51 +153,19 @@ pub fn initialize_workspace(
|
|||
.detach();
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
if let Err(e) = fs::linux_watcher::global(|_| {}) {
|
||||
let message = format!(db::indoc!{r#"
|
||||
inotify_init returned {}
|
||||
|
||||
This may be due to system-wide limits on inotify instances. For troubleshooting see: https://zed.dev/docs/linux
|
||||
"#}, e);
|
||||
let prompt = cx.prompt(PromptLevel::Critical, "Could not start inotify", Some(&message),
|
||||
&["Troubleshoot and Quit"]);
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
if prompt.await == Ok(0) {
|
||||
cx.update(|cx| {
|
||||
cx.open_url("https://zed.dev/docs/linux#could-not-start-inotify");
|
||||
cx.quit();
|
||||
}).ok();
|
||||
}
|
||||
}).detach()
|
||||
}
|
||||
initialize_linux_file_watcher(cx);
|
||||
|
||||
if let Some(specs) = cx.gpu_specs() {
|
||||
log::info!("Using GPU: {:?}", specs);
|
||||
if specs.is_software_emulated && std::env::var("ZED_ALLOW_EMULATED_GPU").is_err() {
|
||||
let message = format!(db::indoc!{r#"
|
||||
Zed uses Vulkan for rendering and requires a compatible GPU.
|
||||
|
||||
Currently you are using a software emulated GPU ({}) which
|
||||
will result in awful performance.
|
||||
|
||||
For troubleshooting see: https://zed.dev/docs/linux
|
||||
Set ZED_ALLOW_EMULATED_GPU=1 env var to permanently override.
|
||||
"#}, specs.device_name);
|
||||
let prompt = cx.prompt(PromptLevel::Critical, "Unsupported GPU", Some(&message),
|
||||
&["Skip", "Troubleshoot and Quit"]);
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
if prompt.await == Ok(1) {
|
||||
cx.update(|cx| {
|
||||
cx.open_url("https://zed.dev/docs/linux#zed-fails-to-open-windows");
|
||||
cx.quit();
|
||||
}).ok();
|
||||
}
|
||||
}).detach()
|
||||
}
|
||||
show_software_emulation_warning_if_needed(specs, cx);
|
||||
}
|
||||
|
||||
let inline_completion_button = cx.new_view(|cx| {
|
||||
inline_completion_button::InlineCompletionButton::new(workspace.weak_handle(), app_state.fs.clone(), cx)
|
||||
inline_completion_button::InlineCompletionButton::new(
|
||||
workspace.weak_handle(),
|
||||
app_state.fs.clone(),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
let diagnostic_summary =
|
||||
|
@ -225,7 +193,6 @@ pub fn initialize_workspace(
|
|||
|
||||
let handle = cx.view().downgrade();
|
||||
cx.on_window_should_close(move |cx| {
|
||||
|
||||
handle
|
||||
.update(cx, |workspace, cx| {
|
||||
// We'll handle closing asynchronously
|
||||
|
@ -235,6 +202,104 @@ pub fn initialize_workspace(
|
|||
.unwrap_or(true)
|
||||
});
|
||||
|
||||
initialize_panels(prompt_builder.clone(), cx);
|
||||
register_actions(app_state.clone(), workspace, cx);
|
||||
|
||||
workspace.focus_handle(cx).focus(cx);
|
||||
})
|
||||
.detach();
|
||||
|
||||
feature_gate_zed_pro_actions(cx);
|
||||
}
|
||||
|
||||
fn feature_gate_zed_pro_actions(cx: &mut AppContext) {
|
||||
let zed_pro_actions = [TypeId::of::<OpenAccountSettings>()];
|
||||
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&zed_pro_actions);
|
||||
});
|
||||
|
||||
cx.observe_flag::<feature_flags::ZedPro, _>({
|
||||
move |is_enabled, cx| {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
if is_enabled {
|
||||
filter.show_action_types(zed_pro_actions.iter());
|
||||
} else {
|
||||
filter.hide_action_types(&zed_pro_actions);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
fn initialize_linux_file_watcher(cx: &mut ViewContext<Workspace>) {
|
||||
if let Err(e) = fs::linux_watcher::global(|_| {}) {
|
||||
let message = format!(
|
||||
db::indoc! {r#"
|
||||
inotify_init returned {}
|
||||
|
||||
This may be due to system-wide limits on inotify instances. For troubleshooting see: https://zed.dev/docs/linux
|
||||
"#},
|
||||
e
|
||||
);
|
||||
let prompt = cx.prompt(
|
||||
PromptLevel::Critical,
|
||||
"Could not start inotify",
|
||||
Some(&message),
|
||||
&["Troubleshoot and Quit"],
|
||||
);
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
if prompt.await == Ok(0) {
|
||||
cx.update(|cx| {
|
||||
cx.open_url("https://zed.dev/docs/linux#could-not-start-inotify");
|
||||
cx.quit();
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.detach()
|
||||
}
|
||||
}
|
||||
|
||||
fn show_software_emulation_warning_if_needed(
|
||||
specs: gpui::GPUSpecs,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
if specs.is_software_emulated && std::env::var("ZED_ALLOW_EMULATED_GPU").is_err() {
|
||||
let message = format!(
|
||||
db::indoc! {r#"
|
||||
Zed uses Vulkan for rendering and requires a compatible GPU.
|
||||
|
||||
Currently you are using a software emulated GPU ({}) which
|
||||
will result in awful performance.
|
||||
|
||||
For troubleshooting see: https://zed.dev/docs/linux
|
||||
Set ZED_ALLOW_EMULATED_GPU=1 env var to permanently override.
|
||||
"#},
|
||||
specs.device_name
|
||||
);
|
||||
let prompt = cx.prompt(
|
||||
PromptLevel::Critical,
|
||||
"Unsupported GPU",
|
||||
Some(&message),
|
||||
&["Skip", "Troubleshoot and Quit"],
|
||||
);
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
if prompt.await == Ok(1) {
|
||||
cx.update(|cx| {
|
||||
cx.open_url("https://zed.dev/docs/linux#zed-fails-to-open-windows");
|
||||
cx.quit();
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.detach()
|
||||
}
|
||||
}
|
||||
|
||||
fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Workspace>) {
|
||||
let release_channel = ReleaseChannel::global(cx);
|
||||
let assistant2_feature_flag = cx.wait_for_flag::<feature_flags::Assistant2FeatureFlag>();
|
||||
let git_ui_feature_flag = cx.wait_for_flag::<feature_flags::GitUiFeatureFlag>();
|
||||
|
@ -296,8 +361,7 @@ pub fn initialize_workspace(
|
|||
}
|
||||
})?;
|
||||
|
||||
let is_assistant2_enabled =
|
||||
if cfg!(test) || release_channel != ReleaseChannel::Dev {
|
||||
let is_assistant2_enabled = if cfg!(test) || release_channel != ReleaseChannel::Dev {
|
||||
false
|
||||
} else {
|
||||
assistant2_feature_flag.await
|
||||
|
@ -320,7 +384,13 @@ pub fn initialize_workspace(
|
|||
})
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn register_actions(
|
||||
app_state: Arc<AppState>,
|
||||
workspace: &mut Workspace,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
workspace
|
||||
.register_action(about)
|
||||
.register_action(|_, _: &Minimize, cx| {
|
||||
|
@ -340,7 +410,8 @@ pub fn initialize_workspace(
|
|||
theme::adjust_buffer_font_size(cx, |size| *size += px(1.0))
|
||||
})
|
||||
.register_action(|workspace, _: &workspace::Open, cx| {
|
||||
workspace.client()
|
||||
workspace
|
||||
.client()
|
||||
.telemetry()
|
||||
.report_app_event("open project".to_string());
|
||||
let paths = workspace.prompt_for_open_path(
|
||||
|
@ -397,42 +468,7 @@ pub fn initialize_workspace(
|
|||
.register_action(move |_, _: &zed_actions::ResetBufferFontSize, cx| {
|
||||
theme::reset_buffer_font_size(cx)
|
||||
})
|
||||
.register_action(|_, _: &install_cli::Install, cx| {
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
if cfg!(any(target_os = "linux", target_os = "freebsd")) {
|
||||
let prompt = cx.prompt(
|
||||
PromptLevel::Warning,
|
||||
"CLI should already be installed",
|
||||
Some("If you installed Zed from our official release add ~/.local/bin to your PATH.\n\nIf you installed Zed from a different source like your package manager, then you may need to create an alias/symlink manually.\n\nDepending on your package manager, the CLI might be named zeditor, zedit, zed-editor or something else."),
|
||||
&["Ok"],
|
||||
);
|
||||
cx.background_executor().spawn(prompt).detach();
|
||||
return Ok(());
|
||||
}
|
||||
let path = install_cli::install_cli(cx.deref())
|
||||
.await
|
||||
.context("error creating CLI symlink")?;
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
struct InstalledZedCli;
|
||||
|
||||
workspace.show_toast(
|
||||
Toast::new(
|
||||
NotificationId::unique::<InstalledZedCli>(),
|
||||
format!(
|
||||
"Installed `zed` to {}. You can launch {} from your terminal.",
|
||||
path.to_string_lossy(),
|
||||
ReleaseChannel::global(cx).display_name()
|
||||
),
|
||||
),
|
||||
cx,
|
||||
)
|
||||
})?;
|
||||
register_zed_scheme(&cx).await.log_err();
|
||||
Ok(())
|
||||
})
|
||||
.detach_and_prompt_err("Error installing zed cli", cx, |_, _| None);
|
||||
})
|
||||
.register_action(install_cli)
|
||||
.register_action(|_, _: &install_cli::RegisterZedScheme, cx| {
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
register_zed_scheme(&cx).await?;
|
||||
|
@ -452,11 +488,7 @@ pub fn initialize_workspace(
|
|||
})?;
|
||||
Ok(())
|
||||
})
|
||||
.detach_and_prompt_err(
|
||||
"Error registering zed:// scheme",
|
||||
cx,
|
||||
|_, _| None,
|
||||
);
|
||||
.detach_and_prompt_err("Error registering zed:// scheme", cx, |_, _| None);
|
||||
})
|
||||
.register_action(|workspace, _: &OpenLog, cx| {
|
||||
open_log_file(workspace, cx);
|
||||
|
@ -481,7 +513,11 @@ pub fn initialize_workspace(
|
|||
move |_: &mut Workspace,
|
||||
_: &zed_actions::OpenKeymap,
|
||||
cx: &mut ViewContext<Workspace>| {
|
||||
open_settings_file(paths::keymap_file(), || settings::initial_keymap_content().as_ref().into(), cx);
|
||||
open_settings_file(
|
||||
paths::keymap_file(),
|
||||
|| settings::initial_keymap_content().as_ref().into(),
|
||||
cx,
|
||||
);
|
||||
},
|
||||
)
|
||||
.register_action(
|
||||
|
@ -603,49 +639,33 @@ pub fn initialize_workspace(
|
|||
if workspace.project().read(cx).is_via_ssh() {
|
||||
workspace.register_action({
|
||||
move |workspace, _: &OpenServerSettings, cx| {
|
||||
let open_server_settings = workspace.project().update(cx, |project, cx| {
|
||||
project.open_server_settings(cx)
|
||||
});
|
||||
let open_server_settings = workspace
|
||||
.project()
|
||||
.update(cx, |project, cx| project.open_server_settings(cx));
|
||||
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let buffer = open_server_settings.await?;
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_path(buffer.read(cx).project_path(cx).expect("Settings file must have a location"), None, true, cx)
|
||||
})?.await?;
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_path(
|
||||
buffer
|
||||
.read(cx)
|
||||
.project_path(cx)
|
||||
.expect("Settings file must have a location"),
|
||||
None,
|
||||
true,
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await?;
|
||||
|
||||
anyhow::Ok(())
|
||||
}).detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
workspace.focus_handle(cx).focus(cx);
|
||||
})
|
||||
.detach();
|
||||
|
||||
feature_gate_zed_pro_actions(cx);
|
||||
}
|
||||
|
||||
fn feature_gate_zed_pro_actions(cx: &mut AppContext) {
|
||||
let zed_pro_actions = [TypeId::of::<OpenAccountSettings>()];
|
||||
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&zed_pro_actions);
|
||||
});
|
||||
|
||||
cx.observe_flag::<feature_flags::ZedPro, _>({
|
||||
move |is_enabled, cx| {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
if is_enabled {
|
||||
filter.show_action_types(zed_pro_actions.iter());
|
||||
} else {
|
||||
filter.hide_action_types(&zed_pro_actions);
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn initialize_pane(workspace: &Workspace, pane: &View<Pane>, cx: &mut ViewContext<Workspace>) {
|
||||
|
@ -694,6 +714,45 @@ fn test_panic(_: &TestPanic, _: &mut AppContext) {
|
|||
panic!("Ran the TestPanic action")
|
||||
}
|
||||
|
||||
fn install_cli(_: &mut Workspace, _: &install_cli::Install, cx: &mut ViewContext<Workspace>) {
|
||||
const LINUX_PROMPT_DETAIL: &str = "If you installed Zed from our official release add ~/.local/bin to your PATH.\n\nIf you installed Zed from a different source like your package manager, then you may need to create an alias/symlink manually.\n\nDepending on your package manager, the CLI might be named zeditor, zedit, zed-editor or something else.";
|
||||
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
if cfg!(any(target_os = "linux", target_os = "freebsd")) {
|
||||
let prompt = cx.prompt(
|
||||
PromptLevel::Warning,
|
||||
"CLI should already be installed",
|
||||
Some(LINUX_PROMPT_DETAIL),
|
||||
&["Ok"],
|
||||
);
|
||||
cx.background_executor().spawn(prompt).detach();
|
||||
return Ok(());
|
||||
}
|
||||
let path = install_cli::install_cli(cx.deref())
|
||||
.await
|
||||
.context("error creating CLI symlink")?;
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
struct InstalledZedCli;
|
||||
|
||||
workspace.show_toast(
|
||||
Toast::new(
|
||||
NotificationId::unique::<InstalledZedCli>(),
|
||||
format!(
|
||||
"Installed `zed` to {}. You can launch {} from your terminal.",
|
||||
path.to_string_lossy(),
|
||||
ReleaseChannel::global(cx).display_name()
|
||||
),
|
||||
),
|
||||
cx,
|
||||
)
|
||||
})?;
|
||||
register_zed_scheme(&cx).await.log_err();
|
||||
Ok(())
|
||||
})
|
||||
.detach_and_prompt_err("Error installing zed cli", cx, |_, _| None);
|
||||
}
|
||||
|
||||
fn quit(_: &Quit, cx: &mut AppContext) {
|
||||
let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
|
||||
cx.spawn(|mut cx| async move {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue