git: Make inline blame padding configurable (#33631)

Just like with diagnostics, adding a configurable padding to inline
blame

Release Notes:

- Added configurable padding to inline blame

---------

Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Peter Tripp <petertripp@gmail.com>
This commit is contained in:
Abdelhakim Qbaich 2025-08-07 21:35:07 -04:00 committed by GitHub
parent 35cd1b9ae1
commit cdfb3348ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 60 additions and 19 deletions

View file

@ -1171,6 +1171,9 @@
// Sets a delay after which the inline blame information is shown. // Sets a delay after which the inline blame information is shown.
// Delay is restarted with every cursor movement. // Delay is restarted with every cursor movement.
"delay_ms": 0, "delay_ms": 0,
// The amount of padding between the end of the source line and the start
// of the inline blame in units of em widths.
"padding": 7,
// Whether or not to display the git commit summary on the same line. // Whether or not to display the git commit summary on the same line.
"show_commit_summary": false, "show_commit_summary": false,
// The minimum column number to show the inline blame information at // The minimum column number to show the inline blame information at

View file

@ -3101,9 +3101,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA
// Turn inline-blame-off by default so no state is transferred without us explicitly doing so // Turn inline-blame-off by default so no state is transferred without us explicitly doing so
let inline_blame_off_settings = Some(InlineBlameSettings { let inline_blame_off_settings = Some(InlineBlameSettings {
enabled: false, enabled: false,
delay_ms: None, ..Default::default()
min_column: None,
show_commit_summary: false,
}); });
cx_a.update(|cx| { cx_a.update(|cx| {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {

View file

@ -86,8 +86,6 @@ use util::post_inc;
use util::{RangeExt, ResultExt, debug_panic}; use util::{RangeExt, ResultExt, debug_panic};
use workspace::{CollaboratorId, Workspace, item::Item, notifications::NotifyTaskExt}; use workspace::{CollaboratorId, Workspace, item::Item, notifications::NotifyTaskExt};
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 7.;
/// Determines what kinds of highlights should be applied to a lines background. /// Determines what kinds of highlights should be applied to a lines background.
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
struct LineHighlightSpec { struct LineHighlightSpec {
@ -2428,10 +2426,13 @@ impl EditorElement {
let editor = self.editor.read(cx); let editor = self.editor.read(cx);
let blame = editor.blame.clone()?; let blame = editor.blame.clone()?;
let padding = { let padding = {
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;
const INLINE_ACCEPT_SUGGESTION_EM_WIDTHS: f32 = 14.; const INLINE_ACCEPT_SUGGESTION_EM_WIDTHS: f32 = 14.;
let mut padding = INLINE_BLAME_PADDING_EM_WIDTHS; let mut padding = ProjectSettings::get_global(cx)
.git
.inline_blame
.unwrap_or_default()
.padding as f32;
if let Some(edit_prediction) = editor.active_edit_prediction.as_ref() { if let Some(edit_prediction) = editor.active_edit_prediction.as_ref() {
match &edit_prediction.completion { match &edit_prediction.completion {
@ -2469,7 +2470,7 @@ impl EditorElement {
let min_column_in_pixels = ProjectSettings::get_global(cx) let min_column_in_pixels = ProjectSettings::get_global(cx)
.git .git
.inline_blame .inline_blame
.and_then(|settings| settings.min_column) .map(|settings| settings.min_column)
.map(|col| self.column_pixels(col as usize, window)) .map(|col| self.column_pixels(col as usize, window))
.unwrap_or(px(0.)); .unwrap_or(px(0.));
let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels; let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels;
@ -8365,7 +8366,13 @@ impl Element for EditorElement {
}) })
.flatten()?; .flatten()?;
let mut element = render_inline_blame_entry(blame_entry, &style, cx)?; let mut element = render_inline_blame_entry(blame_entry, &style, cx)?;
let inline_blame_padding = INLINE_BLAME_PADDING_EM_WIDTHS * em_advance; let inline_blame_padding = ProjectSettings::get_global(cx)
.git
.inline_blame
.unwrap_or_default()
.padding
as f32
* em_advance;
Some( Some(
element element
.layout_as_root(AvailableSpace::min_size(), window, cx) .layout_as_root(AvailableSpace::min_size(), window, cx)

View file

@ -431,10 +431,9 @@ impl GitSettings {
pub fn inline_blame_delay(&self) -> Option<Duration> { pub fn inline_blame_delay(&self) -> Option<Duration> {
match self.inline_blame { match self.inline_blame {
Some(InlineBlameSettings { Some(InlineBlameSettings { delay_ms, .. }) if delay_ms > 0 => {
delay_ms: Some(delay_ms), Some(Duration::from_millis(delay_ms))
.. }
}) if delay_ms > 0 => Some(Duration::from_millis(delay_ms)),
_ => None, _ => None,
} }
} }
@ -470,7 +469,7 @@ pub enum GitGutterSetting {
Hide, Hide,
} }
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub struct InlineBlameSettings { pub struct InlineBlameSettings {
/// Whether or not to show git blame data inline in /// Whether or not to show git blame data inline in
@ -483,11 +482,19 @@ pub struct InlineBlameSettings {
/// after a delay once the cursor stops moving. /// after a delay once the cursor stops moving.
/// ///
/// Default: 0 /// Default: 0
pub delay_ms: Option<u64>, #[serde(default)]
pub delay_ms: u64,
/// The amount of padding between the end of the source line and the start
/// of the inline blame in units of columns.
///
/// Default: 7
#[serde(default = "default_inline_blame_padding")]
pub padding: u32,
/// The minimum column number to show the inline blame information at /// The minimum column number to show the inline blame information at
/// ///
/// Default: 0 /// Default: 0
pub min_column: Option<u32>, #[serde(default)]
pub min_column: u32,
/// Whether to show commit summary as part of the inline blame. /// Whether to show commit summary as part of the inline blame.
/// ///
/// Default: false /// Default: false
@ -495,6 +502,22 @@ pub struct InlineBlameSettings {
pub show_commit_summary: bool, pub show_commit_summary: bool,
} }
fn default_inline_blame_padding() -> u32 {
7
}
impl Default for InlineBlameSettings {
fn default() -> Self {
Self {
enabled: true,
delay_ms: 0,
padding: default_inline_blame_padding(),
min_column: 0,
show_commit_summary: false,
}
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
pub struct BinarySettings { pub struct BinarySettings {
pub path: Option<String>, pub path: Option<String>,

View file

@ -1795,7 +1795,6 @@ Example:
{ {
"git": { "git": {
"inline_blame": { "inline_blame": {
"enabled": true,
"delay_ms": 500 "delay_ms": 500
} }
} }
@ -1808,7 +1807,6 @@ Example:
{ {
"git": { "git": {
"inline_blame": { "inline_blame": {
"enabled": true,
"show_commit_summary": true "show_commit_summary": true
} }
} }
@ -1821,13 +1819,24 @@ Example:
{ {
"git": { "git": {
"inline_blame": { "inline_blame": {
"enabled": true,
"min_column": 80 "min_column": 80
} }
} }
} }
``` ```
5. Set the padding between the end of the line and the inline blame hint, in ems:
```json
{
"git": {
"inline_blame": {
"padding": 10
}
}
}
```
### Hunk Style ### Hunk Style
- Description: What styling we should use for the diff hunks. - Description: What styling we should use for the diff hunks.

View file

@ -223,6 +223,7 @@ TBD: Centered layout related settings
"enabled": true, // Show/hide inline blame "enabled": true, // Show/hide inline blame
"delay": 0, // Show after delay (ms) "delay": 0, // Show after delay (ms)
"min_column": 0, // Minimum column to inline display blame "min_column": 0, // Minimum column to inline display blame
"padding": 7, // Padding between code and inline blame (em)
"show_commit_summary": false // Show/hide commit summary "show_commit_summary": false // Show/hide commit summary
}, },
"hunk_style": "staged_hollow" // staged_hollow, unstaged_hollow "hunk_style": "staged_hollow" // staged_hollow, unstaged_hollow