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:
parent
5289b815fe
commit
15353630e4
2 changed files with 45 additions and 32 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue