Skip to content

Commit 22f9571

Browse files
committed
feat: split inline-blame.behaviour into two options
_ _
1 parent b9f8226 commit 22f9571

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

book/src/editor.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,24 @@ The following statusline elements can be configured:
164164

165165
### `[editor.inline-blame]` Section
166166

167+
Inline blame is virtual text that appears at the end of a line, displaying information about the most recent commit that affected this line.
168+
167169
| Key | Description | Default |
168170
| ------- | ------------------------------------------ | ------- |
169-
| `behaviour` | Choose the behaviour of inline blame | `"disabled"` |
171+
| `behaviour` | Choose when to show inline blame | `"hidden"` |
172+
| `compute` | Choose when inline blame should be computed | `"on-demand"` |
170173
| `format` | The format in which to show the inline blame | `"{author}, {time-ago} • {message} • {commit}"` |
171174

172175
The `behaviour` can be one of the following:
173-
- `"all-lines"`: Inline blame is turned on. Virtual text will appear at the end of each non-empty line, showing information about the latest commit for that line.
174-
- `"cursor-line"`: Inline blame is turned on. Virtual text will appear at the end of the current cursor line, showing information about the latest commit for that line.
175-
- `"background"`: Inline blame is turned off, but the blame is still requested in the background when opening and reloading files. This will have zero impact on performance, but will use slightly more resources in the background. This allows blame for line (`space + B`) to be retrieved instantaneously with zero delay.
176-
- `"disabled"`: Inline blame is turned off, with no requests happening in the background. When you run `space + B` for the first time in a file, it will load the blame for this file. You may have to wait a little bit for the blame to become available, depending on the size of your repository. After it becomes available, for this file `space + B` will retrieve the blame for any line in this file with zero delay. If the file is reloaded, the process will repeat as the blame is potentially out of date and needs to be refreshed.
176+
- `"all-lines"`: Inline blame is on every line.
177+
- `"cursor-line"`: Inline blame is only on the line of the primary cursor.
178+
- `"hidden"`: Inline blame is not shown.
179+
180+
Inline blame will only show if the blame for the file has already been computed.
181+
182+
The `compute` key determines under which circumstances the blame is computed, and can be one of the following:
183+
- `"on-demand"`: Blame for the file is computed only when explicitly requested, such as when using `space + B` to blame the line of the cursor. There may be a little delay when loading the blame. When opening new files, even with `behaviour` not set to `"hidden"`, the inline blame won't show. It needs to be computed first in order to become available. This computation can be manually triggered by requesting it with `space + B`.
184+
- `"background"`: Blame for the file is loaded in the background. This will have zero effect on performance of the Editor, but will use a little bit extra resources. Directly requesting the blame with `space + B` will be instant. Inline blame will show as soon as the blame is available when loading new files.
177185

178186
`inline-blame-format` allows customization of the blame message, and can be set to any string. Variables can be used like so: `{variable}`. These are the available variables:
179187

helix-term/src/commands.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,8 +3480,9 @@ pub(crate) fn blame_line_impl(editor: &mut Editor, doc_id: DocumentId, cursor_li
34803480
let line_blame = match doc.line_blame(cursor_line, &inline_blame_config.format) {
34813481
result
34823482
if (result.is_ok() && doc.is_blame_potentially_out_of_date)
3483-
|| matches!(result, Err(LineBlameError::NotReadyYet) if inline_blame_config.behaviour
3484-
== helix_view::editor::InlineBlameBehaviour::Disabled) =>
3483+
|| matches!(result, Err(LineBlameError::NotReadyYet) if inline_blame_config.compute
3484+
== helix_view::editor::InlineBlameCompute::OnDemand
3485+
) =>
34853486
{
34863487
if let Some(path) = doc.path() {
34873488
let tx = editor.handlers.blame.clone();

helix-term/src/commands/typed.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ fn reload(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyh
13271327
}
13281328

13291329
let scrolloff = cx.editor.config().scrolloff;
1330-
let inline_blame_behaviour = cx.editor.config().inline_blame.behaviour;
1330+
let inline_compute = cx.editor.config().inline_blame.compute;
13311331
let (view, doc) = current!(cx.editor);
13321332
doc.reload(view, &cx.editor.diff_providers).map(|_| {
13331333
view.ensure_cursor_in_view(doc, scrolloff);
@@ -1340,7 +1340,7 @@ fn reload(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyh
13401340
.file_changed(path.clone());
13411341
}
13421342

1343-
if doc.should_request_full_file_blame(inline_blame_behaviour) {
1343+
if doc.should_request_full_file_blame(inline_compute) {
13441344
if let Some(path) = doc.path() {
13451345
helix_event::send_blocking(
13461346
&cx.editor.handlers.blame,
@@ -1380,7 +1380,7 @@ fn reload_all(cx: &mut compositor::Context, _args: Args, event: PromptEvent) ->
13801380
})
13811381
.collect();
13821382

1383-
let blame_behaviour = cx.editor.config().inline_blame.behaviour;
1383+
let blame_compute = cx.editor.config().inline_blame.compute;
13841384

13851385
for (doc_id, view_ids) in docs_view_ids {
13861386
let doc = doc_mut!(cx.editor, &doc_id);
@@ -1410,7 +1410,7 @@ fn reload_all(cx: &mut compositor::Context, _args: Args, event: PromptEvent) ->
14101410
}
14111411
}
14121412

1413-
if doc.should_request_full_file_blame(blame_behaviour) {
1413+
if doc.should_request_full_file_blame(blame_compute) {
14141414
if let Some(path) = doc.path() {
14151415
helix_event::send_blocking(
14161416
&cx.editor.handlers.blame,

helix-term/src/handlers/blame.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{mem, time::Duration};
33
use helix_event::register_hook;
44
use helix_vcs::FileBlame;
55
use helix_view::{
6-
editor::InlineBlameBehaviour,
6+
editor::InlineBlameCompute,
77
events::{DocumentDidOpen, EditorConfigDidChange},
88
handlers::{BlameEvent, Handlers},
99
DocumentId,
@@ -44,7 +44,7 @@ impl helix_event::AsyncHook for BlameHandler {
4444
return;
4545
};
4646
doc.file_blame = Some(result);
47-
if editor.config().inline_blame.behaviour == InlineBlameBehaviour::Disabled {
47+
if editor.config().inline_blame.compute == InlineBlameCompute::OnDemand {
4848
if let Some(line) = line_blame {
4949
crate::commands::blame_line_impl(editor, doc_id, line);
5050
} else {
@@ -61,7 +61,7 @@ impl helix_event::AsyncHook for BlameHandler {
6161
pub(super) fn register_hooks(handlers: &Handlers) {
6262
let tx = handlers.blame.clone();
6363
register_hook!(move |event: &mut DocumentDidOpen<'_>| {
64-
if event.editor.config().inline_blame.behaviour != InlineBlameBehaviour::Disabled {
64+
if event.editor.config().inline_blame.compute != InlineBlameCompute::OnDemand {
6565
helix_event::send_blocking(
6666
&tx,
6767
BlameEvent {
@@ -75,9 +75,9 @@ pub(super) fn register_hooks(handlers: &Handlers) {
7575
});
7676
let tx = handlers.blame.clone();
7777
register_hook!(move |event: &mut EditorConfigDidChange<'_>| {
78-
let has_enabled_inline_blame = event.old_config.inline_blame.behaviour
79-
== InlineBlameBehaviour::Disabled
80-
&& event.editor.config().inline_blame.behaviour != InlineBlameBehaviour::Disabled;
78+
let has_enabled_inline_blame = event.old_config.inline_blame.compute
79+
== InlineBlameCompute::OnDemand
80+
&& event.editor.config().inline_blame.compute == InlineBlameCompute::Background;
8181

8282
if has_enabled_inline_blame {
8383
// request blame for all documents, since any of them could have

helix-view/src/document.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use helix_core::{
4242
ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
4343
};
4444

45-
use crate::editor::InlineBlameBehaviour;
45+
use crate::editor::InlineBlameCompute;
4646
use crate::{
4747
editor::Config,
4848
events::{DocumentDidChange, SelectionDidChange},
@@ -741,11 +741,8 @@ impl Document {
741741
}
742742
}
743743

744-
pub fn should_request_full_file_blame(
745-
&mut self,
746-
blame_behaviour: InlineBlameBehaviour,
747-
) -> bool {
748-
if blame_behaviour == InlineBlameBehaviour::Disabled {
744+
pub fn should_request_full_file_blame(&mut self, blame_fetch: InlineBlameCompute) -> bool {
745+
if blame_fetch == InlineBlameCompute::OnDemand {
749746
self.is_blame_potentially_out_of_date
750747
} else {
751748
true

helix-view/src/editor.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,39 +175,42 @@ impl Default for GutterLineNumbersConfig {
175175
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
176176
#[serde(rename_all = "kebab-case")]
177177
pub enum InlineBlameBehaviour {
178-
/// Do not show inline blame
179-
///
180-
/// Loads blame for the file in the background when the document is
181-
/// opened and request it again when it is `:reload`ed.
182-
///
183-
/// This allows instantaneous access to line blame with `space + B` and when
184-
/// `:toggle inline-blame.enable` but for the cost of consuming more
185-
/// resources in the background
186-
Background,
187178
/// Do not show inline blame, and do not request it in the background
188179
///
189180
/// When manually requesting the inline blame, it may take several seconds to appear.
190-
Disabled,
181+
Hidden,
191182
/// Show the inline blame on the cursor line
192183
CursorLine,
193184
/// Show the inline blame on every other line
194185
AllLines,
195186
}
196187

188+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
189+
#[serde(rename_all = "kebab-case")]
190+
pub enum InlineBlameCompute {
191+
/// Inline blame for a file will be fetched when a document is opened or reloaded, for example
192+
Background,
193+
/// Inline blame for a file will be fetched when explicitly requested, e.g. when using `space + B`
194+
OnDemand,
195+
}
196+
197197
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
198198
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
199199
pub struct InlineBlameConfig {
200-
/// Show inline blame for a line when cursor is on that line
200+
/// How to show the inline blame
201201
pub behaviour: InlineBlameBehaviour,
202+
/// Whether the inline blame should be fetched in the background
203+
pub compute: InlineBlameCompute,
202204
/// How the inline blame should look like and the information it includes
203205
pub format: String,
204206
}
205207

206208
impl Default for InlineBlameConfig {
207209
fn default() -> Self {
208210
Self {
209-
behaviour: InlineBlameBehaviour::Disabled,
211+
behaviour: InlineBlameBehaviour::Hidden,
210212
format: "{author}, {time-ago} • {message} • {commit}".to_owned(),
213+
compute: InlineBlameCompute::OnDemand,
211214
}
212215
}
213216
}

0 commit comments

Comments
 (0)