refactor: rename to blame_line

This commit is contained in:
Nik Revenco 2025-03-18 03:03:48 +00:00
parent e2e3ce4ea0
commit fed006456a
3 changed files with 9 additions and 13 deletions

View file

@ -77,15 +77,11 @@ fn blame(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyho
let (view, doc) = current_ref!(cx.editor); let (view, doc) = current_ref!(cx.editor);
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
let (from, to) = selection let cursor_line = selection.primary().cursor(doc.text().slice(..));
.line_ranges(doc.text().slice(..))
.next()
.map(|(from, to)| (from as u32, to as u32))
.context("No selections")?;
let result = cx let result = cx
.editor .editor
.diff_providers .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| { .inspect_err(|err| {
log::error!("Could not get blame: {err}"); log::error!("Could not get blame: {err}");
}) })

View file

@ -144,7 +144,7 @@ impl fmt::Display for BlameInformation {
} }
/// Emulates the result of running `git blame` from the command line. /// 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_dir = get_repo_dir(file)?;
let repo = open_repo(repo_dir) let repo = open_repo(repo_dir)
.context("failed to open git repo")? .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, traverse_all_commits,
&mut resource_cache, &mut resource_cache,
BStr::new(relative_path), BStr::new(relative_path),
Some(range), Some(line..line.saturating_add(0)),
)? )?
.entries .entries
.first() .first()

View file

@ -49,14 +49,14 @@ impl DiffProviderRegistry {
}) })
} }
pub fn blame( pub fn blame_line(
&self, &self,
file: &Path, file: &Path,
range: std::ops::Range<u32>, line: u32,
) -> anyhow::Result<BlameInformation> { ) -> anyhow::Result<BlameInformation> {
self.providers self.providers
.iter() .iter()
.map(|provider| provider.blame(file, range.clone())) .map(|provider| provider.blame_line(file, line))
.next() .next()
.context("No provider found")? .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 { match self {
#[cfg(feature = "git")] #[cfg(feature = "git")]
Self::Git => git::blame(file, range), Self::Git => git::blame_line(file, line),
Self::None => bail!("No blame support compiled in"), Self::None => bail!("No blame support compiled in"),
} }
} }