From 9bdf9ac941303e4b7e02303d26712ebe618abf6c Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 18 Mar 2025 19:53:22 +0000 Subject: [PATCH] chore: clean up chore: remove unused import _ --- helix-term/src/commands/typed.rs | 34 ------------------- helix-term/src/handlers/blame.rs | 11 +----- helix-term/src/ui/text_decorations/blame.rs | 4 +-- .../src/ui/text_decorations/diagnostics.rs | 31 ++--------------- helix-vcs/src/git.rs | 2 +- helix-vcs/src/lib.rs | 7 ++-- 6 files changed, 8 insertions(+), 81 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 0d5e1a98..9661689c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -70,29 +70,6 @@ impl CommandCompleter { } } -fn blame(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyhow::Result<()> { - if event != PromptEvent::Validate { - return Ok(()); - } - - let (view, doc) = current_ref!(cx.editor); - let text = doc.text(); - let selection = doc.selection(view.id); - let cursor_line = text.char_to_line(selection.primary().cursor(doc.text().slice(..))); - let result = cx - .editor - .diff_providers - .blame_line(doc.path().context("Not in a file")?, cursor_line.try_into()?) - .inspect_err(|err| { - log::error!("Could not get blame: {err}"); - }) - .context("No blame information")?; - - cx.editor.set_status(result.to_string()); - - Ok(()) -} - fn quit(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyhow::Result<()> { log::debug!("quitting..."); @@ -3578,17 +3555,6 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ ..Signature::DEFAULT }, }, - TypableCommand { - name: "blame-line-range", - aliases: &["blame"], - doc: "Blames a range of lines. No args: Blame selection. 1 arg: Blame line. 2 args: Represents (from, to) line range to git blame.", - fun: blame, - completer: CommandCompleter::none(), - signature: Signature { - positionals: (0, Some(2)), - ..Signature::DEFAULT - }, - }, ]; pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> = diff --git a/helix-term/src/handlers/blame.rs b/helix-term/src/handlers/blame.rs index 720556d4..6600ab9e 100644 --- a/helix-term/src/handlers/blame.rs +++ b/helix-term/src/handlers/blame.rs @@ -1,4 +1,3 @@ -use helix_core::text_annotations::InlineAnnotation; use helix_event::{register_hook, send_blocking}; use helix_view::{ handlers::{BlameEvent, Handlers}, @@ -57,18 +56,10 @@ fn request_git_blame(editor: &mut Editor) { return; }; - // gix-blame expects a 1-based line + // 0-based into 1-based line number let Ok(output) = editor.diff_providers.blame_line(file, cursor_line + 1) else { return; }; doc.blame = Some(output.to_string()); - // doc.blame = Some(vec![InlineAnnotation::new( - // text.try_line_to_char(cursor_lin + 1) - // .unwrap_or(text.len_chars()) - // // to get the last position in the current line - // - 1, - // output.to_string(), - // )]); - // log::error!("{:?}", doc.blame); } diff --git a/helix-term/src/ui/text_decorations/blame.rs b/helix-term/src/ui/text_decorations/blame.rs index 766074da..ddb9976a 100644 --- a/helix-term/src/ui/text_decorations/blame.rs +++ b/helix-term/src/ui/text_decorations/blame.rs @@ -41,8 +41,8 @@ impl Decoration for EolBlame<'_> { let style = self.style; let width = renderer.viewport.width; let start_col = col - renderer.offset.col as u16; - // start drawing the git blame 1 space after the end of the line - let draw_col = col + 1; + // start drawing the git blame 6 spaces after the end of the line + let draw_col = col + 6; let end_col = renderer .column_in_bounds(draw_col as usize, 1) diff --git a/helix-term/src/ui/text_decorations/diagnostics.rs b/helix-term/src/ui/text_decorations/diagnostics.rs index df7ea439..fb82bcf5 100644 --- a/helix-term/src/ui/text_decorations/diagnostics.rs +++ b/helix-term/src/ui/text_decorations/diagnostics.rs @@ -271,41 +271,14 @@ impl Decoration for InlineDiagnostics<'_> { DiagnosticFilter::Disable => None, }; if let Some((eol_diagnostic, _)) = eol_diagnostic { - let renderer = Renderer { + let mut renderer = Renderer { renderer, first_row: pos.visual_line, row: pos.visual_line, config: &self.state.config, styles: &self.styles, }; - // let ref mut this = renderer; - let row = pos.visual_line; - let col = virt_off.col; - let style = renderer.styles.severity_style(eol_diagnostic.severity()); - let width = renderer.renderer.viewport.width; - let start_col = (col - renderer.renderer.offset.col) as u16; - let mut end_col = start_col; - let mut draw_col = (col + 1) as u16; - - for line in eol_diagnostic.message.lines() { - if !renderer.renderer.column_in_bounds(draw_col as usize, 1) { - break; - } - - (end_col, _) = renderer.renderer.set_string_truncated( - renderer.renderer.viewport.x + draw_col, - row, - line, - width.saturating_sub(draw_col) as usize, - |_| style, - true, - false, - ); - - draw_col = end_col - renderer.renderer.viewport.x + 2; // double space between lines - } - - col_off = end_col - start_col; + col_off = renderer.draw_eol_diagnostic(eol_diagnostic, pos.visual_line, virt_off.col); } self.state.compute_line_diagnostics(); diff --git a/helix-vcs/src/git.rs b/helix-vcs/src/git.rs index 5847f810..b72bd0ae 100644 --- a/helix-vcs/src/git.rs +++ b/helix-vcs/src/git.rs @@ -137,7 +137,7 @@ impl fmt::Display for BlameInformation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "{} • {} • {} • {}", + "{}, {} • {} • {}", self.author_name, self.commit_date, self.commit_message, self.commit_hash ) } diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs index 551d81f9..8f89c1a1 100644 --- a/helix-vcs/src/lib.rs +++ b/helix-vcs/src/lib.rs @@ -49,11 +49,8 @@ impl DiffProviderRegistry { }) } - pub fn blame_line( - &self, - file: &Path, - line: u32, - ) -> anyhow::Result<BlameInformation> { + /// Blame line in a file. Lines are 1-indexed + pub fn blame_line(&self, file: &Path, line: u32) -> anyhow::Result<BlameInformation> { self.providers .iter() .map(|provider| provider.blame_line(file, line))