on master help sign in
Simplify goto_*_diagnostic commands
commit0f4cd73000140cd9872f291ddb1473f96cbc7364 authorBlaž Hrastnik <blaz@mxxn.io> dateSat 6 Nov 2021, 18:04 (5 years ago) parentf659e11
1 file changed+26−30
helix-term/src/commands.rs+26−30
helix-term/src/commands.rs+26−30
@@ -3348,26 +3348,24 @@ fn goto_first_diag(cx: &mut Context) {
33483348 let editor = &mut cx.editor;
33493349 let (_, doc) = current!(editor);
33503350
3351− let diag = if let Some(diag) = doc.diagnostics().first() {
3352− diag.range.start
3353− } else {
3354− return;
3351+ let pos = match doc.diagnostics().first() {
3352+ Some(diag) => diag.range.start,
3353+ None => return,
33553354 };
33563355
3357− goto_pos(editor, diag);
3356+ goto_pos(editor, pos);
33583357}
33593358
33603359fn goto_last_diag(cx: &mut Context) {
33613360 let editor = &mut cx.editor;
33623361 let (_, doc) = current!(editor);
33633362
3364− let diag = if let Some(diag) = doc.diagnostics().last() {
3365− diag.range.start
3366− } else {
3367− return;
3363+ let pos = match doc.diagnostics().last() {
3364+ Some(diag) => diag.range.start,
3365+ None => return,
33683366 };
33693367
3370− goto_pos(editor, diag);
3368+ goto_pos(editor, pos);
33713369}
33723370
33733371fn goto_next_diag(cx: &mut Context) {
@@ -3378,20 +3376,19 @@ fn goto_next_diag(cx: &mut Context) {
33783376 .selection(view.id)
33793377 .primary()
33803378 .cursor(doc.text().slice(..));
3381− let diag = if let Some(diag) = doc
3379+
3380+ let diag = doc
33823381 .diagnostics()
33833382 .iter()
3384− .map(|diag| diag.range.start)
3385− .find(|&pos| pos > cursor_pos)
3386− {
3387− diag
3388− } else if let Some(diag) = doc.diagnostics().first() {
3389− diag.range.start
3390− } else {
3391− return;
3383+ .find(|diag| diag.range.start > cursor_pos)
3384+ .or_else(|| doc.diagnostics().first());
3385+
3386+ let pos = match diag {
3387+ Some(diag) => diag.range.start,
3388+ None => return,
33923389 };
33933390
3394− goto_pos(editor, diag);
3391+ goto_pos(editor, pos);
33953392}
33963393
33973394fn goto_prev_diag(cx: &mut Context) {
@@ -3402,21 +3399,20 @@ fn goto_prev_diag(cx: &mut Context) {
34023399 .selection(view.id)
34033400 .primary()
34043401 .cursor(doc.text().slice(..));
3405− let diag = if let Some(diag) = doc
3402+
3403+ let diag = doc
34063404 .diagnostics()
34073405 .iter()
34083406 .rev()
3409− .map(|diag| diag.range.start)
3410− .find(|&pos| pos < cursor_pos)
3411− {
3412− diag
3413− } else if let Some(diag) = doc.diagnostics().last() {
3414− diag.range.start
3415− } else {
3416− return;
3407+ .find(|diag| diag.range.start < cursor_pos)
3408+ .or_else(|| doc.diagnostics().last());
3409+
3410+ let pos = match diag {
3411+ Some(diag) => diag.range.start,
3412+ None => return,
34173413 };
34183414
3419− goto_pos(editor, diag);
3415+ goto_pos(editor, pos);
34203416}
34213417
34223418fn signature_help(cx: &mut Context) {