Skip to content

Commit ddf8ac1

Browse files
committed
feat: implement inline git blame
1 parent 711aa58 commit ddf8ac1

File tree

7 files changed

+23
-54
lines changed

7 files changed

+23
-54
lines changed

helix-term/src/handlers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
3737
auto_save::register_hooks(&handlers);
3838
diagnostics::register_hooks(&handlers);
3939
snippet::register_hooks(&handlers);
40-
// blame::register_hooks(&handlers);
40+
blame::register_hooks(&handlers);
4141
handlers
4242
}

helix-term/src/handlers/blame.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ fn request_git_blame(editor: &mut Editor) {
6262
return;
6363
};
6464

65-
doc.blame = Some(vec![InlineAnnotation::new(
66-
text.try_line_to_char(cursor_lin + 1)
67-
.unwrap_or(text.len_chars())
68-
// to get the last position in the current line
69-
- 1,
70-
output.to_string(),
71-
)]);
72-
log::error!("{:?}", doc.blame);
65+
doc.blame = Some(output.to_string());
66+
// doc.blame = Some(vec![InlineAnnotation::new(
67+
// text.try_line_to_char(cursor_lin + 1)
68+
// .unwrap_or(text.len_chars())
69+
// // to get the last position in the current line
70+
// - 1,
71+
// output.to_string(),
72+
// )]);
73+
// log::error!("{:?}", doc.blame);
7374
}

helix-term/src/ui/editor.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,14 @@ impl EditorView {
202202
config.end_of_line_diagnostics,
203203
));
204204
if config.vcs.blame {
205-
decorations.add_decoration(text_decorations::blame::EolBlame::new(
206-
doc,
207-
theme,
208-
doc.text().char_to_line(primary_cursor),
209-
"hello world".to_string(),
210-
));
205+
if let Some(blame) = &doc.blame {
206+
decorations.add_decoration(text_decorations::blame::EolBlame::new(
207+
doc,
208+
theme,
209+
doc.text().char_to_line(primary_cursor),
210+
blame,
211+
));
212+
}
211213
}
212214
render_document(
213215
surface,
+3-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(dead_code, unused_variables, unused_mut)]
22

3-
use helix_core::doc_formatter::FormattedGrapheme;
43
use helix_core::Position;
54

65
use helix_view::theme::Style;
@@ -10,14 +9,14 @@ use crate::ui::document::{LinePos, TextRenderer};
109
use crate::ui::text_decorations::Decoration;
1110

1211
pub struct EolBlame<'a> {
13-
message: String,
12+
message: &'a str,
1413
doc: &'a Document,
1514
cursor: usize,
1615
style: Style,
1716
}
1817

1918
impl<'a> EolBlame<'a> {
20-
pub fn new(doc: &'a Document, theme: &Theme, cursor: usize, message: String) -> Self {
19+
pub fn new(doc: &'a Document, theme: &Theme, cursor: usize, message: &'a str) -> Self {
2120
EolBlame {
2221
style: theme.get("ui.virtual.blame"),
2322
message,
@@ -28,12 +27,6 @@ impl<'a> EolBlame<'a> {
2827
}
2928

3029
impl Decoration for EolBlame<'_> {
31-
// fn decorate_line(&mut self, renderer: &mut TextRenderer, pos: LinePos) {
32-
// // renderer.draw_dec
33-
// // ration_grapheme(grapheme, style, row, col)
34-
// let col_off = 50;
35-
// }
36-
3730
fn render_virt_lines(
3831
&mut self,
3932
renderer: &mut TextRenderer,
@@ -45,9 +38,6 @@ impl Decoration for EolBlame<'_> {
4538
}
4639
let row = pos.visual_line;
4740
let col = virt_off.col as u16;
48-
// if col != self.cursor as u16 {
49-
// return Position::new(0, 0);
50-
// }
5141
let style = self.style;
5242
let width = renderer.viewport.width;
5343
let start_col = col - renderer.offset.col as u16;
@@ -61,7 +51,7 @@ impl Decoration for EolBlame<'_> {
6151
.set_string_truncated(
6252
renderer.viewport.x + draw_col,
6353
row,
64-
&self.message,
54+
self.message,
6555
width.saturating_sub(draw_col) as usize,
6656
|_| self.style,
6757
true,
@@ -75,20 +65,4 @@ impl Decoration for EolBlame<'_> {
7565

7666
Position::new(0, col_off as usize)
7767
}
78-
79-
// fn reset_pos(&mut self, _pos: usize) -> usize {
80-
// usize::MAX
81-
// }
82-
83-
// fn skip_concealed_anchor(&mut self, conceal_end_char_idx: usize) -> usize {
84-
// self.reset_pos(conceal_end_char_idx)
85-
// }
86-
87-
// fn decorate_grapheme(
88-
// &mut self,
89-
// _renderer: &mut TextRenderer,
90-
// _grapheme: &FormattedGrapheme,
91-
// ) -> usize {
92-
// usize::MAX
93-
// }
9468
}

helix-vcs/src/git.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl fmt::Display for BlameInformation {
137137
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138138
write!(
139139
f,
140-
" {} - {} - {} - {}",
140+
"{} {} {} {}",
141141
self.author_name, self.commit_date, self.commit_message, self.commit_hash
142142
)
143143
}

helix-view/src/document.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub struct Document {
143143
///
144144
/// To know if they're up-to-date, check the `id` field in `DocumentInlayHints`.
145145
pub(crate) inlay_hints: HashMap<ViewId, DocumentInlayHints>,
146-
pub blame: Option<Vec<InlineAnnotation>>,
146+
pub blame: Option<String>,
147147
pub(crate) jump_labels: HashMap<ViewId, Vec<Overlay>>,
148148
/// Set to `true` when the document is updated, reset to `false` on the next inlay hints
149149
/// update from the LSP

helix-view/src/view.rs

-8
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,6 @@ impl View {
452452
text_annotations.add_overlay(labels, style);
453453
}
454454

455-
if let Some(blame_annotation) = &doc.blame {
456-
let annotation_style = theme
457-
.and_then(|t| t.find_scope_index("ui.virtual.inlay-hint.type"))
458-
.map(Highlight);
459-
460-
text_annotations.add_inline_annotations(blame_annotation, annotation_style);
461-
}
462-
463455
if let Some(DocumentInlayHints {
464456
id: _,
465457
type_inlay_hints,

0 commit comments

Comments
 (0)