on master help sign in
Simplify goto_*_diagnostic commands
0f4cd73Blaž Hrastnik
helix-term/src/commands.rs+26−30
@@ -3348,26 +3348,24 @@ fn goto_first_diag(cx: &mut Context) {
3348 let editor = &mut cx.editor;
3348 let editor = &mut cx.editor;
3349 let (_, doc) = current!(editor);
3349 let (_, doc) = current!(editor);
3350
3350
3351− let diag = if let Some(diag) = doc.diagnostics().first() {
3351+ let pos = match doc.diagnostics().first() {
3352− diag.range.start
3352+ Some(diag) => diag.range.start,
3353− } else {
3354− return;
3353+ None => return,
3355 };
3354 };
3356
3355
3357− goto_pos(editor, diag);
3356+ goto_pos(editor, pos);
3358}
3357}
3359
3358
3360fn goto_last_diag(cx: &mut Context) {
3359fn goto_last_diag(cx: &mut Context) {
3361 let editor = &mut cx.editor;
3360 let editor = &mut cx.editor;
3362 let (_, doc) = current!(editor);
3361 let (_, doc) = current!(editor);
3363
3362
3364− let diag = if let Some(diag) = doc.diagnostics().last() {
3363+ let pos = match doc.diagnostics().last() {
3365− diag.range.start
3364+ Some(diag) => diag.range.start,
3366− } else {
3367− return;
3365+ None => return,
3368 };
3366 };
3369
3367
3370− goto_pos(editor, diag);
3368+ goto_pos(editor, pos);
3371}
3369}
3372
3370
3373fn goto_next_diag(cx: &mut Context) {
3371fn goto_next_diag(cx: &mut Context) {
@@ -3378,20 +3376,19 @@ fn goto_next_diag(cx: &mut Context) {
3378 .selection(view.id)
3376 .selection(view.id)
3379 .primary()
3377 .primary()
3380 .cursor(doc.text().slice(..));
3378 .cursor(doc.text().slice(..));
3379+
3381− let diag = if let Some(diag) = doc
3380+ let diag = doc
3382 .diagnostics()
3381 .diagnostics()
3383 .iter()
3382 .iter()
3384− .map(|diag| diag.range.start)
3385− .find(|&pos| pos > cursor_pos)
3383+ .find(|diag| diag.range.start > cursor_pos)
3386− {
3387− diag
3388− } else if let Some(diag) = doc.diagnostics().first() {
3384+ .or_else(|| doc.diagnostics().first());
3385+
3386+ let pos = match diag {
3389− diag.range.start
3387+ Some(diag) => diag.range.start,
3390− } else {
3391− return;
3388+ None => return,
3392 };
3389 };
3393
3390
3394− goto_pos(editor, diag);
3391+ goto_pos(editor, pos);
3395}
3392}
3396
3393
3397fn goto_prev_diag(cx: &mut Context) {
3394fn goto_prev_diag(cx: &mut Context) {
@@ -3402,21 +3399,20 @@ fn goto_prev_diag(cx: &mut Context) {
3402 .selection(view.id)
3399 .selection(view.id)
3403 .primary()
3400 .primary()
3404 .cursor(doc.text().slice(..));
3401 .cursor(doc.text().slice(..));
3402+
3405− let diag = if let Some(diag) = doc
3403+ let diag = doc
3406 .diagnostics()
3404 .diagnostics()
3407 .iter()
3405 .iter()
3408 .rev()
3406 .rev()
3409− .map(|diag| diag.range.start)
3410− .find(|&pos| pos < cursor_pos)
3407+ .find(|diag| diag.range.start < cursor_pos)
3411− {
3412− diag
3413− } else if let Some(diag) = doc.diagnostics().last() {
3408+ .or_else(|| doc.diagnostics().last());
3409+
3410+ let pos = match diag {
3414− diag.range.start
3411+ Some(diag) => diag.range.start,
3415− } else {
3416− return;
3412+ None => return,
3417 };
3413 };
3418
3414
3419− goto_pos(editor, diag);
3415+ goto_pos(editor, pos);
3420}
3416}
3421
3417
3422fn signature_help(cx: &mut Context) {
3418fn signature_help(cx: &mut Context) {