66import { Disposable } from 'vs/base/common/lifecycle' ;
77import { IFileService , FileSystemProviderErrorCode , FileSystemProviderError , IFileContent } from 'vs/platform/files/common/files' ;
88import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
9- import { IUserData , UserDataSyncStoreError , UserDataSyncStoreErrorCode , ISynchroniser , SyncStatus , SETTINGS_PREVIEW_RESOURCE , ISettingsMergeService , IUserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSync' ;
9+ import { IUserData , UserDataSyncStoreError , UserDataSyncStoreErrorCode , ISynchroniser , SyncStatus , ISettingsMergeService , IUserDataSyncStoreService , SETTINGS_PREVIEW_RESOURCE } from 'vs/platform/userDataSync/common/userDataSync' ;
1010import { VSBuffer } from 'vs/base/common/buffer' ;
1111import { parse , ParseError } from 'vs/base/common/json' ;
12- import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
1312import { localize } from 'vs/nls' ;
1413import { Emitter , Event } from 'vs/base/common/event' ;
1514import { ILogService } from 'vs/platform/log/common/log' ;
16- import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
1715import { CancelablePromise , createCancelablePromise , ThrottledDelayer } from 'vs/base/common/async' ;
1816import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
17+ import { URI } from 'vs/base/common/uri' ;
1918
2019interface ISyncPreviewResult {
2120 readonly fileContent : IFileContent | null ;
@@ -41,15 +40,15 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
4140 private _onDidChangeLocal : Emitter < void > = this . _register ( new Emitter < void > ( ) ) ;
4241 readonly onDidChangeLocal : Event < void > = this . _onDidChangeLocal . event ;
4342
43+ readonly conflicts : URI = SETTINGS_PREVIEW_RESOURCE ;
44+
4445 constructor (
4546 @IFileService private readonly fileService : IFileService ,
4647 @IEnvironmentService private readonly environmentService : IEnvironmentService ,
4748 @IStorageService private readonly storageService : IStorageService ,
4849 @IUserDataSyncStoreService private readonly userDataSyncStoreService : IUserDataSyncStoreService ,
49- @IEditorService private readonly editorService : IEditorService ,
5050 @ISettingsMergeService private readonly settingsMergeService : ISettingsMergeService ,
5151 @ILogService private readonly logService : ILogService ,
52- @IHistoryService private readonly historyService : IHistoryService ,
5352 ) {
5453 super ( ) ;
5554 this . throttledDelayer = this . _register ( new ThrottledDelayer < void > ( 500 ) ) ;
@@ -111,24 +110,6 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
111110 }
112111 }
113112
114- handleConflicts ( ) : boolean {
115- if ( this . status !== SyncStatus . HasConflicts ) {
116- return false ;
117- }
118- const resourceInput = {
119- resource : SETTINGS_PREVIEW_RESOURCE ,
120- label : localize ( 'Settings Conflicts' , "Local ↔ Remote (Settings Conflicts)" ) ,
121- options : {
122- preserveFocus : false ,
123- pinned : false ,
124- revealIfVisible : true ,
125- } ,
126- mode : 'jsonc'
127- } ;
128- this . editorService . openEditor ( resourceInput ) . then ( ( ) => this . historyService . remove ( resourceInput ) ) ;
129- return true ;
130- }
131-
132113 async continueSync ( ) : Promise < boolean > {
133114 if ( this . status !== SyncStatus . HasConflicts ) {
134115 return false ;
@@ -142,8 +123,8 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
142123 return ;
143124 }
144125
145- if ( await this . fileService . exists ( SETTINGS_PREVIEW_RESOURCE ) ) {
146- const settingsPreivew = await this . fileService . readFile ( SETTINGS_PREVIEW_RESOURCE ) ;
126+ if ( await this . fileService . exists ( this . conflicts ) ) {
127+ const settingsPreivew = await this . fileService . readFile ( this . conflicts ) ;
147128 const content = settingsPreivew . value . toString ( ) ;
148129 if ( this . hasErrors ( content ) ) {
149130 return Promise . reject ( localize ( 'errorInvalidSettings' , "Unable to sync settings. Please resolve conflicts without any errors/warnings and try again." ) ) ;
@@ -162,7 +143,7 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
162143 }
163144
164145 // Delete the preview
165- await this . fileService . del ( SETTINGS_PREVIEW_RESOURCE ) ;
146+ await this . fileService . del ( this . conflicts ) ;
166147 }
167148
168149 this . syncPreviewResultPromise = null ;
@@ -194,15 +175,15 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
194175 if ( fileContent && ! remoteUserData ) {
195176 this . logService . trace ( 'Settings Sync: Remote contents does not exist. So sync with settings file.' ) ;
196177 hasRemoteChanged = true ;
197- await this . fileService . writeFile ( SETTINGS_PREVIEW_RESOURCE , VSBuffer . fromString ( fileContent . value . toString ( ) ) ) ;
178+ await this . fileService . writeFile ( this . conflicts , VSBuffer . fromString ( fileContent . value . toString ( ) ) ) ;
198179 return { fileContent, remoteUserData, hasLocalChanged, hasRemoteChanged, hasConflicts } ;
199180 }
200181
201182 // Settings file does not exist, so sync with remote contents.
202183 if ( remoteUserData && ! fileContent ) {
203184 this . logService . trace ( 'Settings Sync: Settings file does not exist. So sync with remote contents' ) ;
204185 hasLocalChanged = true ;
205- await this . fileService . writeFile ( SETTINGS_PREVIEW_RESOURCE , VSBuffer . fromString ( remoteUserData . content ) ) ;
186+ await this . fileService . writeFile ( this . conflicts , VSBuffer . fromString ( remoteUserData . content ) ) ;
206187 return { fileContent, remoteUserData, hasLocalChanged, hasRemoteChanged, hasConflicts } ;
207188 }
208189
@@ -221,7 +202,7 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
221202 if ( hasLocalChanged || hasRemoteChanged ) {
222203 // Sync only if there are changes
223204 hasConflicts = this . hasErrors ( mergeContent ) ;
224- await this . fileService . writeFile ( SETTINGS_PREVIEW_RESOURCE , VSBuffer . fromString ( mergeContent ) ) ;
205+ await this . fileService . writeFile ( this . conflicts , VSBuffer . fromString ( mergeContent ) ) ;
225206 return { fileContent, remoteUserData, hasLocalChanged, hasRemoteChanged, hasConflicts } ;
226207 }
227208 }
0 commit comments