66import { IWorkbenchContributionsRegistry , Extensions as WorkbenchExtensions , IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
77import { IUserDataSyncService , SyncStatus } from 'vs/workbench/services/userData/common/userData' ;
88import { localize } from 'vs/nls' ;
9- import { Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
9+ import { Disposable , MutableDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
1010import { CommandsRegistry } from 'vs/platform/commands/common/commands' ;
1111import { Registry } from 'vs/platform/registry/common/platform' ;
1212import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle' ;
@@ -20,6 +20,7 @@ import { GLOBAL_ACTIVITY_ID } from 'vs/workbench/common/activity';
2020import { timeout } from 'vs/base/common/async' ;
2121import { registerEditorContribution } from 'vs/editor/browser/editorExtensions' ;
2222import { AcceptChangesController } from 'vs/workbench/contrib/userData/browser/userDataPreviewEditorContribution' ;
23+ import { INotificationService , Severity } from 'vs/platform/notification/common/notification' ;
2324
2425const CONTEXT_SYNC_STATE = new RawContextKey < string > ( 'syncStatus' , SyncStatus . Uninitialized ) ;
2526
@@ -74,11 +75,13 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
7475
7576 private readonly syncEnablementContext : IContextKey < string > ;
7677 private readonly badgeDisposable = this . _register ( new MutableDisposable ( ) ) ;
78+ private readonly conflictsWarningDisposable = this . _register ( new MutableDisposable ( ) ) ;
7779
7880 constructor (
79- @IUserDataSyncService userDataSyncService : IUserDataSyncService ,
81+ @IUserDataSyncService private readonly userDataSyncService : IUserDataSyncService ,
8082 @IContextKeyService contextKeyService : IContextKeyService ,
81- @IActivityService private readonly activityService : IActivityService
83+ @IActivityService private readonly activityService : IActivityService ,
84+ @INotificationService private readonly notificationService : INotificationService
8285 ) {
8386 super ( ) ;
8487 this . syncEnablementContext = CONTEXT_SYNC_STATE . bindTo ( contextKeyService ) ;
@@ -105,6 +108,24 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
105108 if ( badge ) {
106109 this . badgeDisposable . value = this . activityService . showActivity ( GLOBAL_ACTIVITY_ID , badge , clazz ) ;
107110 }
111+
112+ if ( status !== SyncStatus . HasConflicts ) {
113+ this . conflictsWarningDisposable . clear ( ) ;
114+ }
115+ }
116+
117+ private async sync ( ) : Promise < void > {
118+ await this . userDataSyncService . sync ( ) ;
119+ if ( this . userDataSyncService . status === SyncStatus . HasConflicts ) {
120+ const handle = this . notificationService . prompt ( Severity . Warning , localize ( 'conflicts detected' , "Unable to sync due to conflicts. Please resolve them to continue." ) ,
121+ [
122+ {
123+ label : localize ( 'resolve' , "Resolve Conflicts" ) ,
124+ run : ( ) => this . userDataSyncService . handleConflicts ( )
125+ }
126+ ] ) ;
127+ this . conflictsWarningDisposable . value = toDisposable ( ( ) => handle . close ( ) ) ;
128+ }
108129 }
109130
110131 private registerActions ( ) : void {
@@ -154,7 +175,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
154175
155176 // Command Pallette Actions
156177
157- CommandsRegistry . registerCommand ( 'workbench.userData.actions.startSync' , serviceAccessor => serviceAccessor . get ( IUserDataSyncService ) . sync ( ) ) ;
178+ CommandsRegistry . registerCommand ( 'workbench.userData.actions.startSync' , ( ) => this . sync ( ) ) ;
158179 MenuRegistry . appendMenuItem ( MenuId . CommandPalette , {
159180 command : {
160181 id : 'workbench.userData.actions.startSync' ,
@@ -163,6 +184,15 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
163184 when : ContextKeyExpr . and ( CONTEXT_SYNC_STATE . isEqualTo ( SyncStatus . Idle ) , ContextKeyExpr . not ( 'config.userConfiguration.autoSync' ) ) ,
164185 } ) ;
165186
187+ CommandsRegistry . registerCommand ( 'workbench.userData.actions.stopSync' , serviceAccessor => serviceAccessor . get ( IUserDataSyncService ) . stopSync ( ) ) ;
188+ MenuRegistry . appendMenuItem ( MenuId . CommandPalette , {
189+ command : {
190+ id : 'workbench.userData.actions.stopSync' ,
191+ title : localize ( 'stop sync' , "Sync: Stop" )
192+ } ,
193+ when : ContextKeyExpr . and ( CONTEXT_SYNC_STATE . isEqualTo ( SyncStatus . HasConflicts ) , ContextKeyExpr . not ( 'config.userConfiguration.autoSync' ) ) ,
194+ } ) ;
195+
166196 MenuRegistry . appendMenuItem ( MenuId . CommandPalette , {
167197 command : {
168198 id : 'sync.resolveConflicts' ,
0 commit comments