mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Extract a separate trait for Project and Workspace interfaces
This commit is contained in:
parent
ed5f1d3bdd
commit
cadf8d0160
11 changed files with 706 additions and 288 deletions
|
@ -103,9 +103,9 @@ impl ActivityIndicator {
|
|||
);
|
||||
});
|
||||
workspace.add_item(
|
||||
Box::new(
|
||||
cx.add_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx)),
|
||||
),
|
||||
Box::new(cx.add_view(|cx| {
|
||||
Editor::for_buffer(buffer, Some(Arc::new(project.clone())), cx)
|
||||
})),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -167,8 +167,11 @@ impl ProjectDiagnosticsEditor {
|
|||
|
||||
let excerpts = cx.add_model(|cx| MultiBuffer::new(project_handle.read(cx).replica_id()));
|
||||
let editor = cx.add_view(|cx| {
|
||||
let mut editor =
|
||||
Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), cx);
|
||||
let mut editor = Editor::for_multibuffer(
|
||||
excerpts.clone(),
|
||||
Some(Arc::new(project_handle.clone())),
|
||||
cx,
|
||||
);
|
||||
editor.set_vertical_scroll_margin(5, cx);
|
||||
editor
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1662,7 +1662,7 @@ impl EditorElement {
|
|||
let include_root = editor
|
||||
.project
|
||||
.as_ref()
|
||||
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
|
||||
.map(|project| project.visible_worktrees_count(cx) > 1)
|
||||
.unwrap_or_default();
|
||||
let jump_icon = project::File::from_dyn(buffer.file()).map(|file| {
|
||||
let jump_path = ProjectPath {
|
||||
|
@ -1691,20 +1691,14 @@ impl EditorElement {
|
|||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, editor, cx| {
|
||||
if let Some(workspace) = editor
|
||||
.workspace
|
||||
.as_ref()
|
||||
.and_then(|(workspace, _)| workspace.upgrade(cx))
|
||||
{
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
Editor::jump(
|
||||
workspace,
|
||||
jump_path.clone(),
|
||||
jump_position,
|
||||
jump_anchor,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
if let Some((workspace, _)) = editor.workspace.as_mut() {
|
||||
Editor::jump(
|
||||
&**workspace,
|
||||
jump_path.clone(),
|
||||
jump_position,
|
||||
jump_anchor,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
})
|
||||
.with_tooltip::<JumpIcon>(
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
display_map::{InlayOffset, ToDisplayPoint},
|
||||
link_go_to_definition::{InlayHighlight, RangeInEditor},
|
||||
Anchor, AnchorRangeExt, DisplayPoint, Editor, EditorSettings, EditorSnapshot, EditorStyle,
|
||||
ExcerptId, RangeToAnchorExt,
|
||||
ExcerptId, ProjectT, RangeToAnchorExt, WorkspaceT,
|
||||
};
|
||||
use futures::FutureExt;
|
||||
use gpui::{
|
||||
|
@ -103,11 +103,11 @@ pub fn hover_at_inlay(editor: &mut Editor, inlay_hover: InlayHover, cx: &mut Vie
|
|||
cx.background()
|
||||
.timer(Duration::from_millis(HOVER_DELAY_MILLIS))
|
||||
.await;
|
||||
this.update(&mut cx, |this, _| {
|
||||
let language_registry = this.update(&mut cx, |this, cx| {
|
||||
this.hover_state.diagnostic_popover = None;
|
||||
project.languages(cx)
|
||||
})?;
|
||||
|
||||
let language_registry = project.update(&mut cx, |p, _| p.languages().clone());
|
||||
let blocks = vec![inlay_hover.tooltip];
|
||||
let parsed_content = parse_blocks(&blocks, &language_registry, None).await;
|
||||
|
||||
|
@ -252,11 +252,7 @@ fn show_hover(
|
|||
};
|
||||
|
||||
// query the LSP for hover info
|
||||
let hover_request = cx.update(|cx| {
|
||||
project.update(cx, |project, cx| {
|
||||
project.hover(&buffer, buffer_position, cx)
|
||||
})
|
||||
});
|
||||
let hover_request = cx.update(|cx| project.hover(&buffer, buffer_position, cx));
|
||||
|
||||
if let Some(delay) = delay {
|
||||
delay.await;
|
||||
|
@ -310,7 +306,7 @@ fn show_hover(
|
|||
anchor..anchor
|
||||
};
|
||||
|
||||
let language_registry = project.update(&mut cx, |p, _| p.languages().clone());
|
||||
let language_registry = cx.update(|cx| project.languages(cx));
|
||||
let blocks = hover_result.contents;
|
||||
let language = hover_result.language;
|
||||
let parsed_content = parse_blocks(&blocks, &language_registry, language).await;
|
||||
|
@ -423,7 +419,7 @@ impl HoverState {
|
|||
snapshot: &EditorSnapshot,
|
||||
style: &EditorStyle,
|
||||
visible_rows: Range<u32>,
|
||||
workspace: Option<WeakViewHandle<Workspace>>,
|
||||
workspace: Option<Arc<dyn WorkspaceT>>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Option<(DisplayPoint, Vec<AnyElement<Editor>>)> {
|
||||
// If there is a diagnostic, position the popovers based on that.
|
||||
|
@ -462,7 +458,7 @@ impl HoverState {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InfoPopover {
|
||||
pub project: ModelHandle<Project>,
|
||||
pub project: Arc<dyn ProjectT>,
|
||||
symbol_range: RangeInEditor,
|
||||
pub blocks: Vec<HoverBlock>,
|
||||
parsed_content: ParsedMarkdown,
|
||||
|
@ -472,7 +468,7 @@ impl InfoPopover {
|
|||
pub fn render(
|
||||
&mut self,
|
||||
style: &EditorStyle,
|
||||
workspace: Option<WeakViewHandle<Workspace>>,
|
||||
workspace: Option<Arc<dyn WorkspaceT>>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> AnyElement<Editor> {
|
||||
MouseEventHandler::new::<InfoPopover, _>(0, cx, |_, cx| {
|
||||
|
|
|
@ -539,14 +539,12 @@ impl InlayHintCache {
|
|||
.buffer(buffer_id)
|
||||
.and_then(|buffer| {
|
||||
let project = editor.project.as_ref()?;
|
||||
Some(project.update(cx, |project, cx| {
|
||||
project.resolve_inlay_hint(
|
||||
hint_to_resolve,
|
||||
buffer,
|
||||
server_id,
|
||||
cx,
|
||||
)
|
||||
}))
|
||||
Some(project.resolve_inlay_hint(
|
||||
hint_to_resolve,
|
||||
buffer,
|
||||
server_id,
|
||||
cx,
|
||||
))
|
||||
})
|
||||
})?;
|
||||
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||
|
@ -896,9 +894,9 @@ async fn fetch_and_update_hints(
|
|||
.buffer(query.buffer_id)
|
||||
.and_then(|buffer| {
|
||||
let project = editor.project.as_ref()?;
|
||||
Some(project.update(cx, |project, cx| {
|
||||
Some(
|
||||
project.inlay_hints(buffer, fetch_range.clone(), cx)
|
||||
}))
|
||||
)
|
||||
})
|
||||
})
|
||||
.ok()
|
||||
|
|
|
@ -129,8 +129,11 @@ impl FollowableItem for Editor {
|
|||
});
|
||||
|
||||
cx.add_view(|cx| {
|
||||
let mut editor =
|
||||
Editor::for_multibuffer(multibuffer, Some(project.clone()), cx);
|
||||
let mut editor = Editor::for_multibuffer(
|
||||
multibuffer,
|
||||
Some(Arc::new(project.clone())),
|
||||
cx,
|
||||
);
|
||||
editor.remote_id = Some(remote_id);
|
||||
editor
|
||||
})
|
||||
|
@ -652,7 +655,7 @@ impl Item for Editor {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
self.report_editor_event("save", None, cx);
|
||||
let format = self.perform_format(project.clone(), FormatTrigger::Save, cx);
|
||||
let format = self.perform_format(Arc::new(project.clone()), FormatTrigger::Save, cx);
|
||||
let buffers = self.buffer().clone().read(cx).all_buffers();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
format.await?;
|
||||
|
@ -787,7 +790,7 @@ impl Item for Editor {
|
|||
cx,
|
||||
self.project
|
||||
.as_ref()
|
||||
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
|
||||
.map(|project| project.visible_worktrees_count(cx) > 1)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.map(|path| path.to_string_lossy().to_string())
|
||||
|
@ -807,7 +810,7 @@ impl Item for Editor {
|
|||
fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
|
||||
let workspace_id = workspace.database_id();
|
||||
let item_id = cx.view_id();
|
||||
self.workspace = Some((workspace.weak_handle(), workspace.database_id()));
|
||||
self.workspace = Some((Arc::new(workspace.weak_handle()), workspace.database_id()));
|
||||
|
||||
fn serialize(
|
||||
buffer: ModelHandle<Buffer>,
|
||||
|
@ -879,7 +882,8 @@ impl Item for Editor {
|
|||
.context("Project item at stored path was not a buffer")?;
|
||||
Ok(pane.update(&mut cx, |_, cx| {
|
||||
cx.add_view(|cx| {
|
||||
let mut editor = Editor::for_buffer(buffer, Some(project), cx);
|
||||
let mut editor =
|
||||
Editor::for_buffer(buffer, Some(Arc::new(project)), cx);
|
||||
editor.read_scroll_position_from_db(item_id, workspace_id, cx);
|
||||
editor
|
||||
})
|
||||
|
@ -898,7 +902,7 @@ impl ProjectItem for Editor {
|
|||
buffer: ModelHandle<Buffer>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
Self::for_buffer(buffer, Some(project), cx)
|
||||
Self::for_buffer(buffer, Some(Arc::new(project)), cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -396,16 +396,14 @@ pub fn show_link_definition(
|
|||
let result = match &trigger_point {
|
||||
TriggerPoint::Text(_) => {
|
||||
// query the LSP for definition info
|
||||
cx.update(|cx| {
|
||||
project.update(cx, |project, cx| match definition_kind {
|
||||
LinkDefinitionKind::Symbol => {
|
||||
project.definition(&buffer, buffer_position, cx)
|
||||
}
|
||||
cx.update(|cx| match definition_kind {
|
||||
LinkDefinitionKind::Symbol => {
|
||||
project.definition(&buffer, buffer_position, cx)
|
||||
}
|
||||
|
||||
LinkDefinitionKind::Type => {
|
||||
project.type_definition(&buffer, buffer_position, cx)
|
||||
}
|
||||
})
|
||||
LinkDefinitionKind::Type => {
|
||||
project.type_definition(&buffer, buffer_position, cx)
|
||||
}
|
||||
})
|
||||
.await
|
||||
.ok()
|
||||
|
|
|
@ -71,7 +71,7 @@ impl FeedbackEditor {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let editor = cx.add_view(|cx| {
|
||||
let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx);
|
||||
let mut editor = Editor::for_buffer(buffer, Some(Arc::new(project.clone())), cx);
|
||||
editor.set_vertical_scroll_margin(5, cx);
|
||||
editor
|
||||
});
|
||||
|
|
|
@ -965,7 +965,7 @@ impl ProjectSearchView {
|
|||
editor
|
||||
});
|
||||
let results_editor = cx.add_view(|cx| {
|
||||
let mut editor = Editor::for_multibuffer(excerpts, Some(project.clone()), cx);
|
||||
let mut editor = Editor::for_multibuffer(excerpts, Some(Arc::new(project.clone())), cx);
|
||||
editor.set_searchable(false);
|
||||
editor
|
||||
});
|
||||
|
|
|
@ -195,7 +195,11 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
|||
});
|
||||
workspace.add_item(
|
||||
Box::new(cx.add_view(|cx| {
|
||||
Editor::for_multibuffer(buffer, Some(project.clone()), cx)
|
||||
Editor::for_multibuffer(
|
||||
buffer,
|
||||
Some(Arc::new(project.clone())),
|
||||
cx,
|
||||
)
|
||||
})),
|
||||
cx,
|
||||
);
|
||||
|
@ -535,11 +539,9 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
|||
MultiBuffer::singleton(buffer, cx).with_title("Log".into())
|
||||
});
|
||||
workspace.add_item(
|
||||
Box::new(
|
||||
cx.add_view(|cx| {
|
||||
Editor::for_multibuffer(buffer, Some(project), cx)
|
||||
}),
|
||||
),
|
||||
Box::new(cx.add_view(|cx| {
|
||||
Editor::for_multibuffer(buffer, Some(Arc::new(project)), cx)
|
||||
})),
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -706,7 +708,7 @@ fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Works
|
|||
MultiBuffer::singleton(buffer, cx).with_title("Telemetry Log".into())
|
||||
});
|
||||
workspace.add_item(
|
||||
Box::new(cx.add_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))),
|
||||
Box::new(cx.add_view(|cx| Editor::for_multibuffer(buffer, Some(Arc::new(project)), cx))),
|
||||
cx,
|
||||
);
|
||||
}).log_err()?;
|
||||
|
@ -741,7 +743,7 @@ fn open_bundled_file(
|
|||
});
|
||||
workspace.add_item(
|
||||
Box::new(cx.add_view(|cx| {
|
||||
Editor::for_multibuffer(buffer, Some(project.clone()), cx)
|
||||
Editor::for_multibuffer(buffer, Some(Arc::new(project.clone())), cx)
|
||||
})),
|
||||
cx,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue