Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit e72563e

Browse files
committed
Markdown format hover message
1 parent f435cf1 commit e72563e

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/extension.ts

+34-29
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,45 @@ import * as vscode from "vscode";
22
import * as cp from "child_process";
33

44
function parseGitBlamePorcelain(blame: string): { [key: string]: string } {
5+
const lines = blame.trim().split("\n");
6+
lines[0] = `commit ${lines[0]}`;
7+
lines[lines.length - 1] = `line ${lines[lines.length - 1]}`;
58
const fields = Object.fromEntries(
6-
blame
7-
.trim()
8-
.split("\n")
9-
.map((line: string) => {
10-
const words = line.split(" ");
11-
const key = words[0];
12-
const value = words.slice(1).join(" ");
13-
return [key, value];
14-
})
9+
lines.map((line: string) => {
10+
const words = line.split(" ");
11+
const key = words[0];
12+
const value = words.slice(1).join(" ");
13+
return [key, value];
14+
})
1515
);
1616
return fields;
1717
}
1818

1919
function relativeTimePassed(now: number, past: number): string {
20-
var msMinutes = 60 * 1000;
21-
var msHours = msMinutes * 60;
22-
var msDays = msHours * 24;
23-
var msMonths = msDays * 30;
24-
var msYears = msDays * 365;
25-
26-
var diff = now - past;
27-
28-
if (diff < msMinutes) {
29-
return Math.round(diff / 1000) + " seconds ago";
30-
} else if (diff < msHours) {
31-
return Math.round(diff / msMinutes) + " minutes ago";
32-
} else if (diff < msDays) {
33-
return Math.round(diff / msHours) + " hours ago";
34-
} else if (diff < msMonths) {
35-
return "Around " + Math.round(diff / msDays) + " days ago";
36-
} else if (diff < msYears) {
37-
return "Around " + Math.round(diff / msMonths) + " months ago";
20+
const msMinutes = 60 * 1000;
21+
const msHours = msMinutes * 60;
22+
const msDays = msHours * 24;
23+
const msMonths = msDays * 30;
24+
const msYears = msDays * 365;
25+
26+
const elapsed = now - past;
27+
28+
if (elapsed < msMinutes) {
29+
Math.round(elapsed / 1000);
30+
return Math.round(elapsed / 1000) + " seconds ago";
31+
} else if (elapsed < msHours) {
32+
return Math.round(elapsed / msMinutes) + " minutes ago";
33+
} else if (elapsed < msDays) {
34+
return Math.round(elapsed / msHours) + " hours ago";
35+
} else if (elapsed < msMonths) {
36+
return "Around " + Math.round(elapsed / msDays) + " day(s) ago";
37+
} else if (elapsed < msYears) {
38+
return "Around " + Math.round(elapsed / msMonths) + " month(s) ago";
3839
} else {
39-
return "Around " + Math.round(diff / msYears) + " years ago";
40+
return "Around " + Math.round(elapsed / msYears) + " year(s) ago";
4041
}
4142
}
43+
("Around 3 day(s) ago");
4244

4345
const annotationDecoration: vscode.TextEditorDecorationType =
4446
vscode.window.createTextEditorDecorationType({
@@ -94,7 +96,10 @@ export function activate(context: vscode.ExtensionContext) {
9496
// TODO If dirty, set summary to "Uncommitted changes".
9597
// TODO If close in time, set summary to "now".
9698
const message = `${fields.author}, ${elapsed}${fields.summary}`;
97-
const hoverMessage = JSON.stringify(fields, null, 2);
99+
100+
const hoverMessage = Object.entries(fields)
101+
.map((entry) => `- **${entry[0]}**: \`${entry[1]}\``)
102+
.join("\n");
98103

99104
const renderOptions = {
100105
after: {

0 commit comments

Comments
 (0)