Inline git blame (#10398)
This adds so-called "inline git blame" to the editor that, when turned on, shows `git blame` information about the current line inline:  When the inline information is hovered, a new tooltip appears that contains more information on the current commit:  The commit message in this tooltip is rendered as Markdown, is scrollable and clickable. The tooltip is now also the tooltip used in the gutter:  ## Settings 1. The inline git blame information can be turned on and off via settings: ```json { "git": { "inline_blame": { "enabled": true } } } ``` 2. Optionally, a delay can be configured. When a delay is set, the inline blame information will only show up `x milliseconds` after a cursor movement: ```json { "git": { "inline_blame": { "enabled": true, "delay_ms": 600 } } } ``` 3. It can also be turned on/off for the current buffer with `editor: toggle git blame inline`. ## To be done in follow-up PRs - [ ] Add link to pull request in tooltip - [ ] Add avatars of users if possible ## Release notes Release Notes: - Added inline `git blame` information the editor. It can be turned on in the settings with `{"git": { "inline_blame": "on" } }` for every buffer or, temporarily for the current buffer, with `editor: toggle git blame inline`.
This commit is contained in:
parent
573ba83034
commit
faebce8cd0
13 changed files with 655 additions and 237 deletions
|
@ -9,6 +9,8 @@ pub enum TimestampFormat {
|
|||
/// If the message is from today or yesterday the date will be replaced with "Today at x" or "Yesterday at x" respectively.
|
||||
/// E.g. "Today at 12:00 PM", "Yesterday at 11:00 AM", "2021-12-31 3:00AM".
|
||||
EnhancedAbsolute,
|
||||
/// Formats the timestamp as an absolute time, using month name, day of month, year. e.g. "Feb. 24, 2024".
|
||||
MediumAbsolute,
|
||||
/// Formats the timestamp as a relative time, e.g. "just now", "1 minute ago", "2 hours ago", "2 months ago".
|
||||
Relative,
|
||||
}
|
||||
|
@ -30,6 +32,9 @@ pub fn format_localized_timestamp(
|
|||
TimestampFormat::EnhancedAbsolute => {
|
||||
format_absolute_timestamp(timestamp_local, reference_local, true)
|
||||
}
|
||||
TimestampFormat::MediumAbsolute => {
|
||||
format_absolute_timestamp_medium(timestamp_local, reference_local)
|
||||
}
|
||||
TimestampFormat::Relative => format_relative_time(timestamp_local, reference_local)
|
||||
.unwrap_or_else(|| format_relative_date(timestamp_local, reference_local)),
|
||||
}
|
||||
|
@ -72,6 +77,22 @@ fn format_absolute_timestamp(
|
|||
}
|
||||
}
|
||||
|
||||
fn format_absolute_timestamp_medium(
|
||||
timestamp: OffsetDateTime,
|
||||
#[allow(unused_variables)] reference: OffsetDateTime,
|
||||
) -> String {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
macos::format_date_medium(×tamp)
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
// todo(linux) respect user's date/time preferences
|
||||
// todo(windows) respect user's date/time preferences
|
||||
format_timestamp_fallback(timestamp, reference)
|
||||
}
|
||||
}
|
||||
|
||||
fn format_relative_time(timestamp: OffsetDateTime, reference: OffsetDateTime) -> Option<String> {
|
||||
let difference = reference - timestamp;
|
||||
let minutes = difference.whole_minutes();
|
||||
|
@ -253,7 +274,8 @@ mod macos {
|
|||
use core_foundation_sys::{
|
||||
base::kCFAllocatorDefault,
|
||||
date_formatter::{
|
||||
kCFDateFormatterNoStyle, kCFDateFormatterShortStyle, CFDateFormatterCreate,
|
||||
kCFDateFormatterMediumStyle, kCFDateFormatterNoStyle, kCFDateFormatterShortStyle,
|
||||
CFDateFormatterCreate,
|
||||
},
|
||||
locale::CFLocaleCopyCurrent,
|
||||
};
|
||||
|
@ -266,6 +288,10 @@ mod macos {
|
|||
format_with_date_formatter(timestamp, DATE_FORMATTER.with(|f| *f))
|
||||
}
|
||||
|
||||
pub fn format_date_medium(timestamp: &time::OffsetDateTime) -> String {
|
||||
format_with_date_formatter(timestamp, MEDIUM_DATE_FORMATTER.with(|f| *f))
|
||||
}
|
||||
|
||||
fn format_with_date_formatter(
|
||||
timestamp: &time::OffsetDateTime,
|
||||
fmt: CFDateFormatterRef,
|
||||
|
@ -302,6 +328,15 @@ mod macos {
|
|||
kCFDateFormatterNoStyle,
|
||||
)
|
||||
};
|
||||
|
||||
static MEDIUM_DATE_FORMATTER: CFDateFormatterRef = unsafe {
|
||||
CFDateFormatterCreate(
|
||||
kCFAllocatorDefault,
|
||||
CURRENT_LOCALE.with(|locale| *locale),
|
||||
kCFDateFormatterMediumStyle,
|
||||
kCFDateFormatterNoStyle,
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue