@@ -2,43 +2,45 @@ import * as vscode from "vscode";
2
2
import * as cp from "child_process" ;
3
3
4
4
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 ] } ` ;
5
8
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
+ } )
15
15
) ;
16
16
return fields ;
17
17
}
18
18
19
19
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" ;
38
39
} else {
39
- return "Around " + Math . round ( diff / msYears ) + " years ago" ;
40
+ return "Around " + Math . round ( elapsed / msYears ) + " year(s) ago" ;
40
41
}
41
42
}
43
+ ( "Around 3 day(s) ago" ) ;
42
44
43
45
const annotationDecoration : vscode . TextEditorDecorationType =
44
46
vscode . window . createTextEditorDecorationType ( {
@@ -94,7 +96,10 @@ export function activate(context: vscode.ExtensionContext) {
94
96
// TODO If dirty, set summary to "Uncommitted changes".
95
97
// TODO If close in time, set summary to "now".
96
98
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" ) ;
98
103
99
104
const renderOptions = {
100
105
after : {
0 commit comments