@@ -27,17 +27,24 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
27
27
import { IDialogService } from 'vs/platform/dialogs/common/dialogs' ;
28
28
import { ILogService } from 'vs/platform/log/common/log' ;
29
29
import { IProductService } from 'vs/platform/product/common/productService' ;
30
+ import { IOpenerService } from 'vs/platform/opener/common/opener' ;
31
+ import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
30
32
31
33
registerSingleton ( ISessionSyncWorkbenchService , SessionSyncWorkbenchService ) ;
32
34
33
35
const applyLatestCommand = {
34
- id : 'workbench.sessionSync.actions.applyLatest' ,
36
+ id : 'workbench.experimental. sessionSync.actions.applyLatest' ,
35
37
title : localize ( 'apply latest' , "{0}: Apply Latest Edit Session" , EDIT_SESSION_SYNC_TITLE ) ,
36
38
} ;
37
39
const storeLatestCommand = {
38
- id : 'workbench.sessionSync.actions.storeLatest' ,
40
+ id : 'workbench.experimental. sessionSync.actions.storeLatest' ,
39
41
title : localize ( 'store latest' , "{0}: Store Latest Edit Session" , EDIT_SESSION_SYNC_TITLE ) ,
40
42
} ;
43
+ const continueEditSessionCommand = {
44
+ id : '_workbench.experimental.sessionSync.actions.continueEditSession' ,
45
+ title : localize ( 'continue edit session' , "{0}: Continue Edit Session" , EDIT_SESSION_SYNC_TITLE ) ,
46
+ } ;
47
+ const queryParamName = 'editSessionId' ;
41
48
42
49
export class SessionSyncContribution extends Disposable implements IWorkbenchContribution {
43
50
@@ -47,17 +54,23 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
47
54
@ISessionSyncWorkbenchService private readonly sessionSyncWorkbenchService : ISessionSyncWorkbenchService ,
48
55
@IFileService private readonly fileService : IFileService ,
49
56
@IProgressService private readonly progressService : IProgressService ,
57
+ @IOpenerService private readonly openerService : IOpenerService ,
50
58
@ITelemetryService private readonly telemetryService : ITelemetryService ,
51
59
@ISCMService private readonly scmService : ISCMService ,
52
60
@INotificationService private readonly notificationService : INotificationService ,
53
61
@IDialogService private readonly dialogService : IDialogService ,
54
62
@ILogService private readonly logService : ILogService ,
63
+ @IEnvironmentService private readonly environmentService : IEnvironmentService ,
55
64
@IProductService private readonly productService : IProductService ,
56
65
@IConfigurationService private configurationService : IConfigurationService ,
57
66
@IWorkspaceContextService private readonly contextService : IWorkspaceContextService ,
58
67
) {
59
68
super ( ) ;
60
69
70
+ if ( this . environmentService . editSessionId !== undefined ) {
71
+ void this . applyEditSession ( this . environmentService . editSessionId ) . then ( ( ) => this . environmentService . editSessionId = undefined ) ;
72
+ }
73
+
61
74
this . configurationService . onDidChangeConfiguration ( ( e ) => {
62
75
if ( e . affectsConfiguration ( 'workbench.experimental.sessionSync.enabled' ) ) {
63
76
this . registerActions ( ) ;
@@ -72,15 +85,50 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
72
85
return ;
73
86
}
74
87
75
- this . registerApplyEditSessionAction ( ) ;
76
- this . registerStoreEditSessionAction ( ) ;
88
+ this . registerContinueEditSessionAction ( ) ;
89
+
90
+ this . registerApplyLatestEditSessionAction ( ) ;
91
+ this . registerStoreLatestEditSessionAction ( ) ;
77
92
78
93
this . registered = true ;
79
94
}
80
95
81
- private registerApplyEditSessionAction ( ) : void {
96
+ private registerContinueEditSessionAction ( ) {
97
+ const that = this ;
98
+ this . _register ( registerAction2 ( class ContinueEditSessionAction extends Action2 {
99
+ constructor ( ) {
100
+ super ( {
101
+ id : continueEditSessionCommand . id ,
102
+ title : continueEditSessionCommand . title
103
+ } ) ;
104
+ }
105
+
106
+ async run ( accessor : ServicesAccessor , workspaceUri : URI ) : Promise < void > {
107
+ // Run the store action to get back a ref
108
+ const ref = await that . storeEditSession ( ) ;
109
+
110
+ // Append the ref to the URI
111
+ if ( ref !== undefined ) {
112
+ const encodedRef = encodeURIComponent ( ref ) ;
113
+ workspaceUri = workspaceUri . with ( {
114
+ query : workspaceUri . query . length > 0 ? ( workspaceUri + `&${ queryParamName } =${ encodedRef } ` ) : `${ queryParamName } =${ encodedRef } `
115
+ } ) ;
116
+
117
+ that . environmentService . editSessionId = ref ;
118
+ } else {
119
+ that . logService . warn ( `Edit Sessions: Failed to store edit session when invoking ${ continueEditSessionCommand . id } .` ) ;
120
+ }
121
+
122
+ // Open the URI
123
+ that . logService . info ( `Edit Sessions: opening ${ workspaceUri . toString ( ) } ` ) ;
124
+ await that . openerService . open ( workspaceUri , { openExternal : true } ) ;
125
+ }
126
+ } ) ) ;
127
+ }
128
+
129
+ private registerApplyLatestEditSessionAction ( ) : void {
82
130
const that = this ;
83
- this . _register ( registerAction2 ( class ApplyEditSessionAction extends Action2 {
131
+ this . _register ( registerAction2 ( class ApplyLatestEditSessionAction extends Action2 {
84
132
constructor ( ) {
85
133
super ( {
86
134
id : applyLatestCommand . id ,
@@ -100,9 +148,9 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
100
148
} ) ) ;
101
149
}
102
150
103
- private registerStoreEditSessionAction ( ) : void {
151
+ private registerStoreLatestEditSessionAction ( ) : void {
104
152
const that = this ;
105
- this . _register ( registerAction2 ( class StoreEditSessionAction extends Action2 {
153
+ this . _register ( registerAction2 ( class StoreLatestEditSessionAction extends Action2 {
106
154
constructor ( ) {
107
155
super ( {
108
156
id : storeLatestCommand . id ,
@@ -122,8 +170,12 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
122
170
} ) ) ;
123
171
}
124
172
125
- async applyEditSession ( ) {
126
- const editSession = await this . sessionSyncWorkbenchService . read ( undefined ) ;
173
+ async applyEditSession ( ref ?: string ) : Promise < void > {
174
+ if ( ref !== undefined ) {
175
+ this . logService . info ( `Edit Sessions: Applying edit session with ref ${ ref } .` ) ;
176
+ }
177
+
178
+ const editSession = await this . sessionSyncWorkbenchService . read ( ref ) ;
127
179
if ( ! editSession ) {
128
180
return ;
129
181
}
@@ -160,6 +212,7 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
160
212
}
161
213
162
214
if ( hasLocalUncommittedChanges ) {
215
+ // TODO@joyceerhl Provide the option to diff files which would be overwritten by edit session contents
163
216
const result = await this . dialogService . confirm ( {
164
217
message : localize ( 'apply edit session warning' , 'Applying your edit session may overwrite your existing uncommitted changes. Do you want to proceed?' ) ,
165
218
type : 'warning' ,
@@ -178,12 +231,12 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
178
231
}
179
232
}
180
233
} catch ( ex ) {
181
- this . logService . error ( ex ) ;
234
+ this . logService . error ( 'Edit Sessions:' , ( ex as Error ) . toString ( ) ) ;
182
235
this . notificationService . error ( localize ( 'apply failed' , "Failed to apply your edit session." ) ) ;
183
236
}
184
237
}
185
238
186
- async storeEditSession ( ) {
239
+ async storeEditSession ( ) : Promise < string | undefined > {
187
240
const folders : Folder [ ] = [ ] ;
188
241
189
242
for ( const repository of this . scmService . repositories ) {
@@ -223,7 +276,9 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
223
276
const data : EditSession = { folders, version : 1 } ;
224
277
225
278
try {
226
- await this . sessionSyncWorkbenchService . write ( data ) ;
279
+ const ref = await this . sessionSyncWorkbenchService . write ( data ) ;
280
+ this . logService . info ( `Edit Sessions: Stored edit session with ref ${ ref } .` ) ;
281
+ return ref ;
227
282
} catch ( ex ) {
228
283
type UploadFailedEvent = { reason : string } ;
229
284
type UploadFailedClassification = {
@@ -245,6 +300,8 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
245
300
}
246
301
}
247
302
}
303
+
304
+ return undefined ;
248
305
}
249
306
250
307
private getChangedResources ( repository : ISCMRepository ) {
0 commit comments