Make navigation history work with project diagnostics

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-20 18:21:48 +01:00
parent c450945001
commit 377e41a90f
3 changed files with 50 additions and 11 deletions

View file

@ -15,7 +15,14 @@ use gpui::{
use language::{Bias, Buffer, Diagnostic, DiagnosticEntry, Point, Selection, SelectionGoal}; use language::{Bias, Buffer, Diagnostic, DiagnosticEntry, Point, Selection, SelectionGoal};
use postage::watch; use postage::watch;
use project::{Project, ProjectPath}; use project::{Project, ProjectPath};
use std::{any::TypeId, cmp::Ordering, mem, ops::Range, path::PathBuf, sync::Arc}; use std::{
any::{Any, TypeId},
cmp::Ordering,
mem,
ops::Range,
path::PathBuf,
sync::Arc,
};
use util::TryFutureExt; use util::TryFutureExt;
use workspace::{ItemNavHistory, Workspace}; use workspace::{ItemNavHistory, Workspace};
@ -517,10 +524,19 @@ impl workspace::Item for ProjectDiagnostics {
fn build_view( fn build_view(
handle: ModelHandle<Self>, handle: ModelHandle<Self>,
workspace: &Workspace, workspace: &Workspace,
_: ItemNavHistory, nav_history: ItemNavHistory,
cx: &mut ViewContext<Self::View>, cx: &mut ViewContext<Self::View>,
) -> Self::View { ) -> Self::View {
ProjectDiagnosticsEditor::new(handle, workspace.weak_handle(), workspace.settings(), cx) let diagnostics = ProjectDiagnosticsEditor::new(
handle,
workspace.weak_handle(),
workspace.settings(),
cx,
);
diagnostics
.editor
.update(cx, |editor, _| editor.set_nav_history(Some(nav_history)));
diagnostics
} }
fn project_entry(&self) -> Option<project::ProjectEntry> { fn project_entry(&self) -> Option<project::ProjectEntry> {
@ -543,6 +559,11 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
None None
} }
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) {
self.editor
.update(cx, |editor, cx| editor.navigate(data, cx));
}
fn is_dirty(&self, cx: &AppContext) -> bool { fn is_dirty(&self, cx: &AppContext) -> bool {
self.excerpts.read(cx).read(cx).is_dirty() self.excerpts.read(cx).read(cx).is_dirty()
} }
@ -587,12 +608,21 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
where where
Self: Sized, Self: Sized,
{ {
Some(ProjectDiagnosticsEditor::new( let diagnostics = ProjectDiagnosticsEditor::new(
self.model.clone(), self.model.clone(),
self.workspace.clone(), self.workspace.clone(),
self.settings.clone(), self.settings.clone(),
cx, cx,
)) );
diagnostics.editor.update(cx, |editor, cx| {
let nav_history = self
.editor
.read(cx)
.nav_history()
.map(|nav_history| ItemNavHistory::new(nav_history.history(), &cx.handle()));
editor.set_nav_history(nav_history);
});
Some(diagnostics)
} }
fn act_as_type( fn act_as_type(
@ -609,6 +639,10 @@ impl workspace::ItemView for ProjectDiagnosticsEditor {
None None
} }
} }
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
self.editor.update(cx, |editor, cx| editor.deactivated(cx));
}
} }
fn path_header_renderer(buffer: ModelHandle<Buffer>, build_settings: BuildSettings) -> RenderBlock { fn path_header_renderer(buffer: ModelHandle<Buffer>, build_settings: BuildSettings) -> RenderBlock {

View file

@ -470,7 +470,7 @@ impl Editor {
clone.nav_history = self clone.nav_history = self
.nav_history .nav_history
.as_ref() .as_ref()
.map(|nav_history| nav_history.clone(&cx.handle())); .map(|nav_history| ItemNavHistory::new(nav_history.history(), &cx.handle()));
clone clone
} }
@ -2459,6 +2459,14 @@ impl Editor {
self.update_selections(vec![selection], Some(Autoscroll::Fit), cx); self.update_selections(vec![selection], Some(Autoscroll::Fit), cx);
} }
pub fn set_nav_history(&mut self, nav_history: Option<ItemNavHistory>) {
self.nav_history = nav_history;
}
pub fn nav_history(&self) -> Option<&ItemNavHistory> {
self.nav_history.as_ref()
}
fn push_to_nav_history( fn push_to_nav_history(
&self, &self,
position: Anchor, position: Anchor,

View file

@ -551,11 +551,8 @@ impl ItemNavHistory {
} }
} }
pub fn clone<T: ItemView>(&self, item_view: &ViewHandle<T>) -> Self { pub fn history(&self) -> Rc<RefCell<NavHistory>> {
Self { self.history.clone()
history: self.history.clone(),
item_view: Rc::new(item_view.downgrade()),
}
} }
pub fn push<D: 'static + Any>(&self, data: Option<D>) { pub fn push<D: 'static + Any>(&self, data: Option<D>) {