Skip to content

Commit 4d4aec2

Browse files
add new project_settings key to InlineBlameSettings called author_display. It defines how to display the author in git blame displays.
add new enum `GitAuthorDisplaySetting` with values `Author` (default), `You`, `AuthorYou` Author -> Simply the default behaviour, e.g. `Linus Torvalds` You -> Shows `You` inplace of author name on your machine. e.g. `You` AuthorYou -> Both e.g. `Linus Torvalds (You)` currently there is one issue. updating the setting doesn't reflect rendered blames. need to toggle inline blames to take effect.
1 parent 3d3a5ce commit 4d4aec2

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

crates/git/src/repository.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait GitRepository: Send + Sync {
4444
fn create_branch(&self, _: &str) -> Result<()>;
4545
fn branch_exits(&self, _: &str) -> Result<bool>;
4646

47-
fn blame(&self, path: &Path, content: Rope) -> Result<crate::blame::Blame>;
47+
fn blame(&self, path: &Path, content: Rope, author_display_replace: Option<&str>) -> Result<crate::blame::Blame>;
4848

4949
fn path(&self) -> PathBuf;
5050
}
@@ -204,7 +204,7 @@ impl GitRepository for RealGitRepository {
204204
Ok(())
205205
}
206206

207-
fn blame(&self, path: &Path, content: Rope) -> Result<crate::blame::Blame> {
207+
fn blame(&self, path: &Path, content: Rope, author_display_replace: Option<&str>) -> Result<crate::blame::Blame> {
208208
let working_directory = self
209209
.repository
210210
.lock()
@@ -222,6 +222,7 @@ impl GitRepository for RealGitRepository {
222222
&content,
223223
remote_url,
224224
self.hosting_provider_registry.clone(),
225+
author_display_replace,
225226
)
226227
}
227228
}
@@ -349,7 +350,7 @@ impl GitRepository for FakeGitRepository {
349350
Ok(())
350351
}
351352

352-
fn blame(&self, path: &Path, _content: Rope) -> Result<crate::blame::Blame> {
353+
fn blame(&self, path: &Path, _content: Rope, _author_replace_display: Option<&str>) -> Result<crate::blame::Blame> {
353354
let state = self.state.lock();
354355
state
355356
.blames

crates/project/src/buffer_store.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
22
search::SearchQuery,
3+
ProjectSettings, project_settings::GitAuthorDisplaySetting,
34
worktree_store::{WorktreeStore, WorktreeStoreEvent},
45
Item, ProjectPath,
56
};
@@ -23,6 +24,7 @@ use language::{
2324
Buffer, BufferEvent, Capability, DiskState, File as _, Language, Operation,
2425
};
2526
use rpc::{proto, AnyProtoClient, ErrorExt as _, TypedEnvelope};
27+
use settings::Settings;
2628
use smol::channel::Receiver;
2729
use std::{io, ops::Range, path::Path, str::FromStr as _, sync::Arc, time::Instant};
2830
use text::BufferId;
@@ -1124,11 +1126,25 @@ impl BufferStore {
11241126
anyhow::Ok(Some((repo, relative_path, content)))
11251127
});
11261128

1129+
let author_display_setting = ProjectSettings::get_global(cx)
1130+
.git
1131+
.inline_blame
1132+
.unwrap_or_default()
1133+
.author_display
1134+
.unwrap_or_default();
1135+
11271136
cx.background_executor().spawn(async move {
11281137
let Some((repo, relative_path, content)) = blame_params? else {
11291138
return Ok(None);
11301139
};
1131-
repo.blame(&relative_path, content)
1140+
1141+
let author_display_replace = match author_display_setting {
1142+
GitAuthorDisplaySetting::Author => None,
1143+
GitAuthorDisplaySetting::You => Some("You"),
1144+
GitAuthorDisplaySetting::AuthorYou => Some("{} (You)"),
1145+
};
1146+
1147+
repo.blame(&relative_path, content, author_display_replace)
11321148
.with_context(|| format!("Failed to blame {:?}", relative_path.0))
11331149
.map(Some)
11341150
})

crates/project/src/project_settings.rs

+16
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ pub struct InlineBlameSettings {
156156
/// Default: false
157157
#[serde(default = "false_value")]
158158
pub show_commit_summary: bool,
159+
/// Author display format for git blame.
160+
///
161+
/// Default: author
162+
pub author_display: Option<GitAuthorDisplaySetting>,
163+
}
164+
165+
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
166+
#[serde(rename_all = "snake_case")]
167+
pub enum GitAuthorDisplaySetting {
168+
/// Only Author name.
169+
#[default]
170+
Author,
171+
/// You
172+
You,
173+
/// Author (You)
174+
AuthorYou,
159175
}
160176

161177
const fn true_value() -> bool {

0 commit comments

Comments
 (0)