33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { CancellationToken , ConfigurationChangeEvent , Disposable , env , Event , EventEmitter , MarkdownString , ThemeIcon , Timeline , TimelineChangeEvent , TimelineItem , TimelineOptions , TimelineProvider , Uri , workspace , l10n , Command } from 'vscode' ;
6+ import { CancellationToken , ConfigurationChangeEvent , Disposable , Event , EventEmitter , ThemeIcon , Timeline , TimelineChangeEvent , TimelineItem , TimelineOptions , TimelineProvider , Uri , workspace , l10n , Command } from 'vscode' ;
77import { Model } from './model' ;
88import { Repository , Resource } from './repository' ;
99import { debounce } from './decorators' ;
1010import { emojify , ensureEmojis } from './emoji' ;
1111import { CommandCenter } from './commands' ;
1212import { OperationKind , OperationResult } from './operation' ;
1313import { truncate } from './util' ;
14- import { CommitShortStat } from './git' ;
1514import { provideSourceControlHistoryItemAvatar , provideSourceControlHistoryItemHoverCommands , provideSourceControlHistoryItemMessageLinks } from './historyItemDetailsProvider' ;
1615import { AvatarQuery , AvatarQueryCommit } from './api/git' ;
17-
18- const AVATAR_SIZE = 20 ;
16+ import { getHistoryItemHover , getHistoryItemHoverCommitHashCommands , processHistoryItemRemoteHoverCommands } from './historyProvider' ;
1917
2018export class GitTimelineItem extends TimelineItem {
2119 static is ( item : TimelineItem ) : item is GitTimelineItem {
@@ -54,61 +52,6 @@ export class GitTimelineItem extends TimelineItem {
5452 return this . shortenRef ( this . previousRef ) ;
5553 }
5654
57- setItemDetails ( uri : Uri , hash : string | undefined , shortHash : string | undefined , avatar : string | undefined , author : string , email : string | undefined , date : string , message : string , shortStat ?: CommitShortStat , remoteSourceCommands : Command [ ] = [ ] ) : void {
58- this . tooltip = new MarkdownString ( '' , true ) ;
59- this . tooltip . isTrusted = true ;
60-
61- const avatarMarkdown = avatar
62- ? ``
63- : '$(account)' ;
64-
65- if ( email ) {
66- const emailTitle = l10n . t ( 'Email' ) ;
67- this . tooltip . appendMarkdown ( `${ avatarMarkdown } [**${ author } **](mailto:${ email } "${ emailTitle } ${ author } ")` ) ;
68- } else {
69- this . tooltip . appendMarkdown ( `${ avatarMarkdown } **${ author } **` ) ;
70- }
71-
72- this . tooltip . appendMarkdown ( `, $(history) ${ date } \n\n` ) ;
73- this . tooltip . appendMarkdown ( `${ message } \n\n` ) ;
74-
75- if ( shortStat ) {
76- this . tooltip . appendMarkdown ( `---\n\n` ) ;
77-
78- const labels : string [ ] = [ ] ;
79- if ( shortStat . insertions ) {
80- labels . push ( `<span style="color:var(--vscode-scmGraph-historyItemHoverAdditionsForeground);">${ shortStat . insertions === 1 ?
81- l10n . t ( '{0} insertion{1}' , shortStat . insertions , '(+)' ) :
82- l10n . t ( '{0} insertions{1}' , shortStat . insertions , '(+)' ) } </span>`) ;
83- }
84-
85- if ( shortStat . deletions ) {
86- labels . push ( `<span style="color:var(--vscode-scmGraph-historyItemHoverDeletionsForeground);">${ shortStat . deletions === 1 ?
87- l10n . t ( '{0} deletion{1}' , shortStat . deletions , '(-)' ) :
88- l10n . t ( '{0} deletions{1}' , shortStat . deletions , '(-)' ) } </span>`) ;
89- }
90-
91- this . tooltip . appendMarkdown ( `${ labels . join ( ', ' ) } \n\n` ) ;
92- }
93-
94- if ( hash && shortHash ) {
95- this . tooltip . appendMarkdown ( `---\n\n` ) ;
96-
97- this . tooltip . appendMarkdown ( `[\`$(git-commit) ${ shortHash } \`](command:git.viewCommit?${ encodeURIComponent ( JSON . stringify ( [ uri , hash , uri ] ) ) } "${ l10n . t ( 'Open Commit' ) } ")` ) ;
98- this . tooltip . appendMarkdown ( ' ' ) ;
99- this . tooltip . appendMarkdown ( `[$(copy)](command:git.copyContentToClipboard?${ encodeURIComponent ( JSON . stringify ( hash ) ) } "${ l10n . t ( 'Copy Commit Hash' ) } ")` ) ;
100-
101- // Remote commands
102- if ( remoteSourceCommands . length > 0 ) {
103- this . tooltip . appendMarkdown ( ' | ' ) ;
104-
105- const remoteCommandsMarkdown = remoteSourceCommands
106- . map ( command => `[${ command . title } ](command:${ command . command } ?${ encodeURIComponent ( JSON . stringify ( [ ...command . arguments ?? [ ] , hash ] ) ) } "${ command . tooltip } ")` ) ;
107- this . tooltip . appendMarkdown ( remoteCommandsMarkdown . join ( ' ' ) ) ;
108- }
109- }
110- }
111-
11255 private shortenRef ( ref : string ) : string {
11356 if ( ref === '' || ref === '~' || ref === 'HEAD' ) {
11457 return ref ;
@@ -215,13 +158,10 @@ export class GitTimelineProvider implements TimelineProvider {
215158 commits . splice ( commits . length - 1 , 1 ) ;
216159 }
217160
218- const dateFormatter = new Intl . DateTimeFormat ( env . language , { year : 'numeric' , month : 'long' , day : 'numeric' , hour : 'numeric' , minute : 'numeric' } ) ;
219-
220161 const config = workspace . getConfiguration ( 'git' , Uri . file ( repo . root ) ) ;
221162 const dateType = config . get < 'committed' | 'authored' > ( 'timeline.date' ) ;
222163 const showAuthor = config . get < boolean > ( 'timeline.showAuthor' ) ;
223164 const showUncommitted = config . get < boolean > ( 'timeline.showUncommitted' ) ;
224- const commitShortHashLength = config . get < number > ( 'commitShortHashLength' ) ?? 7 ;
225165
226166 const openComparison = l10n . t ( 'Open Comparison' ) ;
227167
@@ -254,10 +194,15 @@ export class GitTimelineProvider implements TimelineProvider {
254194 item . description = c . authorName ;
255195 }
256196
257- const commitRemoteSourceCommands = ! unpublishedCommits . has ( c . hash ) ? remoteHoverCommands : [ ] ;
197+ const commitRemoteSourceCommands = ! unpublishedCommits . has ( c . hash ) ? remoteHoverCommands ?? [ ] : [ ] ;
258198 const messageWithLinks = await provideSourceControlHistoryItemMessageLinks ( this . model , repo , message ) ?? message ;
259199
260- item . setItemDetails ( uri , c . hash , truncate ( c . hash , commitShortHashLength , false ) , avatars ?. get ( c . hash ) , c . authorName ! , c . authorEmail , dateFormatter . format ( date ) , messageWithLinks , c . shortStat , commitRemoteSourceCommands ) ;
200+ const commands : Command [ ] [ ] = [
201+ getHistoryItemHoverCommitHashCommands ( uri , c . hash ) ,
202+ processHistoryItemRemoteHoverCommands ( commitRemoteSourceCommands , c . hash )
203+ ] ;
204+
205+ item . tooltip = getHistoryItemHover ( avatars ?. get ( c . hash ) , c . authorName , c . authorEmail , date , messageWithLinks , c . shortStat , commands ) ;
261206
262207 const cmd = this . commands . resolveTimelineOpenDiffCommand ( item , uri ) ;
263208 if ( cmd ) {
@@ -282,7 +227,7 @@ export class GitTimelineProvider implements TimelineProvider {
282227 // TODO@eamodio : Replace with a better icon -- reflecting its status maybe?
283228 item . iconPath = new ThemeIcon ( 'git-commit' ) ;
284229 item . description = '' ;
285- item . setItemDetails ( uri , undefined , undefined , undefined , you , undefined , dateFormatter . format ( date ) , Resource . getStatusText ( index . type ) ) ;
230+ item . tooltip = getHistoryItemHover ( undefined , you , undefined , date , Resource . getStatusText ( index . type ) , undefined , undefined ) ;
286231
287232 const cmd = this . commands . resolveTimelineOpenDiffCommand ( item , uri ) ;
288233 if ( cmd ) {
@@ -304,7 +249,7 @@ export class GitTimelineProvider implements TimelineProvider {
304249 const item = new GitTimelineItem ( '' , index ? '~' : 'HEAD' , l10n . t ( 'Uncommitted Changes' ) , date . getTime ( ) , 'working' , 'git:file:working' ) ;
305250 item . iconPath = new ThemeIcon ( 'circle-outline' ) ;
306251 item . description = '' ;
307- item . setItemDetails ( uri , undefined , undefined , undefined , you , undefined , dateFormatter . format ( date ) , Resource . getStatusText ( working . type ) ) ;
252+ item . tooltip = getHistoryItemHover ( undefined , you , undefined , date , Resource . getStatusText ( working . type ) , undefined , undefined ) ;
308253
309254 const cmd = this . commands . resolveTimelineOpenDiffCommand ( item , uri ) ;
310255 if ( cmd ) {
0 commit comments