Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -19,9 +19,9 @@ use fs::{Fs, RealFs};
|
|||
use futures::{future, StreamExt};
|
||||
use git::GitHostingProviderRegistry;
|
||||
use gpui::{
|
||||
Action, App, AppContext, AsyncAppContext, Context, DismissEvent, UpdateGlobal as _,
|
||||
VisualContext,
|
||||
Action, App, AppContext as _, Application, AsyncAppContext, DismissEvent, UpdateGlobal as _,
|
||||
};
|
||||
|
||||
use http_client::{read_proxy_from_env, Uri};
|
||||
use language::LanguageRegistry;
|
||||
use log::LevelFilter;
|
||||
|
@ -102,22 +102,23 @@ fn files_not_created_on_launch(errors: HashMap<io::ErrorKind, Vec<&Path>>) {
|
|||
.collect::<Vec<_>>().join("\n\n");
|
||||
|
||||
eprintln!("{message}: {error_details}");
|
||||
App::new().run(move |cx| {
|
||||
if let Ok(window) = cx.open_window(gpui::WindowOptions::default(), |cx| {
|
||||
cx.new_view(|_| gpui::Empty)
|
||||
Application::new().run(move |cx| {
|
||||
if let Ok(window) = cx.open_window(gpui::WindowOptions::default(), |_, cx| {
|
||||
cx.new(|_| gpui::Empty)
|
||||
}) {
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
let response = cx.prompt(
|
||||
.update(cx, |_, window, cx| {
|
||||
let response = window.prompt(
|
||||
gpui::PromptLevel::Critical,
|
||||
message,
|
||||
Some(&error_details),
|
||||
&["Exit"],
|
||||
cx,
|
||||
);
|
||||
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.spawn_in(window, |_, mut cx| async move {
|
||||
response.await?;
|
||||
cx.update(|cx| cx.quit())
|
||||
cx.update(|_, cx| cx.quit())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
})
|
||||
|
@ -132,7 +133,7 @@ fn fail_to_open_window_async(e: anyhow::Error, cx: &mut AsyncAppContext) {
|
|||
cx.update(|cx| fail_to_open_window(e, cx)).log_err();
|
||||
}
|
||||
|
||||
fn fail_to_open_window(e: anyhow::Error, _cx: &mut AppContext) {
|
||||
fn fail_to_open_window(e: anyhow::Error, _cx: &mut App) {
|
||||
eprintln!(
|
||||
"Zed failed to open a window: {e:?}. See https://zed.dev/docs/linux for troubleshooting steps."
|
||||
);
|
||||
|
@ -188,7 +189,7 @@ fn main() {
|
|||
|
||||
log::info!("========== starting zed ==========");
|
||||
|
||||
let app = App::new().with_assets(Assets);
|
||||
let app = Application::new().with_assets(Assets);
|
||||
|
||||
let system_id = app.background_executor().block(system_id()).ok();
|
||||
let installation_id = app.background_executor().block(installation_id()).ok();
|
||||
|
@ -359,8 +360,8 @@ fn main() {
|
|||
language::init(cx);
|
||||
language_extension::init(extension_host_proxy.clone(), languages.clone());
|
||||
languages::init(languages.clone(), node_runtime.clone(), cx);
|
||||
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
||||
let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
|
||||
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
|
||||
let workspace_store = cx.new(|cx| WorkspaceStore::new(client.clone(), cx));
|
||||
|
||||
Client::set_global(client.clone(), cx);
|
||||
|
||||
|
@ -390,7 +391,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
let app_session = cx.new_model(|cx| AppSession::new(session, cx));
|
||||
let app_session = cx.new(|cx| AppSession::new(session, cx));
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
languages: languages.clone(),
|
||||
|
@ -522,8 +523,8 @@ fn main() {
|
|||
for &mut window in cx.windows().iter_mut() {
|
||||
let background_appearance = cx.theme().window_background_appearance();
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
cx.set_background_appearance(background_appearance)
|
||||
.update(cx, |_, window, _| {
|
||||
window.set_background_appearance(background_appearance)
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
@ -615,13 +616,13 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
||||
fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut App) {
|
||||
struct SettingsParseErrorNotification;
|
||||
let id = NotificationId::unique::<SettingsParseErrorNotification>();
|
||||
|
||||
for workspace in workspace::local_workspace_windows(cx) {
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
match error.as_ref() {
|
||||
Some(error) => {
|
||||
if let Some(InvalidSettingsError::LocalSettings { .. }) =
|
||||
|
@ -630,13 +631,16 @@ fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
|||
// Local settings will be displayed by the projects
|
||||
} else {
|
||||
workspace.show_notification(id.clone(), cx, |cx| {
|
||||
cx.new_view(|_| {
|
||||
cx.new(|_cx| {
|
||||
MessageNotification::new(format!(
|
||||
"Invalid user settings file\n{error}"
|
||||
))
|
||||
.with_click_message("Open settings file")
|
||||
.on_click(|cx| {
|
||||
cx.dispatch_action(zed_actions::OpenSettings.boxed_clone());
|
||||
.on_click(|window, cx| {
|
||||
window.dispatch_action(
|
||||
zed_actions::OpenSettings.boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
})
|
||||
|
@ -650,7 +654,7 @@ fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
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(move |cx| handle_cli_connection(connection, app_state, cx))
|
||||
|
@ -722,15 +726,16 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
|
|||
|
||||
let workspace_window =
|
||||
workspace::get_any_active_workspace(app_state, cx.clone()).await?;
|
||||
let workspace = workspace_window.root_view(&cx)?;
|
||||
let workspace = workspace_window.root_model(&cx)?;
|
||||
|
||||
let mut promises = Vec::new();
|
||||
for (channel_id, heading) in request.open_channel_notes {
|
||||
promises.push(cx.update_window(workspace_window.into(), |_, cx| {
|
||||
promises.push(cx.update_window(workspace_window.into(), |_, window, cx| {
|
||||
ChannelView::open(
|
||||
client::ChannelId(channel_id),
|
||||
heading,
|
||||
workspace.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
.log_err()
|
||||
|
@ -853,9 +858,14 @@ async fn restore_or_create_workspace(
|
|||
cx.update(|cx| show_welcome_view(app_state, cx))?.await?;
|
||||
} else {
|
||||
cx.update(|cx| {
|
||||
workspace::open_new(Default::default(), app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
workspace::open_new(
|
||||
Default::default(),
|
||||
app_state,
|
||||
cx,
|
||||
|workspace, window, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), window, cx)
|
||||
},
|
||||
)
|
||||
})?
|
||||
.await?;
|
||||
}
|
||||
|
@ -1053,7 +1063,7 @@ impl ToString for IdType {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_url_arg(arg: &str, cx: &AppContext) -> Result<String> {
|
||||
fn parse_url_arg(arg: &str, cx: &App) -> Result<String> {
|
||||
match std::fs::canonicalize(Path::new(&arg)) {
|
||||
Ok(path) => Ok(format!("file://{}", path.display())),
|
||||
Err(error) => {
|
||||
|
@ -1070,7 +1080,7 @@ fn parse_url_arg(arg: &str, cx: &AppContext) -> Result<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_embedded_fonts(cx: &AppContext) {
|
||||
fn load_embedded_fonts(cx: &App) {
|
||||
let asset_source = cx.asset_source();
|
||||
let font_paths = asset_source.list("fonts").unwrap();
|
||||
let embedded_fonts = Mutex::new(Vec::new());
|
||||
|
@ -1095,7 +1105,7 @@ fn load_embedded_fonts(cx: &AppContext) {
|
|||
}
|
||||
|
||||
/// Spawns a background task to load the user themes from the themes directory.
|
||||
fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
cx.spawn({
|
||||
let fs = fs.clone();
|
||||
|cx| async move {
|
||||
|
@ -1129,7 +1139,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
/// Spawns a background task to watch the themes directory for changes.
|
||||
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
cx.spawn(|cx| async move {
|
||||
let (mut events, _) = fs
|
||||
|
@ -1158,7 +1168,7 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &mut AppContext) {
|
||||
fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
|
||||
let path = {
|
||||
|
@ -1188,10 +1198,10 @@ fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &m
|
|||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>, _cx: &mut AppContext) {}
|
||||
fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>, _cx: &mut App) {}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||
fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
use std::time::Duration;
|
||||
|
||||
use file_icons::FileIcons;
|
||||
|
@ -1220,4 +1230,4 @@ fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut AppContext) {}
|
||||
fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut App) {}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::stdout_is_a_pty;
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{Context as _, Result};
|
||||
use backtrace::{self, Backtrace};
|
||||
use chrono::Utc;
|
||||
use client::{telemetry, TelemetrySettings};
|
||||
use db::kvp::KEY_VALUE_STORE;
|
||||
use gpui::{AppContext, SemanticVersion};
|
||||
use gpui::{App, SemanticVersion};
|
||||
use http_client::{self, HttpClient, HttpClientWithUrl, HttpRequestExt, Method};
|
||||
use paths::{crashes_dir, crashes_retired_dir};
|
||||
use project::Project;
|
||||
|
@ -163,7 +163,7 @@ pub fn init(
|
|||
system_id: Option<String>,
|
||||
installation_id: Option<String>,
|
||||
session_id: String,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) {
|
||||
#[cfg(target_os = "macos")]
|
||||
monitor_main_thread_hangs(http_client.clone(), installation_id.clone(), cx);
|
||||
|
@ -182,7 +182,7 @@ pub fn init(
|
|||
cx,
|
||||
);
|
||||
|
||||
cx.observe_new_models(move |project: &mut Project, cx| {
|
||||
cx.observe_new(move |project: &mut Project, _, cx| {
|
||||
let http_client = http_client.clone();
|
||||
let panic_report_url = panic_report_url.clone();
|
||||
let session_id = session_id.clone();
|
||||
|
@ -233,7 +233,7 @@ pub fn init(
|
|||
pub fn monitor_main_thread_hangs(
|
||||
http_client: Arc<HttpClientWithUrl>,
|
||||
installation_id: Option<String>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) {
|
||||
// This is too noisy to ship to stable for now.
|
||||
if !matches!(
|
||||
|
@ -435,7 +435,7 @@ fn upload_panics_and_crashes(
|
|||
http: Arc<HttpClientWithUrl>,
|
||||
panic_report_url: Url,
|
||||
installation_id: Option<String>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) {
|
||||
let telemetry_settings = *client::TelemetrySettings::get_global(cx);
|
||||
cx.background_executor()
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,53 +5,65 @@ use collections::HashMap;
|
|||
use copilot::{Copilot, CopilotCompletionProvider};
|
||||
use editor::{Editor, EditorMode};
|
||||
use feature_flags::{FeatureFlagAppExt, PredictEditsFeatureFlag};
|
||||
use gpui::{AnyWindowHandle, AppContext, Context, Model, ViewContext, WeakView};
|
||||
use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, WeakEntity, Window};
|
||||
use language::language_settings::{all_language_settings, InlineCompletionProvider};
|
||||
use settings::SettingsStore;
|
||||
use supermaven::{Supermaven, SupermavenCompletionProvider};
|
||||
use workspace::Workspace;
|
||||
use zed_predict_tos::ZedPredictTos;
|
||||
|
||||
pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppContext) {
|
||||
let editors: Rc<RefCell<HashMap<WeakView<Editor>, AnyWindowHandle>>> = Rc::default();
|
||||
cx.observe_new_views({
|
||||
pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
|
||||
let editors: Rc<RefCell<HashMap<WeakEntity<Editor>, AnyWindowHandle>>> = Rc::default();
|
||||
cx.observe_new({
|
||||
let editors = editors.clone();
|
||||
let client = client.clone();
|
||||
let user_store = user_store.clone();
|
||||
move |editor: &mut Editor, cx: &mut ViewContext<Editor>| {
|
||||
move |editor: &mut Editor, window, cx: &mut Context<Editor>| {
|
||||
if editor.mode() != EditorMode::Full {
|
||||
return;
|
||||
}
|
||||
|
||||
register_backward_compatible_actions(editor, cx);
|
||||
|
||||
let editor_handle = cx.view().downgrade();
|
||||
let Some(window) = window else {
|
||||
return;
|
||||
};
|
||||
|
||||
let editor_handle = cx.model().downgrade();
|
||||
cx.on_release({
|
||||
let editor_handle = editor_handle.clone();
|
||||
let editors = editors.clone();
|
||||
move |_, _, _| {
|
||||
move |_, _| {
|
||||
editors.borrow_mut().remove(&editor_handle);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
editors
|
||||
.borrow_mut()
|
||||
.insert(editor_handle, cx.window_handle());
|
||||
.insert(editor_handle, window.window_handle());
|
||||
let provider = all_language_settings(None, cx).inline_completions.provider;
|
||||
assign_inline_completion_provider(editor, provider, &client, user_store.clone(), cx);
|
||||
assign_inline_completion_provider(
|
||||
editor,
|
||||
provider,
|
||||
&client,
|
||||
user_store.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let mut provider = all_language_settings(None, cx).inline_completions.provider;
|
||||
for (editor, window) in editors.borrow().iter() {
|
||||
_ = window.update(cx, |_window, cx| {
|
||||
_ = window.update(cx, |_window, window, cx| {
|
||||
_ = editor.update(cx, |editor, cx| {
|
||||
assign_inline_completion_provider(
|
||||
editor,
|
||||
provider,
|
||||
&client,
|
||||
user_store.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -105,14 +117,19 @@ pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppConte
|
|||
|
||||
let Some(workspace) = window
|
||||
.downcast::<Workspace>()
|
||||
.and_then(|w| w.root_view(cx).ok())
|
||||
.and_then(|w| w.root_model(cx).ok())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
ZedPredictTos::toggle(workspace, user_store.clone(), cx);
|
||||
.update(cx, |_, window, cx| {
|
||||
ZedPredictTos::toggle(
|
||||
workspace,
|
||||
user_store.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
@ -127,27 +144,28 @@ pub fn init(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut AppConte
|
|||
.detach();
|
||||
}
|
||||
|
||||
fn clear_zeta_edit_history(_: &zeta::ClearHistory, cx: &mut AppContext) {
|
||||
fn clear_zeta_edit_history(_: &zeta::ClearHistory, cx: &mut App) {
|
||||
if let Some(zeta) = zeta::Zeta::global(cx) {
|
||||
zeta.update(cx, |zeta, _| zeta.clear_history());
|
||||
}
|
||||
}
|
||||
|
||||
fn assign_inline_completion_providers(
|
||||
editors: &Rc<RefCell<HashMap<WeakView<Editor>, AnyWindowHandle>>>,
|
||||
editors: &Rc<RefCell<HashMap<WeakEntity<Editor>, AnyWindowHandle>>>,
|
||||
provider: InlineCompletionProvider,
|
||||
client: &Arc<Client>,
|
||||
user_store: Model<UserStore>,
|
||||
cx: &mut AppContext,
|
||||
user_store: Entity<UserStore>,
|
||||
cx: &mut App,
|
||||
) {
|
||||
for (editor, window) in editors.borrow().iter() {
|
||||
_ = window.update(cx, |_window, cx| {
|
||||
_ = window.update(cx, |_window, window, cx| {
|
||||
_ = editor.update(cx, |editor, cx| {
|
||||
assign_inline_completion_provider(
|
||||
editor,
|
||||
provider,
|
||||
&client,
|
||||
user_store.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -155,28 +173,31 @@ fn assign_inline_completion_providers(
|
|||
}
|
||||
}
|
||||
|
||||
fn register_backward_compatible_actions(editor: &mut Editor, cx: &ViewContext<Editor>) {
|
||||
fn register_backward_compatible_actions(editor: &mut Editor, cx: &mut Context<Editor>) {
|
||||
// We renamed some of these actions to not be copilot-specific, but that
|
||||
// would have not been backwards-compatible. So here we are re-registering
|
||||
// the actions with the old names to not break people's keymaps.
|
||||
editor
|
||||
.register_action(cx.listener(
|
||||
|editor, _: &copilot::Suggest, cx: &mut ViewContext<Editor>| {
|
||||
editor.show_inline_completion(&Default::default(), cx);
|
||||
|editor, _: &copilot::Suggest, window: &mut Window, cx: &mut Context<Editor>| {
|
||||
editor.show_inline_completion(&Default::default(), window, cx);
|
||||
},
|
||||
))
|
||||
.detach();
|
||||
editor
|
||||
.register_action(cx.listener(
|
||||
|editor, _: &copilot::NextSuggestion, cx: &mut ViewContext<Editor>| {
|
||||
editor.next_inline_completion(&Default::default(), cx);
|
||||
|editor, _: &copilot::NextSuggestion, window: &mut Window, cx: &mut Context<Editor>| {
|
||||
editor.next_inline_completion(&Default::default(), window, cx);
|
||||
},
|
||||
))
|
||||
.detach();
|
||||
editor
|
||||
.register_action(cx.listener(
|
||||
|editor, _: &copilot::PreviousSuggestion, cx: &mut ViewContext<Editor>| {
|
||||
editor.previous_inline_completion(&Default::default(), cx);
|
||||
|editor,
|
||||
_: &copilot::PreviousSuggestion,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>| {
|
||||
editor.previous_inline_completion(&Default::default(), window, cx);
|
||||
},
|
||||
))
|
||||
.detach();
|
||||
|
@ -184,8 +205,9 @@ fn register_backward_compatible_actions(editor: &mut Editor, cx: &ViewContext<Ed
|
|||
.register_action(cx.listener(
|
||||
|editor,
|
||||
_: &editor::actions::AcceptPartialCopilotSuggestion,
|
||||
cx: &mut ViewContext<Editor>| {
|
||||
editor.accept_partial_inline_completion(&Default::default(), cx);
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>| {
|
||||
editor.accept_partial_inline_completion(&Default::default(), window, cx);
|
||||
},
|
||||
))
|
||||
.detach();
|
||||
|
@ -195,8 +217,9 @@ fn assign_inline_completion_provider(
|
|||
editor: &mut Editor,
|
||||
provider: language::language_settings::InlineCompletionProvider,
|
||||
client: &Arc<Client>,
|
||||
user_store: Model<UserStore>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
user_store: Entity<UserStore>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
match provider {
|
||||
language::language_settings::InlineCompletionProvider::None => {}
|
||||
|
@ -209,14 +232,14 @@ fn assign_inline_completion_provider(
|
|||
});
|
||||
}
|
||||
}
|
||||
let provider = cx.new_model(|_| CopilotCompletionProvider::new(copilot));
|
||||
editor.set_inline_completion_provider(Some(provider), cx);
|
||||
let provider = cx.new(|_| CopilotCompletionProvider::new(copilot));
|
||||
editor.set_inline_completion_provider(Some(provider), window, cx);
|
||||
}
|
||||
}
|
||||
language::language_settings::InlineCompletionProvider::Supermaven => {
|
||||
if let Some(supermaven) = Supermaven::global(cx) {
|
||||
let provider = cx.new_model(|_| SupermavenCompletionProvider::new(supermaven));
|
||||
editor.set_inline_completion_provider(Some(provider), cx);
|
||||
let provider = cx.new(|_| SupermavenCompletionProvider::new(supermaven));
|
||||
editor.set_inline_completion_provider(Some(provider), window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,8 +255,8 @@ fn assign_inline_completion_provider(
|
|||
});
|
||||
}
|
||||
}
|
||||
let provider = cx.new_model(|_| zeta::ZetaInlineCompletionProvider::new(zeta));
|
||||
editor.set_inline_completion_provider(Some(provider), cx);
|
||||
let provider = cx.new(|_| zeta::ZetaInlineCompletionProvider::new(zeta));
|
||||
editor.set_inline_completion_provider(Some(provider), window, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use gpui::{
|
||||
div, AppContext, EventEmitter, FocusHandle, FocusableView, FontWeight, InteractiveElement,
|
||||
IntoElement, ParentElement, PromptHandle, PromptLevel, PromptResponse, Refineable, Render,
|
||||
RenderablePromptHandle, Styled, TextStyleRefinement, View, ViewContext, VisualContext,
|
||||
WindowContext,
|
||||
div, App, AppContext as _, Context, Entity, EventEmitter, FocusHandle, Focusable, FontWeight,
|
||||
InteractiveElement, IntoElement, ParentElement, PromptHandle, PromptLevel, PromptResponse,
|
||||
Refineable, Render, RenderablePromptHandle, Styled, TextStyleRefinement, Window,
|
||||
};
|
||||
use markdown::{Markdown, MarkdownStyle};
|
||||
use settings::Settings;
|
||||
|
@ -13,7 +12,7 @@ use ui::{
|
|||
};
|
||||
use workspace::ui::StyledExt;
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.set_prompt_builder(fallback_prompt_renderer)
|
||||
}
|
||||
/// Use this function in conjunction with [AppContext::set_prompt_renderer] to force
|
||||
|
@ -24,9 +23,10 @@ pub fn fallback_prompt_renderer(
|
|||
detail: Option<&str>,
|
||||
actions: &[&str],
|
||||
handle: PromptHandle,
|
||||
cx: &mut WindowContext,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> RenderablePromptHandle {
|
||||
let renderer = cx.new_view({
|
||||
let renderer = cx.new({
|
||||
|cx| FallbackPromptRenderer {
|
||||
_level: level,
|
||||
message: message.to_string(),
|
||||
|
@ -34,9 +34,9 @@ pub fn fallback_prompt_renderer(
|
|||
focus: cx.focus_handle(),
|
||||
active_action_id: 0,
|
||||
detail: detail.filter(|text| !text.is_empty()).map(|text| {
|
||||
cx.new_view(|cx| {
|
||||
cx.new(|cx| {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
let mut base_text_style = cx.text_style();
|
||||
let mut base_text_style = window.text_style();
|
||||
base_text_style.refine(&TextStyleRefinement {
|
||||
font_family: Some(settings.ui_font.family.clone()),
|
||||
font_size: Some(settings.ui_font_size.into()),
|
||||
|
@ -48,13 +48,13 @@ pub fn fallback_prompt_renderer(
|
|||
selection_background_color: { cx.theme().players().local().selection },
|
||||
..Default::default()
|
||||
};
|
||||
Markdown::new(text.to_string(), markdown_style, None, None, cx)
|
||||
Markdown::new(text.to_string(), markdown_style, None, None, window, cx)
|
||||
})
|
||||
}),
|
||||
}
|
||||
});
|
||||
|
||||
handle.with_view(renderer, cx)
|
||||
handle.with_view(renderer, window, cx)
|
||||
}
|
||||
|
||||
/// The default GPUI fallback for rendering prompts, when the platform doesn't support it.
|
||||
|
@ -64,31 +64,36 @@ pub struct FallbackPromptRenderer {
|
|||
actions: Vec<String>,
|
||||
focus: FocusHandle,
|
||||
active_action_id: usize,
|
||||
detail: Option<View<Markdown>>,
|
||||
detail: Option<Entity<Markdown>>,
|
||||
}
|
||||
|
||||
impl FallbackPromptRenderer {
|
||||
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
|
||||
fn confirm(&mut self, _: &menu::Confirm, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
cx.emit(PromptResponse(self.active_action_id));
|
||||
}
|
||||
|
||||
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||
fn cancel(&mut self, _: &menu::Cancel, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(ix) = self.actions.iter().position(|a| a == "Cancel") {
|
||||
cx.emit(PromptResponse(ix));
|
||||
}
|
||||
}
|
||||
|
||||
fn select_first(&mut self, _: &menu::SelectFirst, cx: &mut ViewContext<Self>) {
|
||||
fn select_first(
|
||||
&mut self,
|
||||
_: &menu::SelectFirst,
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.active_action_id = self.actions.len().saturating_sub(1);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn select_last(&mut self, _: &menu::SelectLast, cx: &mut ViewContext<Self>) {
|
||||
fn select_last(&mut self, _: &menu::SelectLast, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.active_action_id = 0;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
|
||||
fn select_next(&mut self, _: &menu::SelectNext, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.active_action_id > 0 {
|
||||
self.active_action_id -= 1;
|
||||
} else {
|
||||
|
@ -97,14 +102,14 @@ impl FallbackPromptRenderer {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
fn select_prev(&mut self, _: &menu::SelectPrev, cx: &mut ViewContext<Self>) {
|
||||
fn select_prev(&mut self, _: &menu::SelectPrev, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.active_action_id = (self.active_action_id + 1) % self.actions.len();
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for FallbackPromptRenderer {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
let font_family = settings.ui_font.family.clone();
|
||||
let prompt = v_flex()
|
||||
|
@ -144,7 +149,7 @@ impl Render for FallbackPromptRenderer {
|
|||
el.style(ButtonStyle::Tinted(TintColor::Accent))
|
||||
})
|
||||
.layer(ElevationIndex::ModalSurface)
|
||||
.on_click(cx.listener(move |_, _, cx| {
|
||||
.on_click(cx.listener(move |_, _, _window, cx| {
|
||||
cx.emit(PromptResponse(ix));
|
||||
}))
|
||||
}),
|
||||
|
@ -173,8 +178,8 @@ impl Render for FallbackPromptRenderer {
|
|||
|
||||
impl EventEmitter<PromptResponse> for FallbackPromptRenderer {}
|
||||
|
||||
impl FocusableView for FallbackPromptRenderer {
|
||||
fn focus_handle(&self, _: &crate::AppContext) -> FocusHandle {
|
||||
impl Focusable for FallbackPromptRenderer {
|
||||
fn focus_handle(&self, _: &crate::App) -> FocusHandle {
|
||||
self.focus.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::handle_open_request;
|
||||
use crate::restorable_workspace_locations;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use cli::{ipc, IpcHandshake};
|
||||
use cli::{ipc::IpcSender, CliRequest, CliResponse};
|
||||
use client::parse_zed_link;
|
||||
|
@ -12,7 +12,7 @@ use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
|||
use futures::channel::{mpsc, oneshot};
|
||||
use futures::future::join_all;
|
||||
use futures::{FutureExt, SinkExt, StreamExt};
|
||||
use gpui::{AppContext, AsyncAppContext, Global, WindowHandle};
|
||||
use gpui::{App, AsyncAppContext, Global, WindowHandle};
|
||||
use language::Point;
|
||||
use recent_projects::{open_ssh_project, SshSettings};
|
||||
use remote::SshConnectionOptions;
|
||||
|
@ -37,7 +37,7 @@ pub struct OpenRequest {
|
|||
}
|
||||
|
||||
impl OpenRequest {
|
||||
pub fn parse(urls: Vec<String>, cx: &AppContext) -> Result<Self> {
|
||||
pub fn parse(urls: Vec<String>, cx: &App) -> Result<Self> {
|
||||
let mut this = Self::default();
|
||||
for url in urls {
|
||||
if let Some(server_name) = url.strip_prefix("zed-cli://") {
|
||||
|
@ -67,7 +67,7 @@ impl OpenRequest {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_ssh_file_path(&mut self, file: &str, cx: &AppContext) -> Result<()> {
|
||||
fn parse_ssh_file_path(&mut self, file: &str, cx: &App) -> Result<()> {
|
||||
let url = url::Url::parse(file)?;
|
||||
let host = url
|
||||
.host()
|
||||
|
@ -233,9 +233,9 @@ pub async fn open_paths_with_positions(
|
|||
};
|
||||
if let Some(active_editor) = item.downcast::<Editor>() {
|
||||
workspace
|
||||
.update(cx, |_, cx| {
|
||||
.update(cx, |_, window, cx| {
|
||||
active_editor.update(cx, |editor, cx| {
|
||||
editor.go_to_singleton_buffer_point(point, cx);
|
||||
editor.go_to_singleton_buffer_point(point, window, cx);
|
||||
});
|
||||
})
|
||||
.log_err();
|
||||
|
@ -334,8 +334,8 @@ async fn open_workspaces(
|
|||
env,
|
||||
..Default::default()
|
||||
};
|
||||
workspace::open_new(open_options, app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
workspace::open_new(open_options, app_state, cx, |workspace, window, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), window, cx)
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
|
@ -466,8 +466,8 @@ async fn open_local_workspace(
|
|||
let wait = async move {
|
||||
if paths_with_position.is_empty() {
|
||||
let (done_tx, done_rx) = oneshot::channel();
|
||||
let _subscription = workspace.update(cx, |_, cx| {
|
||||
cx.on_release(move |_, _, _| {
|
||||
let _subscription = workspace.update(cx, |_, _, cx| {
|
||||
cx.on_release(move |_, _| {
|
||||
let _ = done_tx.send(());
|
||||
})
|
||||
});
|
||||
|
@ -565,7 +565,7 @@ mod tests {
|
|||
assert_eq!(cx.windows().len(), 1);
|
||||
let workspace = cx.windows()[0].downcast::<Workspace>().unwrap();
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
assert!(workspace.active_item_as::<Editor>(cx).is_none())
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -575,7 +575,7 @@ mod tests {
|
|||
|
||||
assert_eq!(cx.windows().len(), 1);
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
assert!(workspace.active_item_as::<Editor>(cx).is_some());
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -587,7 +587,7 @@ mod tests {
|
|||
|
||||
let workspace_2 = cx.windows()[1].downcast::<Workspace>().unwrap();
|
||||
workspace_2
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
assert!(workspace.active_item_as::<Editor>(cx).is_some());
|
||||
let items = workspace.items(cx).collect::<Vec<_>>();
|
||||
assert_eq!(items.len(), 1, "Workspace should have two items");
|
||||
|
@ -609,7 +609,7 @@ mod tests {
|
|||
assert_eq!(cx.windows().len(), 1);
|
||||
let workspace_1 = cx.windows()[0].downcast::<Workspace>().unwrap();
|
||||
workspace_1
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
assert!(workspace.active_item_as::<Editor>(cx).is_some())
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -620,7 +620,7 @@ mod tests {
|
|||
|
||||
assert_eq!(cx.windows().len(), 1);
|
||||
workspace_1
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
let items = workspace.items(cx).collect::<Vec<_>>();
|
||||
assert_eq!(items.len(), 2, "Workspace should have two items");
|
||||
})
|
||||
|
@ -633,7 +633,7 @@ mod tests {
|
|||
assert_eq!(cx.windows().len(), 2);
|
||||
let workspace_2 = cx.windows()[1].downcast::<Workspace>().unwrap();
|
||||
workspace_2
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
let items = workspace.items(cx).collect::<Vec<_>>();
|
||||
assert_eq!(items.len(), 1, "Workspace should have two items");
|
||||
})
|
||||
|
|
|
@ -10,8 +10,8 @@ use editor::actions::{
|
|||
};
|
||||
use editor::{Editor, EditorSettings};
|
||||
use gpui::{
|
||||
Action, ClickEvent, Corner, ElementId, EventEmitter, FocusHandle, FocusableView,
|
||||
InteractiveElement, ParentElement, Render, Styled, Subscription, View, ViewContext, WeakView,
|
||||
Action, ClickEvent, Context, Corner, ElementId, Entity, EventEmitter, FocusHandle, Focusable,
|
||||
InteractiveElement, ParentElement, Render, Styled, Subscription, WeakEntity, Window,
|
||||
};
|
||||
use search::{buffer_search, BufferSearchBar};
|
||||
use settings::{Settings, SettingsStore};
|
||||
|
@ -28,18 +28,18 @@ use zed_actions::{assistant::InlineAssist, outline::ToggleOutline};
|
|||
pub struct QuickActionBar {
|
||||
_inlay_hints_enabled_subscription: Option<Subscription>,
|
||||
active_item: Option<Box<dyn ItemHandle>>,
|
||||
buffer_search_bar: View<BufferSearchBar>,
|
||||
buffer_search_bar: Entity<BufferSearchBar>,
|
||||
show: bool,
|
||||
toggle_selections_handle: PopoverMenuHandle<ContextMenu>,
|
||||
toggle_settings_handle: PopoverMenuHandle<ContextMenu>,
|
||||
workspace: WeakView<Workspace>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
}
|
||||
|
||||
impl QuickActionBar {
|
||||
pub fn new(
|
||||
buffer_search_bar: View<BufferSearchBar>,
|
||||
buffer_search_bar: Entity<BufferSearchBar>,
|
||||
workspace: &Workspace,
|
||||
cx: &mut ViewContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let mut this = Self {
|
||||
_inlay_hints_enabled_subscription: None,
|
||||
|
@ -56,13 +56,13 @@ impl QuickActionBar {
|
|||
this
|
||||
}
|
||||
|
||||
fn active_editor(&self) -> Option<View<Editor>> {
|
||||
fn active_editor(&self) -> Option<Entity<Editor>> {
|
||||
self.active_item
|
||||
.as_ref()
|
||||
.and_then(|item| item.downcast::<Editor>())
|
||||
}
|
||||
|
||||
fn apply_settings(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn apply_settings(&mut self, cx: &mut Context<Self>) {
|
||||
let new_show = EditorSettings::get_global(cx).toolbar.quick_actions;
|
||||
if new_show != self.show {
|
||||
self.show = new_show;
|
||||
|
@ -82,7 +82,7 @@ impl QuickActionBar {
|
|||
}
|
||||
|
||||
impl Render for QuickActionBar {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let Some(editor) = self.active_editor() else {
|
||||
return div().id("empty quick action bar");
|
||||
};
|
||||
|
@ -128,9 +128,9 @@ impl Render for QuickActionBar {
|
|||
"Buffer Search",
|
||||
{
|
||||
let buffer_search_bar = self.buffer_search_bar.clone();
|
||||
move |_, cx| {
|
||||
move |_, window, cx| {
|
||||
buffer_search_bar.update(cx, |search_bar, cx| {
|
||||
search_bar.toggle(&buffer_search::Deploy::find(), cx)
|
||||
search_bar.toggle(&buffer_search::Deploy::find(), window, cx)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -146,10 +146,15 @@ impl Render for QuickActionBar {
|
|||
"Inline Assist",
|
||||
{
|
||||
let workspace = self.workspace.clone();
|
||||
move |_, cx| {
|
||||
move |_, window, cx| {
|
||||
if let Some(workspace) = workspace.upgrade() {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
AssistantPanel::inline_assist(workspace, &InlineAssist::default(), cx);
|
||||
AssistantPanel::inline_assist(
|
||||
workspace,
|
||||
&InlineAssist::default(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -167,14 +172,14 @@ impl Render for QuickActionBar {
|
|||
.style(ButtonStyle::Subtle)
|
||||
.toggle_state(self.toggle_selections_handle.is_deployed())
|
||||
.when(!self.toggle_selections_handle.is_deployed(), |this| {
|
||||
this.tooltip(|cx| Tooltip::text("Selection Controls", cx))
|
||||
this.tooltip(Tooltip::text("Selection Controls"))
|
||||
}),
|
||||
)
|
||||
.with_handle(self.toggle_selections_handle.clone())
|
||||
.anchor(Corner::TopRight)
|
||||
.menu(move |cx| {
|
||||
.menu(move |window, cx| {
|
||||
let focus = focus.clone();
|
||||
let menu = ContextMenu::build(cx, move |menu, _| {
|
||||
let menu = ContextMenu::build(window, cx, move |menu, _, _| {
|
||||
menu.context(focus.clone())
|
||||
.action("Select All", Box::new(SelectAll))
|
||||
.action(
|
||||
|
@ -217,13 +222,13 @@ impl Render for QuickActionBar {
|
|||
.style(ButtonStyle::Subtle)
|
||||
.toggle_state(self.toggle_settings_handle.is_deployed())
|
||||
.when(!self.toggle_settings_handle.is_deployed(), |this| {
|
||||
this.tooltip(|cx| Tooltip::text("Editor Controls", cx))
|
||||
this.tooltip(Tooltip::text("Editor Controls"))
|
||||
}),
|
||||
)
|
||||
.anchor(Corner::TopRight)
|
||||
.with_handle(self.toggle_settings_handle.clone())
|
||||
.menu(move |cx| {
|
||||
let menu = ContextMenu::build(cx, |mut menu, _| {
|
||||
.menu(move |window, cx| {
|
||||
let menu = ContextMenu::build(window, cx, |mut menu, _, _| {
|
||||
if supports_inlay_hints {
|
||||
menu = menu.toggleable_entry(
|
||||
"Inlay Hints",
|
||||
|
@ -232,11 +237,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleInlayHints.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_inlay_hints(
|
||||
&editor::actions::ToggleInlayHints,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -253,11 +259,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleSelectionMenu.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_selection_menu(
|
||||
&editor::actions::ToggleSelectionMenu,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
@ -273,11 +280,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleAutoSignatureHelp.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_auto_signature_help_menu(
|
||||
&editor::actions::ToggleAutoSignatureHelp,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -293,11 +301,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleInlineCompletions.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_inline_completions(
|
||||
&editor::actions::ToggleInlineCompletions,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -315,11 +324,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleGitBlameInline.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_git_blame_inline(
|
||||
&editor::actions::ToggleGitBlameInline,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
@ -335,11 +345,12 @@ impl Render for QuickActionBar {
|
|||
Some(editor::actions::ToggleGitBlame.boxed_clone()),
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.toggle_git_blame(
|
||||
&editor::actions::ToggleGitBlame,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
@ -356,10 +367,10 @@ impl Render for QuickActionBar {
|
|||
IconPosition::Start,
|
||||
None,
|
||||
{
|
||||
move |cx| {
|
||||
move |window, cx| {
|
||||
let new_value = !vim_mode_enabled;
|
||||
VimModeSetting::override_global(VimModeSetting(new_value), cx);
|
||||
cx.refresh();
|
||||
window.refresh();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -396,7 +407,7 @@ struct QuickActionBarButton {
|
|||
action: Box<dyn Action>,
|
||||
focus_handle: FocusHandle,
|
||||
tooltip: SharedString,
|
||||
on_click: Box<dyn Fn(&ClickEvent, &mut WindowContext)>,
|
||||
on_click: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
|
||||
}
|
||||
|
||||
impl QuickActionBarButton {
|
||||
|
@ -407,7 +418,7 @@ impl QuickActionBarButton {
|
|||
action: Box<dyn Action>,
|
||||
focus_handle: FocusHandle,
|
||||
tooltip: impl Into<SharedString>,
|
||||
on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
||||
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
|
@ -422,7 +433,7 @@ impl QuickActionBarButton {
|
|||
}
|
||||
|
||||
impl RenderOnce for QuickActionBarButton {
|
||||
fn render(self, _: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, _: &mut App) -> impl IntoElement {
|
||||
let tooltip = self.tooltip.clone();
|
||||
let action = self.action.boxed_clone();
|
||||
|
||||
|
@ -431,10 +442,10 @@ impl RenderOnce for QuickActionBarButton {
|
|||
.icon_size(IconSize::Small)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.toggle_state(self.toggled)
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::for_action_in(tooltip.clone(), &*action, &self.focus_handle, cx)
|
||||
.tooltip(move |window, cx| {
|
||||
Tooltip::for_action_in(tooltip.clone(), &*action, &self.focus_handle, window, cx)
|
||||
})
|
||||
.on_click(move |event, cx| (self.on_click)(event, cx))
|
||||
.on_click(move |event, window, cx| (self.on_click)(event, window, cx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,7 +453,8 @@ impl ToolbarItemView for QuickActionBar {
|
|||
fn set_active_pane_item(
|
||||
&mut self,
|
||||
active_pane_item: Option<&dyn ItemHandle>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> ToolbarItemLocation {
|
||||
self.active_item = active_pane_item.map(ItemHandle::boxed_clone);
|
||||
if let Some(active_item) = active_pane_item {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{AnyElement, Modifiers, WeakView};
|
||||
use gpui::{AnyElement, Modifiers, WeakEntity};
|
||||
use markdown_preview::{
|
||||
markdown_preview_view::MarkdownPreviewView, OpenPreview, OpenPreviewToTheSide,
|
||||
};
|
||||
|
@ -10,8 +10,8 @@ use super::QuickActionBar;
|
|||
impl QuickActionBar {
|
||||
pub fn render_toggle_markdown_preview(
|
||||
&self,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<AnyElement> {
|
||||
let mut active_editor_is_markdown = false;
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl QuickActionBar {
|
|||
.shape(IconButtonShape::Square)
|
||||
.icon_size(IconSize::Small)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.tooltip(move |cx| {
|
||||
.tooltip(move |window, cx| {
|
||||
Tooltip::with_meta(
|
||||
"Preview Markdown",
|
||||
Some(&markdown_preview::OpenPreview),
|
||||
|
@ -45,16 +45,17 @@ impl QuickActionBar {
|
|||
"{} to open in a split",
|
||||
text_for_keystroke(&alt_click, PlatformStyle::platform())
|
||||
),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_click(move |_, cx| {
|
||||
.on_click(move |_, window, cx| {
|
||||
if let Some(workspace) = workspace.upgrade() {
|
||||
workspace.update(cx, |_, cx| {
|
||||
if cx.modifiers().alt {
|
||||
cx.dispatch_action(Box::new(OpenPreviewToTheSide));
|
||||
if window.modifiers().alt {
|
||||
window.dispatch_action(Box::new(OpenPreviewToTheSide), cx);
|
||||
} else {
|
||||
cx.dispatch_action(Box::new(OpenPreview));
|
||||
window.dispatch_action(Box::new(OpenPreview), cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use gpui::ElementId;
|
||||
use gpui::{percentage, Animation, AnimationExt, AnyElement, Transformation, View};
|
||||
use gpui::{percentage, Animation, AnimationExt, AnyElement, Entity, Transformation};
|
||||
use picker::Picker;
|
||||
use repl::{
|
||||
components::{KernelPickerDelegate, KernelSelector},
|
||||
|
@ -32,7 +32,7 @@ struct ReplMenuState {
|
|||
}
|
||||
|
||||
impl QuickActionBar {
|
||||
pub fn render_repl_menu(&self, cx: &mut ViewContext<Self>) -> Option<AnyElement> {
|
||||
pub fn render_repl_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
|
||||
if !JupyterSettings::enabled(cx) {
|
||||
return None;
|
||||
}
|
||||
|
@ -82,10 +82,10 @@ impl QuickActionBar {
|
|||
|
||||
let editor = editor.downgrade();
|
||||
let dropdown_menu = PopoverMenu::new(element_id("menu"))
|
||||
.menu(move |cx| {
|
||||
.menu(move |window, cx| {
|
||||
let editor = editor.clone();
|
||||
let session = session.clone();
|
||||
ContextMenu::build(cx, move |menu, cx| {
|
||||
ContextMenu::build(window, cx, move |menu, _, cx| {
|
||||
let menu_state = session_state(session, cx);
|
||||
let status = menu_state.status;
|
||||
let editor = editor.clone();
|
||||
|
@ -93,7 +93,7 @@ impl QuickActionBar {
|
|||
menu.map(|menu| {
|
||||
if status.is_connected() {
|
||||
let status = status.clone();
|
||||
menu.custom_row(move |_cx| {
|
||||
menu.custom_row(move |_window, _cx| {
|
||||
h_flex()
|
||||
.child(
|
||||
Label::new(format!(
|
||||
|
@ -106,7 +106,7 @@ impl QuickActionBar {
|
|||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.custom_row(move |_cx| {
|
||||
.custom_row(move |_window, _cx| {
|
||||
h_flex()
|
||||
.child(
|
||||
Label::new(status.clone().to_string())
|
||||
|
@ -117,7 +117,7 @@ impl QuickActionBar {
|
|||
})
|
||||
} else {
|
||||
let status = status.clone();
|
||||
menu.custom_row(move |_cx| {
|
||||
menu.custom_row(move |_window, _cx| {
|
||||
h_flex()
|
||||
.child(
|
||||
Label::new(format!("{}...", status.clone().to_string()))
|
||||
|
@ -130,7 +130,7 @@ impl QuickActionBar {
|
|||
})
|
||||
.separator()
|
||||
.custom_entry(
|
||||
move |_cx| {
|
||||
move |_window, _cx| {
|
||||
Label::new(if has_nonempty_selection {
|
||||
"Run Selection"
|
||||
} else {
|
||||
|
@ -140,13 +140,13 @@ impl QuickActionBar {
|
|||
},
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
repl::run(editor.clone(), true, cx).log_err();
|
||||
move |window, cx| {
|
||||
repl::run(editor.clone(), true, window, cx).log_err();
|
||||
}
|
||||
},
|
||||
)
|
||||
.custom_entry(
|
||||
move |_cx| {
|
||||
move |_window, _cx| {
|
||||
Label::new("Interrupt")
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Error)
|
||||
|
@ -154,13 +154,13 @@ impl QuickActionBar {
|
|||
},
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |_, cx| {
|
||||
repl::interrupt(editor.clone(), cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
.custom_entry(
|
||||
move |_cx| {
|
||||
move |_window, _cx| {
|
||||
Label::new("Clear Outputs")
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Muted)
|
||||
|
@ -168,14 +168,14 @@ impl QuickActionBar {
|
|||
},
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
move |_, cx| {
|
||||
repl::clear_outputs(editor.clone(), cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
.separator()
|
||||
.custom_entry(
|
||||
move |_cx| {
|
||||
move |_window, _cx| {
|
||||
Label::new("Shut Down Kernel")
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Error)
|
||||
|
@ -183,13 +183,13 @@ impl QuickActionBar {
|
|||
},
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
repl::shutdown(editor.clone(), cx);
|
||||
move |window, cx| {
|
||||
repl::shutdown(editor.clone(), window, cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
.custom_entry(
|
||||
move |_cx| {
|
||||
move |_window, _cx| {
|
||||
Label::new("Restart Kernel")
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Error)
|
||||
|
@ -197,8 +197,8 @@ impl QuickActionBar {
|
|||
},
|
||||
{
|
||||
let editor = editor.clone();
|
||||
move |cx| {
|
||||
repl::restart(editor.clone(), cx);
|
||||
move |window, cx| {
|
||||
repl::restart(editor.clone(), window, cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -216,7 +216,7 @@ impl QuickActionBar {
|
|||
.size(IconSize::XSmall)
|
||||
.color(Color::Muted),
|
||||
)
|
||||
.tooltip(move |cx| Tooltip::text("REPL Menu", cx))
|
||||
.tooltip(Tooltip::text("REPL Menu"))
|
||||
.width(rems(1.).into())
|
||||
.disabled(menu_state.popover_disabled),
|
||||
);
|
||||
|
@ -241,8 +241,8 @@ impl QuickActionBar {
|
|||
})
|
||||
.size(ButtonSize::Compact)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.tooltip(move |cx| Tooltip::text(menu_state.tooltip.clone(), cx))
|
||||
.on_click(|_, cx| cx.dispatch_action(Box::new(repl::Run {})))
|
||||
.tooltip(Tooltip::text(menu_state.tooltip))
|
||||
.on_click(|_, window, cx| window.dispatch_action(Box::new(repl::Run {}), cx))
|
||||
.into_any_element();
|
||||
|
||||
Some(
|
||||
|
@ -256,7 +256,7 @@ impl QuickActionBar {
|
|||
pub fn render_repl_launch_menu(
|
||||
&self,
|
||||
kernel_specification: KernelSpecification,
|
||||
cx: &mut ViewContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<AnyElement> {
|
||||
let tooltip: SharedString =
|
||||
SharedString::from(format!("Start REPL for {}", kernel_specification.name()));
|
||||
|
@ -269,14 +269,16 @@ impl QuickActionBar {
|
|||
.size(ButtonSize::Compact)
|
||||
.icon_color(Color::Muted)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.tooltip(move |cx| Tooltip::text(tooltip.clone(), cx))
|
||||
.on_click(|_, cx| cx.dispatch_action(Box::new(repl::Run {}))),
|
||||
.tooltip(Tooltip::text(tooltip))
|
||||
.on_click(|_, window, cx| {
|
||||
window.dispatch_action(Box::new(repl::Run {}), cx)
|
||||
}),
|
||||
)
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_kernel_selector(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
pub fn render_kernel_selector(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let editor = if let Some(editor) = self.active_editor() {
|
||||
editor
|
||||
} else {
|
||||
|
@ -290,7 +292,9 @@ impl QuickActionBar {
|
|||
let session = repl::session(editor.downgrade(), cx);
|
||||
|
||||
let current_kernelspec = match session {
|
||||
SessionSupport::ActiveSession(view) => Some(view.read(cx).kernel_specification.clone()),
|
||||
SessionSupport::ActiveSession(session) => {
|
||||
Some(session.read(cx).kernel_specification.clone())
|
||||
}
|
||||
SessionSupport::Inactive(kernel_specification) => Some(kernel_specification),
|
||||
SessionSupport::RequiresSetup(_language_name) => None,
|
||||
SessionSupport::Unsupported => None,
|
||||
|
@ -302,8 +306,8 @@ impl QuickActionBar {
|
|||
PopoverMenuHandle::default();
|
||||
KernelSelector::new(
|
||||
{
|
||||
Box::new(move |kernelspec, cx| {
|
||||
repl::assign_kernelspec(kernelspec, editor.downgrade(), cx).ok();
|
||||
Box::new(move |kernelspec, window, cx| {
|
||||
repl::assign_kernelspec(kernelspec, editor.downgrade(), window, cx).ok();
|
||||
})
|
||||
},
|
||||
worktree_id,
|
||||
|
@ -340,17 +344,13 @@ impl QuickActionBar {
|
|||
.size(IconSize::XSmall),
|
||||
),
|
||||
)
|
||||
.tooltip(move |cx| Tooltip::text("Select Kernel", cx)),
|
||||
.tooltip(Tooltip::text("Select Kernel")),
|
||||
)
|
||||
.with_handle(menu_handle.clone())
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
pub fn render_repl_setup(
|
||||
&self,
|
||||
language: &str,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<AnyElement> {
|
||||
pub fn render_repl_setup(&self, language: &str, cx: &mut Context<Self>) -> Option<AnyElement> {
|
||||
let tooltip: SharedString = SharedString::from(format!("Setup Zed REPL for {}", language));
|
||||
Some(
|
||||
h_flex()
|
||||
|
@ -362,8 +362,8 @@ impl QuickActionBar {
|
|||
.shape(ui::IconButtonShape::Square)
|
||||
.icon_size(ui::IconSize::Small)
|
||||
.icon_color(Color::Muted)
|
||||
.tooltip(move |cx| Tooltip::text(tooltip.clone(), cx))
|
||||
.on_click(|_, cx| {
|
||||
.tooltip(Tooltip::text(tooltip.clone()))
|
||||
.on_click(|_, _window, cx| {
|
||||
cx.open_url(&format!("{}#installation", ZED_REPL_DOCUMENTATION))
|
||||
}),
|
||||
)
|
||||
|
@ -372,7 +372,7 @@ impl QuickActionBar {
|
|||
}
|
||||
}
|
||||
|
||||
fn session_state(session: View<Session>, cx: &WindowContext) -> ReplMenuState {
|
||||
fn session_state(session: Entity<Session>, cx: &mut App) -> ReplMenuState {
|
||||
let session = session.read(cx);
|
||||
|
||||
let kernel_name = session.kernel_specification.name();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue