Move ProjectDiagnosticsEditor::jump
to Editor::jump
This commit is contained in:
parent
5fdafbe8c9
commit
c2eaf6128e
2 changed files with 39 additions and 31 deletions
|
@ -28,7 +28,7 @@ use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::TryFutureExt;
|
||||||
use workspace::{ItemHandle as _, ItemNavHistory, Workspace};
|
use workspace::{ItemHandle as _, ItemNavHistory, Workspace};
|
||||||
|
|
||||||
actions!(diagnostics, [Deploy]);
|
actions!(diagnostics, [Deploy]);
|
||||||
|
@ -39,7 +39,6 @@ const CONTEXT_LINE_COUNT: u32 = 1;
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(ProjectDiagnosticsEditor::deploy);
|
cx.add_action(ProjectDiagnosticsEditor::deploy);
|
||||||
cx.add_action(ProjectDiagnosticsEditor::jump);
|
|
||||||
items::init(cx);
|
items::init(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,30 +194,6 @@ impl ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump(workspace: &mut Workspace, action: &Jump, cx: &mut ViewContext<Workspace>) {
|
|
||||||
let editor = workspace.open_path(action.path.clone(), true, cx);
|
|
||||||
let position = action.position;
|
|
||||||
let anchor = action.anchor;
|
|
||||||
cx.spawn_weak(|_, mut cx| async move {
|
|
||||||
let editor = editor.await.log_err()?.downcast::<Editor>()?;
|
|
||||||
editor.update(&mut cx, |editor, cx| {
|
|
||||||
let buffer = editor.buffer().read(cx).as_singleton()?;
|
|
||||||
let buffer = buffer.read(cx);
|
|
||||||
let cursor = if buffer.can_resolve(&anchor) {
|
|
||||||
anchor.to_point(buffer)
|
|
||||||
} else {
|
|
||||||
buffer.clip_point(position, Bias::Left)
|
|
||||||
};
|
|
||||||
editor.change_selections(Some(Autoscroll::Newest), cx, |s| {
|
|
||||||
s.select_ranges([cursor..cursor]);
|
|
||||||
});
|
|
||||||
Some(())
|
|
||||||
})?;
|
|
||||||
Some(())
|
|
||||||
})
|
|
||||||
.detach()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_excerpts(&mut self, language_server_id: Option<usize>, cx: &mut ViewContext<Self>) {
|
fn update_excerpts(&mut self, language_server_id: Option<usize>, cx: &mut ViewContext<Self>) {
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
self.paths_to_update.retain(|path, server_id| {
|
self.paths_to_update.retain(|path, server_id| {
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub use multi_buffer::{
|
||||||
ToPoint,
|
ToPoint,
|
||||||
};
|
};
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use project::{HoverBlock, Project, ProjectTransaction};
|
use project::{HoverBlock, Project, ProjectPath, ProjectTransaction};
|
||||||
use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection};
|
use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
@ -86,6 +86,13 @@ pub struct HoverAt {
|
||||||
point: Option<DisplayPoint>,
|
point: Option<DisplayPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct Jump {
|
||||||
|
path: ProjectPath,
|
||||||
|
position: Point,
|
||||||
|
anchor: language::Anchor,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
pub struct Input(pub String);
|
pub struct Input(pub String);
|
||||||
|
|
||||||
|
@ -216,7 +223,7 @@ impl_actions!(
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
impl_internal_actions!(editor, [Scroll, Select, HoverAt]);
|
impl_internal_actions!(editor, [Scroll, Select, HoverAt, Jump]);
|
||||||
|
|
||||||
enum DocumentHighlightRead {}
|
enum DocumentHighlightRead {}
|
||||||
enum DocumentHighlightWrite {}
|
enum DocumentHighlightWrite {}
|
||||||
|
@ -306,6 +313,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(Editor::hover);
|
cx.add_action(Editor::hover);
|
||||||
cx.add_action(Editor::hover_at);
|
cx.add_action(Editor::hover_at);
|
||||||
cx.add_action(Editor::open_excerpts);
|
cx.add_action(Editor::open_excerpts);
|
||||||
|
cx.add_action(Editor::jump);
|
||||||
cx.add_action(Editor::restart_language_server);
|
cx.add_action(Editor::restart_language_server);
|
||||||
cx.add_async_action(Editor::confirm_completion);
|
cx.add_async_action(Editor::confirm_completion);
|
||||||
cx.add_async_action(Editor::confirm_code_action);
|
cx.add_async_action(Editor::confirm_code_action);
|
||||||
|
@ -5826,6 +5834,30 @@ impl Editor {
|
||||||
nav_history.borrow_mut().enable();
|
nav_history.borrow_mut().enable();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn jump(workspace: &mut Workspace, action: &Jump, cx: &mut ViewContext<Workspace>) {
|
||||||
|
let editor = workspace.open_path(action.path.clone(), true, cx);
|
||||||
|
let position = action.position;
|
||||||
|
let anchor = action.anchor;
|
||||||
|
cx.spawn_weak(|_, mut cx| async move {
|
||||||
|
let editor = editor.await.log_err()?.downcast::<Editor>()?;
|
||||||
|
editor.update(&mut cx, |editor, cx| {
|
||||||
|
let buffer = editor.buffer().read(cx).as_singleton()?;
|
||||||
|
let buffer = buffer.read(cx);
|
||||||
|
let cursor = if buffer.can_resolve(&anchor) {
|
||||||
|
language::ToPoint::to_point(&anchor, buffer)
|
||||||
|
} else {
|
||||||
|
buffer.clip_point(position, Bias::Left)
|
||||||
|
};
|
||||||
|
editor.change_selections(Some(Autoscroll::Newest), cx, |s| {
|
||||||
|
s.select_ranges([cursor..cursor]);
|
||||||
|
});
|
||||||
|
Some(())
|
||||||
|
})?;
|
||||||
|
Some(())
|
||||||
|
})
|
||||||
|
.detach()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EditorSnapshot {
|
impl EditorSnapshot {
|
||||||
|
@ -9647,9 +9679,10 @@ mod tests {
|
||||||
[aaaa
|
[aaaa
|
||||||
(bbbb]
|
(bbbb]
|
||||||
cccc)"});
|
cccc)"});
|
||||||
let excerpt_ranges = excerpt_ranges
|
let excerpt_ranges = excerpt_ranges.into_iter().map(|context| ExcerptRange {
|
||||||
.into_iter()
|
context,
|
||||||
.map(|context| ExcerptRange { context, primary: None });
|
primary: None,
|
||||||
|
});
|
||||||
let buffer = cx.add_model(|cx| Buffer::new(0, initial_text, cx));
|
let buffer = cx.add_model(|cx| Buffer::new(0, initial_text, cx));
|
||||||
let multibuffer = cx.add_model(|cx| {
|
let multibuffer = cx.add_model(|cx| {
|
||||||
let mut multibuffer = MultiBuffer::new(0);
|
let mut multibuffer = MultiBuffer::new(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue