Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a yank diagnostic command #9640

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl MappableCommand {
yank_main_selection_to_clipboard, "Yank main selection to clipboard",
yank_joined_to_primary_clipboard, "Join and yank selections to primary clipboard",
yank_main_selection_to_primary_clipboard, "Yank main selection to primary clipboard",
yank_diagnostic, "Yank diagnostic(s) under primary cursor to register, or clipboard by default",
replace_with_yanked, "Replace with yanked text",
replace_selections_with_clipboard, "Replace selections by clipboard content",
replace_selections_with_primary_clipboard, "Replace selections by primary clipboard",
Expand Down Expand Up @@ -5519,6 +5520,33 @@ fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) {
}
}

fn yank_diagnostic(cx: &mut Context) {
let (view, doc) = current_ref!(cx.editor);
let primary = doc.selection(view.id).primary();

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())
.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) {
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()),
}
}

fn record_macro(cx: &mut Context) {
if let Some((reg, mut keys)) = cx.editor.macro_recording.take() {
// Remove the keypress which ends the recording
Expand Down
Loading