Skip to content

Commit

Permalink
improve success message
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Feb 18, 2024
1 parent 6685897 commit f586557
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5524,16 +5524,25 @@ fn yank_diagnostic(cx: &mut Context) {
let (view, doc) = current_ref!(cx.editor);
let primary = doc.selection(view.id).primary();

let diag = doc
let diag: Vec<_> = doc
.diagnostics()
.iter()
.filter(|d| primary.overlaps(&helix_core::Range::new(d.range.start, d.range.end)))
.map(|d| d.message.clone());
.map(|d| d.message.clone())
.collect();
let n = diag.len();
if n == 0 {
cx.editor
.set_error("No diagnostics under primary selection");
return;
}

let reg = cx.register.unwrap_or('+');
match cx.editor.registers.write(reg, diag.collect()) {
Ok(_) => cx
.editor
.set_status(format!("Yanked diagnostic(s) to register {reg}")),
match cx.editor.registers.write(reg, diag) {
Ok(_) => cx.editor.set_status(format!(
"Yanked {n} diagnostic{} to register {reg}",
if n == 1 { "" } else { "s" }
)),
Err(err) => cx.editor.set_error(err.to_string()),
}
}
Expand Down

0 comments on commit f586557

Please sign in to comment.