diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d41dbbd5..6a668b76 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -77,15 +77,11 @@ fn blame(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyho let (view, doc) = current_ref!(cx.editor); let selection = doc.selection(view.id); - let (from, to) = selection - .line_ranges(doc.text().slice(..)) - .next() - .map(|(from, to)| (from as u32, to as u32)) - .context("No selections")?; + let cursor_line = selection.primary().cursor(doc.text().slice(..)); let result = cx .editor .diff_providers - .blame(doc.path().context("Not in a file")?, from..to) + .blame_line(doc.path().context("Not in a file")?, cursor_line.try_into()?) .inspect_err(|err| { log::error!("Could not get blame: {err}"); }) diff --git a/helix-vcs/src/git.rs b/helix-vcs/src/git.rs index 80021576..dcc30fbf 100644 --- a/helix-vcs/src/git.rs +++ b/helix-vcs/src/git.rs @@ -144,7 +144,7 @@ impl fmt::Display for BlameInformation { } /// Emulates the result of running `git blame` from the command line. -pub fn blame(file: &Path, range: std::ops::Range<u32>) -> Result<BlameInformation> { +pub fn blame_line(file: &Path, line: u32) -> Result<BlameInformation> { let repo_dir = get_repo_dir(file)?; let repo = open_repo(repo_dir) .context("failed to open git repo")? @@ -175,7 +175,7 @@ pub fn blame(file: &Path, range: std::ops::Range<u32>) -> Result<BlameInformatio traverse_all_commits, &mut resource_cache, BStr::new(relative_path), - Some(range), + Some(line..line.saturating_add(0)), )? .entries .first() diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs index abc7689f..551d81f9 100644 --- a/helix-vcs/src/lib.rs +++ b/helix-vcs/src/lib.rs @@ -49,14 +49,14 @@ impl DiffProviderRegistry { }) } - pub fn blame( + pub fn blame_line( &self, file: &Path, - range: std::ops::Range<u32>, + line: u32, ) -> anyhow::Result<BlameInformation> { self.providers .iter() - .map(|provider| provider.blame(file, range.clone())) + .map(|provider| provider.blame_line(file, line)) .next() .context("No provider found")? } @@ -121,10 +121,10 @@ impl DiffProvider { } } - fn blame(&self, file: &Path, range: std::ops::Range<u32>) -> Result<BlameInformation> { + fn blame_line(&self, file: &Path, line: u32) -> Result<BlameInformation> { match self { #[cfg(feature = "git")] - Self::Git => git::blame(file, range), + Self::Git => git::blame_line(file, line), Self::None => bail!("No blame support compiled in"), } }