Simplify goto_*_diagnostic commands

pull/993/head
Blaž Hrastnik 3 years ago
parent f659e1178a
commit 0f4cd73000

@ -3348,26 +3348,24 @@ fn goto_first_diag(cx: &mut Context) {
let editor = &mut cx.editor; let editor = &mut cx.editor;
let (_, doc) = current!(editor); let (_, doc) = current!(editor);
let diag = if let Some(diag) = doc.diagnostics().first() { let pos = match doc.diagnostics().first() {
diag.range.start Some(diag) => diag.range.start,
} else { None => return,
return;
}; };
goto_pos(editor, diag); goto_pos(editor, pos);
} }
fn goto_last_diag(cx: &mut Context) { fn goto_last_diag(cx: &mut Context) {
let editor = &mut cx.editor; let editor = &mut cx.editor;
let (_, doc) = current!(editor); let (_, doc) = current!(editor);
let diag = if let Some(diag) = doc.diagnostics().last() { let pos = match doc.diagnostics().last() {
diag.range.start Some(diag) => diag.range.start,
} else { None => return,
return;
}; };
goto_pos(editor, diag); goto_pos(editor, pos);
} }
fn goto_next_diag(cx: &mut Context) { fn goto_next_diag(cx: &mut Context) {
@ -3378,20 +3376,19 @@ fn goto_next_diag(cx: &mut Context) {
.selection(view.id) .selection(view.id)
.primary() .primary()
.cursor(doc.text().slice(..)); .cursor(doc.text().slice(..));
let diag = if let Some(diag) = doc
let diag = doc
.diagnostics() .diagnostics()
.iter() .iter()
.map(|diag| diag.range.start) .find(|diag| diag.range.start > cursor_pos)
.find(|&pos| pos > cursor_pos) .or_else(|| doc.diagnostics().first());
{
diag let pos = match diag {
} else if let Some(diag) = doc.diagnostics().first() { Some(diag) => diag.range.start,
diag.range.start None => return,
} else {
return;
}; };
goto_pos(editor, diag); goto_pos(editor, pos);
} }
fn goto_prev_diag(cx: &mut Context) { fn goto_prev_diag(cx: &mut Context) {
@ -3402,21 +3399,20 @@ fn goto_prev_diag(cx: &mut Context) {
.selection(view.id) .selection(view.id)
.primary() .primary()
.cursor(doc.text().slice(..)); .cursor(doc.text().slice(..));
let diag = if let Some(diag) = doc
let diag = doc
.diagnostics() .diagnostics()
.iter() .iter()
.rev() .rev()
.map(|diag| diag.range.start) .find(|diag| diag.range.start < cursor_pos)
.find(|&pos| pos < cursor_pos) .or_else(|| doc.diagnostics().last());
{
diag let pos = match diag {
} else if let Some(diag) = doc.diagnostics().last() { Some(diag) => diag.range.start,
diag.range.start None => return,
} else {
return;
}; };
goto_pos(editor, diag); goto_pos(editor, pos);
} }
fn signature_help(cx: &mut Context) { fn signature_help(cx: &mut Context) {

Loading…
Cancel
Save