@@ -17,13 +17,11 @@ import {
1717 GitBlameCommit ,
1818 GitCommit ,
1919 GitDiffHunkLine ,
20- GitRemote ,
2120 GitService ,
2221 GitUri
2322} from '../git/gitService' ;
2423import { Objects , Strings } from '../system' ;
2524import { toRgba } from '../webviews/apps/shared/colors' ;
26- import { ContactPresence } from '../vsls/vsls' ;
2725
2826export interface ComputedHeatmap {
2927 cold : boolean ;
@@ -61,55 +59,37 @@ export class Annotations {
6159 decoration . renderOptions ! . before ! . borderColor = color ;
6260 }
6361
64- private static getHeatmapColor ( date : Date , heatmap : ComputedHeatmap ) {
65- const baseColor = heatmap . cold ? heatmap . colors . cold : heatmap . colors . hot ;
66-
67- const age = heatmap . computeAge ( date ) ;
68- if ( age === 0 ) return baseColor ;
69-
70- if ( computedHeatmapColor === undefined || computedHeatmapColor . color !== baseColor ) {
71- let rgba = toRgba ( baseColor ) ;
72- if ( rgba == null ) {
73- rgba = toRgba ( heatmap . cold ? defaultHeatmapColdColor : defaultHeatmapHotColor ) ! ;
62+ static async changesHoverMessage (
63+ commit : GitBlameCommit ,
64+ uri : GitUri ,
65+ editorLine : number
66+ ) : Promise < MarkdownString | undefined > {
67+ let ref ;
68+ if ( commit . isUncommitted ) {
69+ if ( uri . sha !== undefined && GitService . isUncommittedStaged ( uri . sha ) ) {
70+ ref = uri . sha ;
7471 }
75-
76- const [ r , g , b ] = rgba ;
77- computedHeatmapColor = {
78- color : baseColor ,
79- rgb : `${ r } , ${ g } , ${ b } `
80- } ;
72+ }
73+ else {
74+ ref = commit . sha ;
8175 }
8276
83- return `rgba( ${ computedHeatmapColor . rgb } , ${ ( 1 - age / 10 ) . toFixed ( 2 ) } )` ;
84- }
77+ const line = editorLine + 1 ;
78+ const commitLine = commit . lines . find ( l => l . line === line ) || commit . lines [ 0 ] ;
8579
86- static getHoverMessage (
87- commit : GitCommit ,
88- dateFormat : string | null ,
89- presence : ContactPresence | undefined ,
90- remotes : GitRemote [ ] ,
91- annotationType ?: FileAnnotationType ,
92- line : number = 0
93- ) : MarkdownString {
94- if ( dateFormat === null ) {
95- dateFormat = 'MMMM Do, YYYY h:mma' ;
80+ let originalFileName = commit . originalFileName ;
81+ if ( originalFileName === undefined ) {
82+ if ( uri . fsPath !== commit . uri . fsPath ) {
83+ originalFileName = commit . fileName ;
84+ }
9685 }
9786
98- const markdown = new MarkdownString (
99- CommitFormatter . fromTemplate ( Container . config . hovers . detailsMarkdownFormat , commit , {
100- annotationType : annotationType ,
101- dateFormat : dateFormat ,
102- line : line ,
103- markdown : true ,
104- presence : presence ,
105- remotes : remotes
106- } )
107- ) ;
108- markdown . isTrusted = true ;
109- return markdown ;
87+ const commitEditorLine = commitLine . originalLine - 1 ;
88+ const hunkLine = await Container . git . getDiffForLine ( uri , commitEditorLine , ref , undefined , originalFileName ) ;
89+ return this . changesHoverDiffMessage ( commit , uri , hunkLine , commitEditorLine ) ;
11090 }
11191
112- static getHoverDiffMessage (
92+ static changesHoverDiffMessage (
11393 commit : GitCommit ,
11494 uri : GitUri ,
11595 hunkLine : GitDiffHunkLine | undefined ,
@@ -156,57 +136,36 @@ export class Annotations {
156136 return markdown ;
157137 }
158138
159- private static getDiffFromHunkLine ( hunkLine : GitDiffHunkLine ) : string {
160- if ( Container . config . hovers . changesDiff === 'hunk' ) {
161- return `\`\`\`diff\n${ hunkLine . hunk . diff } \n\`\`\`` ;
162- }
163-
164- return `\`\`\`diff${ hunkLine . previous === undefined ? '' : `\n-${ hunkLine . previous . line } ` } ${
165- hunkLine . current === undefined ? '' : `\n+${ hunkLine . current . line } `
166- } \n\`\`\``;
167- }
168-
169- static async changesHover (
170- commit : GitBlameCommit ,
139+ static async detailsHoverMessage (
140+ commit : GitCommit ,
141+ uri : GitUri ,
171142 editorLine : number ,
172- uri : GitUri
173- ) : Promise < Partial < DecorationOptions > > {
174- let ref ;
175- if ( commit . isUncommitted ) {
176- if ( uri . sha !== undefined && GitService . isUncommittedStaged ( uri . sha ) ) {
177- ref = uri . sha ;
178- }
179- }
180- else {
181- ref = commit . sha ;
182- }
183-
184- const line = editorLine + 1 ;
185- const commitLine = commit . lines . find ( l => l . line === line ) || commit . lines [ 0 ] ;
186-
187- let originalFileName = commit . originalFileName ;
188- if ( originalFileName === undefined ) {
189- if ( uri . fsPath !== commit . uri . fsPath ) {
190- originalFileName = commit . fileName ;
191- }
143+ dateFormat : string | null ,
144+ annotationType ?: FileAnnotationType
145+ ) : Promise < MarkdownString > {
146+ if ( dateFormat === null ) {
147+ dateFormat = 'MMMM Do, YYYY h:mma' ;
192148 }
193149
194- const commitEditorLine = commitLine . originalLine - 1 ;
195- const hunkLine = await Container . git . getDiffForLine ( uri , commitEditorLine , ref , undefined , originalFileName ) ;
196- const message = this . getHoverDiffMessage ( commit , uri , hunkLine , commitEditorLine ) ;
150+ const [ presence , remotes ] = await Promise . all ( [
151+ Container . vsls . getContactPresence ( commit . email ) ,
152+ Container . git . getRemotes ( commit . repoPath )
153+ ] ) ;
197154
198- return {
199- hoverMessage : message
200- } ;
155+ const markdown = new MarkdownString (
156+ CommitFormatter . fromTemplate ( Container . config . hovers . detailsMarkdownFormat , commit , {
157+ annotationType : annotationType ,
158+ dateFormat : dateFormat ,
159+ line : editorLine ,
160+ markdown : true ,
161+ presence : presence ,
162+ remotes : remotes
163+ } )
164+ ) ;
165+ markdown . isTrusted = true ;
166+ return markdown ;
201167 }
202168
203- // static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType, line: number = 0): DecorationOptions {
204- // const message = this.getHoverMessage(commit, dateFormat, hasRemote, annotationType);
205- // return {
206- // hoverMessage: message
207- // } as DecorationOptions;
208- // }
209-
210169 static gutter (
211170 commit : GitCommit ,
212171 format : string ,
@@ -314,29 +273,6 @@ export class Annotations {
314273 } ;
315274 }
316275
317- // static hover(commit: GitCommit, renderOptions: IRenderOptions, now: number): DecorationOptions {
318- // const decoration = {
319- // renderOptions: { before: { ...renderOptions } }
320- // } as DecorationOptions;
321-
322- // this.applyHeatmap(decoration, commit.date, now);
323-
324- // return decoration;
325- // }
326-
327- // static hoverRenderOptions(heatmap: HeatmapConfig): IRenderOptions {
328- // if (!heatmap.enabled) return { before: undefined };
329-
330- // return {
331- // borderStyle: 'solid',
332- // borderWidth: '0 0 0 2px',
333- // contentText: GlyphChars.ZeroWidthSpace,
334- // height: '100%',
335- // margin: '0 26px 0 0',
336- // textDecoration: 'none'
337- // } as IRenderOptions;
338- // }
339-
340276 static trailing (
341277 commit : GitCommit ,
342278 format : string ,
@@ -363,20 +299,35 @@ export class Annotations {
363299 } ;
364300 }
365301
366- // static withRange(decoration: DecorationOptions, start?: number, end?: number): DecorationOptions {
367- // let range = decoration.range;
368- // if (start !== undefined) {
369- // range = range.with({
370- // start: range.start.with({ character: start })
371- // });
372- // }
373-
374- // if (end !== undefined) {
375- // range = range.with({
376- // end: range.end.with({ character: end })
377- // });
378- // }
379-
380- // return { ...decoration, range: range };
381- // }
302+ private static getDiffFromHunkLine ( hunkLine : GitDiffHunkLine ) : string {
303+ if ( Container . config . hovers . changesDiff === 'hunk' ) {
304+ return `\`\`\`diff\n${ hunkLine . hunk . diff } \n\`\`\`` ;
305+ }
306+
307+ return `\`\`\`diff${ hunkLine . previous === undefined ? '' : `\n-${ hunkLine . previous . line } ` } ${
308+ hunkLine . current === undefined ? '' : `\n+${ hunkLine . current . line } `
309+ } \n\`\`\``;
310+ }
311+
312+ private static getHeatmapColor ( date : Date , heatmap : ComputedHeatmap ) {
313+ const baseColor = heatmap . cold ? heatmap . colors . cold : heatmap . colors . hot ;
314+
315+ const age = heatmap . computeAge ( date ) ;
316+ if ( age === 0 ) return baseColor ;
317+
318+ if ( computedHeatmapColor === undefined || computedHeatmapColor . color !== baseColor ) {
319+ let rgba = toRgba ( baseColor ) ;
320+ if ( rgba == null ) {
321+ rgba = toRgba ( heatmap . cold ? defaultHeatmapColdColor : defaultHeatmapHotColor ) ! ;
322+ }
323+
324+ const [ r , g , b ] = rgba ;
325+ computedHeatmapColor = {
326+ color : baseColor ,
327+ rgb : `${ r } , ${ g } , ${ b } `
328+ } ;
329+ }
330+
331+ return `rgba(${ computedHeatmapColor . rgb } , ${ ( 1 - age / 10 ) . toFixed ( 2 ) } )` ;
332+ }
382333}
0 commit comments