@@ -17,6 +17,8 @@ import {
1717 GitBlameCommit ,
1818 GitCommit ,
1919 GitDiffHunkLine ,
20+ GitLogCommit ,
21+ GitService ,
2022 GitUri
2123} from '../git/gitService' ;
2224import { Objects , Strings } from '../system' ;
@@ -62,74 +64,121 @@ export class Annotations {
6264 commit : GitBlameCommit ,
6365 uri : GitUri ,
6466 editorLine : number
67+ ) : Promise < MarkdownString | undefined > ;
68+ static async changesHoverMessage (
69+ commit : GitLogCommit ,
70+ uri : GitUri ,
71+ editorLine : number ,
72+ hunkLine : GitDiffHunkLine
73+ ) : Promise < MarkdownString | undefined > ;
74+ static async changesHoverMessage (
75+ commit : GitBlameCommit | GitLogCommit ,
76+ uri : GitUri ,
77+ editorLine : number ,
78+ hunkLine ?: GitDiffHunkLine
6579 ) : Promise < MarkdownString | undefined > {
66- let ref ;
67- if ( commit . isUncommitted ) {
68- if ( uri . isUncommittedStaged ) {
69- ref = uri . sha ;
80+ const documentRef = uri . sha ;
81+ if ( commit instanceof GitBlameCommit ) {
82+ // TODO: Figure out how to optimize this
83+ let ref ;
84+ if ( commit . isUncommitted ) {
85+ if ( GitService . isUncommittedStaged ( documentRef ) ) {
86+ ref = documentRef ;
87+ }
88+ }
89+ else {
90+ ref = commit . sha ;
7091 }
71- }
72- else {
73- ref = commit . sha ;
74- }
7592
76- const line = editorLine + 1 ;
77- const commitLine = commit . lines . find ( l => l . line === line ) || commit . lines [ 0 ] ;
93+ const line = editorLine + 1 ;
94+ const commitLine = commit . lines . find ( l => l . line === line ) || commit . lines [ 0 ] ;
7895
79- let originalFileName = commit . originalFileName ;
80- if ( originalFileName === undefined ) {
81- if ( uri . fsPath !== commit . uri . fsPath ) {
82- originalFileName = commit . fileName ;
96+ let originalFileName = commit . originalFileName ;
97+ if ( originalFileName === undefined ) {
98+ if ( uri . fsPath !== commit . uri . fsPath ) {
99+ originalFileName = commit . fileName ;
100+ }
83101 }
84- }
85102
86- const commitEditorLine = commitLine . originalLine - 1 ;
87- const hunkLine = await Container . git . getDiffForLine ( uri , commitEditorLine , ref , undefined , originalFileName ) ;
88- return this . changesHoverDiffMessage ( commit , uri , hunkLine , commitEditorLine ) ;
89- }
103+ editorLine = commitLine . originalLine - 1 ;
104+ hunkLine = await Container . git . getDiffForLine ( uri , editorLine , ref , undefined , originalFileName ) ;
105+
106+ // If we didn't find a diff & ref is undefined (meaning uncommitted), check for a staged diff
107+ if ( hunkLine === undefined && ref === undefined ) {
108+ hunkLine = await Container . git . getDiffForLine (
109+ uri ,
110+ editorLine ,
111+ undefined ,
112+ GitService . uncommittedStagedSha ,
113+ originalFileName
114+ ) ;
115+ }
116+ }
90117
91- static changesHoverDiffMessage (
92- commit : GitCommit ,
93- uri : GitUri ,
94- hunkLine : GitDiffHunkLine | undefined ,
95- editorLine ?: number
96- ) : MarkdownString | undefined {
97118 if ( hunkLine === undefined || commit . previousSha === undefined ) return undefined ;
98119
99120 const diff = this . getDiffFromHunkLine ( hunkLine ) ;
100121
101- let message : string ;
122+ let message ;
123+ let previous ;
124+ let current ;
102125 if ( commit . isUncommitted ) {
103- if ( uri . isUncommittedStaged ) {
104- message = `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs (
105- commit ,
106- editorLine
107- ) } "Open Changes") ${ GlyphChars . Dash } [\`${
108- commit . previousShortSha
109- } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
110- commit . previousSha !
111- ) } "Show Commit Details") ${ GlyphChars . ArrowLeftRightLong } _${ uri . shortSha } _\n${ diff } `;
112- }
113- else {
114- message = `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs (
115- commit ,
116- editorLine
117- ) } "Open Changes") ${ GlyphChars . Dash } _uncommitted changes_\n${ diff } `;
126+ const diffUris = await commit . getPreviousLineDiffUris ( uri , editorLine , documentRef ) ;
127+ if ( diffUris === undefined || diffUris . previous === undefined ) {
128+ return undefined ;
118129 }
130+
131+ message = `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( {
132+ lhs : {
133+ sha : diffUris . previous . sha || '' ,
134+ uri : diffUris . previous . documentUri ( )
135+ } ,
136+ rhs : {
137+ sha : diffUris . current . sha || '' ,
138+ uri : diffUris . current . documentUri ( )
139+ } ,
140+ repoPath : commit . repoPath ,
141+ line : editorLine
142+ } ) } "Open Changes")`;
143+
144+ previous =
145+ diffUris . previous . sha === undefined || diffUris . previous . isUncommitted
146+ ? `_${ GitService . shortenSha ( diffUris . previous . sha , {
147+ working : 'Working Tree'
148+ } ) } _`
149+ : `[\`${ GitService . shortenSha (
150+ diffUris . previous . sha || ''
151+ ) } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
152+ diffUris . previous . sha || ''
153+ ) } "Show Commit Details")`;
154+
155+ current =
156+ diffUris . current . sha === undefined || diffUris . current . isUncommitted
157+ ? `_${ GitService . shortenSha ( diffUris . current . sha , {
158+ working : 'Working Tree'
159+ } ) } _`
160+ : `[\`${ GitService . shortenSha (
161+ diffUris . current . sha || ''
162+ ) } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
163+ diffUris . current . sha || ''
164+ ) } "Show Commit Details")`;
119165 }
120166 else {
121- message = `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs (
122- commit ,
123- editorLine
124- ) } "Open Changes") ${ GlyphChars . Dash } [\`${
125- commit . previousShortSha
126- } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs ( commit . previousSha ! ) } "Show Commit Details") ${
127- GlyphChars . ArrowLeftRightLong
128- } [\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
167+ message = `[\`Changes\`](${ DiffWithCommand . getMarkdownCommandArgs ( commit , editorLine ) } "Open Changes")` ;
168+
169+ previous = `[\`${ commit . previousShortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
170+ commit . previousSha !
171+ ) } "Show Commit Details")`;
172+
173+ current = `[\`${ commit . shortSha } \`](${ ShowQuickCommitDetailsCommand . getMarkdownCommandArgs (
129174 commit . sha
130- ) } "Show Commit Details")\n ${ diff } `;
175+ ) } "Show Commit Details")`;
131176 }
132177
178+ message += ` ${ GlyphChars . Dash } ${ previous } ${
179+ GlyphChars . ArrowLeftRightLong
180+ } ${ current } \n${ diff } `;
181+
133182 const markdown = new MarkdownString ( message ) ;
134183 markdown . isTrusted = true ;
135184 return markdown ;
@@ -140,14 +189,15 @@ export class Annotations {
140189 uri : GitUri ,
141190 editorLine : number ,
142191 dateFormat : string | null ,
143- annotationType ? : FileAnnotationType
192+ annotationType : FileAnnotationType | undefined
144193 ) : Promise < MarkdownString > {
145194 if ( dateFormat === null ) {
146195 dateFormat = 'MMMM Do, YYYY h:mma' ;
147196 }
148197
149- const [ presence , remotes ] = await Promise . all ( [
198+ const [ presence , previousLineDiffUris , remotes ] = await Promise . all ( [
150199 Container . vsls . getContactPresence ( commit . email ) ,
200+ commit . isUncommitted ? commit . getPreviousLineDiffUris ( uri , editorLine , uri . sha ) : undefined ,
151201 Container . git . getRemotes ( commit . repoPath )
152202 ] ) ;
153203
@@ -158,6 +208,7 @@ export class Annotations {
158208 line : editorLine ,
159209 markdown : true ,
160210 presence : presence ,
211+ previousLineDiffUris : previousLineDiffUris ,
161212 remotes : remotes
162213 } )
163214 ) ;
@@ -274,13 +325,22 @@ export class Annotations {
274325
275326 static trailing (
276327 commit : GitCommit ,
328+ // uri: GitUri,
329+ // editorLine: number,
277330 format : string ,
278331 dateFormat : string | null ,
279332 scrollable : boolean = true
280333 ) : Partial < DecorationOptions > {
334+ // TODO: Enable this once there is better caching
335+ // let diffUris;
336+ // if (commit.isUncommitted) {
337+ // diffUris = await commit.getPreviousLineDiffUris(uri, editorLine, uri.sha);
338+ // }
339+
281340 const message = CommitFormatter . fromTemplate ( format , commit , {
282- truncateMessageAtNewLine : true ,
283- dateFormat : dateFormat
341+ dateFormat : dateFormat ,
342+ // previousLineDiffUris: diffUris,
343+ truncateMessageAtNewLine : true
284344 } ) ;
285345
286346 return {
0 commit comments