zed: Add OpenRequestKind (#34860)

This PR refactors the `OpenRequest` to introduce an `OpenRequestKind`
enum.

It seems most of the fields on `OpenRequest` are mutually-exclusive, so
it is better to model it as an enum rather than using a bunch of
`Option`s.

There are likely more of the existing fields that can be converted into
`OpenRequestKind` variants, but I'm being conservative for this first
pass.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-07-21 21:11:11 -04:00 committed by GitHub
parent 5289b815fe
commit 15353630e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 32 deletions

View file

@ -55,6 +55,8 @@ use zed::{
inline_completion_registry, open_paths_with_positions,
};
use crate::zed::OpenRequestKind;
#[cfg(feature = "mimalloc")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
@ -746,32 +748,34 @@ pub fn main() {
}
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut App) {
if let Some(connection) = request.cli_connection {
let app_state = app_state.clone();
cx.spawn(async move |cx| handle_cli_connection(connection, app_state, cx).await)
.detach();
return;
}
if let Some(kind) = request.kind {
match kind {
OpenRequestKind::CliConnection(connection) => {
let app_state = app_state.clone();
cx.spawn(async move |cx| handle_cli_connection(connection, app_state, cx).await)
.detach();
}
OpenRequestKind::Extension { extension_id } => {
cx.spawn(async move |cx| {
let workspace =
workspace::get_any_active_workspace(app_state, cx.clone()).await?;
workspace.update(cx, |_, window, cx| {
window.dispatch_action(
Box::new(zed_actions::Extensions {
category_filter: None,
id: Some(extension_id),
}),
cx,
);
})
})
.detach_and_log_err(cx);
}
OpenRequestKind::DockMenuAction { index } => {
cx.perform_dock_menu_action(index);
}
}
if let Some(action_index) = request.dock_menu_action {
cx.perform_dock_menu_action(action_index);
return;
}
if let Some(extension) = request.extension_id {
cx.spawn(async move |cx| {
let workspace = workspace::get_any_active_workspace(app_state, cx.clone()).await?;
workspace.update(cx, |_, window, cx| {
window.dispatch_action(
Box::new(zed_actions::Extensions {
category_filter: None,
id: Some(extension),
}),
cx,
);
})
})
.detach_and_log_err(cx);
return;
}