Skip to content

Commit 29f9853

Browse files
authored
svg_preview: Remove unnecessary dependency on editor (zed-industries#43147)
Editor is a choke point in our compilation graph while also being a very common crate that is being edited. So reducing things that depend on it will generally improve compilation times for us. Release Notes: - N/A *or* Added/Fixed/Improved ...
1 parent 1e45c99 commit 29f9853

File tree

24 files changed

+127
-119
lines changed

24 files changed

+127
-119
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/agent_ui/src/agent_diff.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use editor::{
1313
scroll::Autoscroll,
1414
};
1515
use gpui::{
16-
Action, AnyElement, AnyView, App, AppContext, Empty, Entity, EventEmitter, FocusHandle,
17-
Focusable, Global, SharedString, Subscription, Task, WeakEntity, Window, prelude::*,
16+
Action, AnyElement, App, AppContext, Empty, Entity, EventEmitter, FocusHandle, Focusable,
17+
Global, SharedString, Subscription, Task, WeakEntity, Window, prelude::*,
1818
};
1919

2020
use language::{Buffer, Capability, DiskState, OffsetRangeExt, Point};
@@ -580,11 +580,11 @@ impl Item for AgentDiffPane {
580580
type_id: TypeId,
581581
self_handle: &'a Entity<Self>,
582582
_: &'a App,
583-
) -> Option<AnyView> {
583+
) -> Option<gpui::AnyEntity> {
584584
if type_id == TypeId::of::<Self>() {
585-
Some(self_handle.to_any())
585+
Some(self_handle.clone().into())
586586
} else if type_id == TypeId::of::<Editor>() {
587-
Some(self.editor.to_any())
587+
Some(self.editor.clone().into())
588588
} else {
589589
None
590590
}

crates/agent_ui/src/text_thread_editor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use editor::{FoldPlaceholder, display_map::CreaseId};
2222
use fs::Fs;
2323
use futures::FutureExt;
2424
use gpui::{
25-
Action, Animation, AnimationExt, AnyElement, AnyView, App, ClipboardEntry, ClipboardItem,
26-
Empty, Entity, EventEmitter, FocusHandle, Focusable, FontWeight, Global, InteractiveElement,
27-
IntoElement, ParentElement, Pixels, Render, RenderImage, SharedString, Size,
28-
StatefulInteractiveElement, Styled, Subscription, Task, WeakEntity, actions, div, img, point,
29-
prelude::*, pulsating_between, size,
25+
Action, Animation, AnimationExt, AnyElement, App, ClipboardEntry, ClipboardItem, Empty, Entity,
26+
EventEmitter, FocusHandle, Focusable, FontWeight, Global, InteractiveElement, IntoElement,
27+
ParentElement, Pixels, Render, RenderImage, SharedString, Size, StatefulInteractiveElement,
28+
Styled, Subscription, Task, WeakEntity, actions, div, img, point, prelude::*,
29+
pulsating_between, size,
3030
};
3131
use language::{
3232
BufferSnapshot, LspAdapterDelegate, ToOffset,
@@ -66,7 +66,7 @@ use workspace::{
6666
};
6767
use workspace::{
6868
Save, Toast, Workspace,
69-
item::{self, FollowableItem, Item, ItemHandle},
69+
item::{self, FollowableItem, Item},
7070
notifications::NotificationId,
7171
pane,
7272
searchable::{SearchEvent, SearchableItem},
@@ -2588,11 +2588,11 @@ impl Item for TextThreadEditor {
25882588
type_id: TypeId,
25892589
self_handle: &'a Entity<Self>,
25902590
_: &'a App,
2591-
) -> Option<AnyView> {
2591+
) -> Option<gpui::AnyEntity> {
25922592
if type_id == TypeId::of::<Self>() {
2593-
Some(self_handle.to_any())
2593+
Some(self_handle.clone().into())
25942594
} else if type_id == TypeId::of::<Editor>() {
2595-
Some(self.editor.to_any())
2595+
Some(self.editor.clone().into())
25962596
} else {
25972597
None
25982598
}

crates/breadcrumbs/src/breadcrumbs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Render for Breadcrumbs {
123123
.upgrade()
124124
.zip(zed_actions::outline::TOGGLE_OUTLINE.get())
125125
{
126-
callback(editor.to_any(), window, cx);
126+
callback(editor.to_any_view(), window, cx);
127127
}
128128
}
129129
})

crates/collab_ui/src/channel_view.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use editor::{
1111
display_map::ToDisplayPoint, scroll::Autoscroll,
1212
};
1313
use gpui::{
14-
AnyView, App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render,
14+
App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render,
1515
Subscription, Task, VisualContext as _, WeakEntity, Window, actions,
1616
};
1717
use project::Project;
@@ -25,7 +25,7 @@ use util::ResultExt;
2525
use workspace::{CollaboratorId, item::TabContentParams};
2626
use workspace::{
2727
ItemNavHistory, Pane, SaveIntent, Toast, ViewId, Workspace, WorkspaceId,
28-
item::{FollowableItem, Item, ItemEvent, ItemHandle},
28+
item::{FollowableItem, Item, ItemEvent},
2929
searchable::SearchableItemHandle,
3030
};
3131
use workspace::{item::Dedup, notifications::NotificationId};
@@ -441,11 +441,11 @@ impl Item for ChannelView {
441441
type_id: TypeId,
442442
self_handle: &'a Entity<Self>,
443443
_: &'a App,
444-
) -> Option<AnyView> {
444+
) -> Option<gpui::AnyEntity> {
445445
if type_id == TypeId::of::<Self>() {
446-
Some(self_handle.to_any())
446+
Some(self_handle.clone().into())
447447
} else if type_id == TypeId::of::<Editor>() {
448-
Some(self.editor.to_any())
448+
Some(self.editor.clone().into())
449449
} else {
450450
None
451451
}

crates/debugger_ui/src/stack_trace_view.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use editor::{
77
RowHighlightOptions, SelectionEffects, ToPoint, scroll::Autoscroll,
88
};
99
use gpui::{
10-
AnyView, App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString,
10+
App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString,
1111
Subscription, Task, WeakEntity, Window,
1212
};
1313
use language::{BufferSnapshot, Capability, Point, Selection, SelectionGoal, TreeSitterOptions};
@@ -418,11 +418,11 @@ impl Item for StackTraceView {
418418
type_id: TypeId,
419419
self_handle: &'a Entity<Self>,
420420
_: &'a App,
421-
) -> Option<AnyView> {
421+
) -> Option<gpui::AnyEntity> {
422422
if type_id == TypeId::of::<Self>() {
423-
Some(self_handle.to_any())
423+
Some(self_handle.clone().into())
424424
} else if type_id == TypeId::of::<Editor>() {
425-
Some(self.editor.to_any())
425+
Some(self.editor.clone().into())
426426
} else {
427427
None
428428
}

crates/diagnostics/src/buffer_diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,11 @@ impl Item for BufferDiagnosticsEditor {
680680
type_id: std::any::TypeId,
681681
self_handle: &'a Entity<Self>,
682682
_: &'a App,
683-
) -> Option<gpui::AnyView> {
683+
) -> Option<gpui::AnyEntity> {
684684
if type_id == TypeId::of::<Self>() {
685-
Some(self_handle.to_any())
685+
Some(self_handle.clone().into())
686686
} else if type_id == TypeId::of::<Editor>() {
687-
Some(self.editor.to_any())
687+
Some(self.editor.clone().into())
688688
} else {
689689
None
690690
}

crates/diagnostics/src/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use editor::{
1717
multibuffer_context_lines,
1818
};
1919
use gpui::{
20-
AnyElement, AnyView, App, AsyncApp, Context, Entity, EventEmitter, FocusHandle, FocusOutEvent,
20+
AnyElement, App, AsyncApp, Context, Entity, EventEmitter, FocusHandle, FocusOutEvent,
2121
Focusable, Global, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
2222
Styled, Subscription, Task, WeakEntity, Window, actions, div,
2323
};
@@ -880,11 +880,11 @@ impl Item for ProjectDiagnosticsEditor {
880880
type_id: TypeId,
881881
self_handle: &'a Entity<Self>,
882882
_: &'a App,
883-
) -> Option<AnyView> {
883+
) -> Option<gpui::AnyEntity> {
884884
if type_id == TypeId::of::<Self>() {
885-
Some(self_handle.to_any())
885+
Some(self_handle.clone().into())
886886
} else if type_id == TypeId::of::<Editor>() {
887-
Some(self.editor.to_any())
887+
Some(self.editor.clone().into())
888888
} else {
889889
None
890890
}

crates/editor/src/editor_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26983,7 +26983,7 @@ async fn test_non_utf_8_opens(cx: &mut TestAppContext) {
2698326983
.unwrap();
2698426984

2698526985
assert_eq!(
26986-
handle.to_any().entity_type(),
26986+
handle.to_any_view().entity_type(),
2698726987
TypeId::of::<InvalidItemView>()
2698826988
);
2698926989
}

crates/editor/src/items.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,21 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor)
588588
impl Item for Editor {
589589
type Event = EditorEvent;
590590

591+
fn act_as_type<'a>(
592+
&'a self,
593+
type_id: TypeId,
594+
self_handle: &'a Entity<Self>,
595+
cx: &'a App,
596+
) -> Option<gpui::AnyEntity> {
597+
if TypeId::of::<Self>() == type_id {
598+
Some(self_handle.clone().into())
599+
} else if TypeId::of::<MultiBuffer>() == type_id {
600+
Some(self_handle.read(cx).buffer.clone().into())
601+
} else {
602+
None
603+
}
604+
}
605+
591606
fn navigate(
592607
&mut self,
593608
data: Box<dyn std::any::Any>,

0 commit comments

Comments
 (0)