@@ -17,6 +17,13 @@ import { MergeEditorInput, MergeEditorInputData } from 'vs/workbench/contrib/mer
17
17
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
18
18
import { MergeEditorSerializer } from './mergeEditorSerializer' ;
19
19
import { Codicon } from 'vs/base/common/codicons' ;
20
+ import { IWorkbenchFileService } from 'vs/workbench/services/files/common/files' ;
21
+ import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider' ;
22
+ import { VSBuffer } from 'vs/base/common/buffer' ;
23
+ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService' ;
24
+ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput' ;
25
+ import { INotificationService } from 'vs/platform/notification/common/notification' ;
26
+ import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
20
27
21
28
Registry . as < IEditorPaneRegistry > ( EditorExtensions . EditorPane ) . registerEditorPane (
22
29
EditorPaneDescriptor . create (
@@ -152,3 +159,132 @@ interface IOpenEditorArgs {
152
159
input2 : MergeEditorInputData ;
153
160
output : URI ;
154
161
}
162
+
163
+ registerAction2 ( class extends Action2 {
164
+
165
+ constructor ( ) {
166
+ super ( {
167
+ id : 'merge.dev.copyContents' ,
168
+ title : localize ( 'merge.dev.copyContents' , "Developer Merge Editor: Copy Contents of Inputs, Base and Result as JSON" ) ,
169
+ icon : Codicon . layoutCentered ,
170
+ f1 : true ,
171
+ } ) ;
172
+ }
173
+
174
+ run ( accessor : ServicesAccessor ) : void {
175
+ const { activeEditorPane } = accessor . get ( IEditorService ) ;
176
+ const clipboardService = accessor . get ( IClipboardService ) ;
177
+ const notificationService = accessor . get ( INotificationService ) ;
178
+
179
+ if ( ! ( activeEditorPane instanceof MergeEditor ) ) {
180
+ notificationService . info ( {
181
+ name : localize ( 'mergeEditor.name' , 'Merge Editor' ) ,
182
+ message : localize ( 'mergeEditor.noActiveMergeEditor' , "No active merge editor" )
183
+ } ) ;
184
+ return ;
185
+ }
186
+ const model = activeEditorPane . model ;
187
+ if ( ! model ) {
188
+ return ;
189
+ }
190
+ const contents : MergeEditorContents = {
191
+ languageId : model . result . getLanguageId ( ) ,
192
+ base : model . base . getValue ( ) ,
193
+ input1 : model . input1 . getValue ( ) ,
194
+ input2 : model . input2 . getValue ( ) ,
195
+ result : model . result . getValue ( ) ,
196
+ } ;
197
+ const jsonStr = JSON . stringify ( contents , undefined , 4 ) ;
198
+ clipboardService . writeText ( jsonStr ) ;
199
+
200
+ notificationService . info ( {
201
+ name : localize ( 'mergeEditor.name' , 'Merge Editor' ) ,
202
+ message : localize ( 'mergeEditor.successfullyCopiedMergeEditorContents' , "Successfully copied merge editor contents" ) ,
203
+ } ) ;
204
+ }
205
+ } ) ;
206
+
207
+ registerAction2 ( class extends Action2 {
208
+
209
+ constructor ( ) {
210
+ super ( {
211
+ id : 'merge.dev.openContents' ,
212
+ title : localize ( 'merge.dev.openContents' , "Developer Merge Editor: Open Contents of Inputs, Base and Result from JSON" ) ,
213
+ icon : Codicon . layoutCentered ,
214
+ f1 : true ,
215
+ } ) ;
216
+ }
217
+
218
+ async run ( accessor : ServicesAccessor ) : Promise < void > {
219
+ const service = accessor . get ( IWorkbenchFileService ) ;
220
+ const instaService = accessor . get ( IInstantiationService ) ;
221
+ const editorService = accessor . get ( IEditorService ) ;
222
+ const inputService = accessor . get ( IQuickInputService ) ;
223
+ const clipboardService = accessor . get ( IClipboardService ) ;
224
+ const textModelService = accessor . get ( ITextModelService ) ;
225
+
226
+ const result = await inputService . input ( {
227
+ prompt : localize ( 'mergeEditor.enterJSON' , 'Enter JSON' ) ,
228
+ value : await clipboardService . readText ( ) ,
229
+ } ) ;
230
+ if ( ! result ) {
231
+ return ;
232
+ }
233
+
234
+ const content : MergeEditorContents = JSON . parse ( result ) ;
235
+
236
+ const scheme = 'merge-editor-dev' ;
237
+
238
+ let provider = service . getProvider ( scheme ) as InMemoryFileSystemProvider | undefined ;
239
+ if ( ! provider ) {
240
+ provider = new InMemoryFileSystemProvider ( ) ;
241
+ service . registerProvider ( scheme , provider ) ;
242
+ }
243
+
244
+ const baseUri = URI . from ( { scheme, path : '/ancestor' } ) ;
245
+ const input1Uri = URI . from ( { scheme, path : '/input1' } ) ;
246
+ const input2Uri = URI . from ( { scheme, path : '/input2' } ) ;
247
+ const resultUri = URI . from ( { scheme, path : '/result' } ) ;
248
+
249
+ function writeFile ( uri : URI , content : string ) : Promise < void > {
250
+ return provider ! . writeFile ( uri , VSBuffer . fromString ( content ) . buffer , { create : true , overwrite : true , unlock : true } ) ;
251
+ }
252
+
253
+ await Promise . all ( [
254
+ writeFile ( baseUri , content . base ) ,
255
+ writeFile ( input1Uri , content . input1 ) ,
256
+ writeFile ( input2Uri , content . input2 ) ,
257
+ writeFile ( resultUri , content . result ) ,
258
+ ] ) ;
259
+
260
+ async function setLanguageId ( uri : URI , languageId : string ) : Promise < void > {
261
+ const ref = await textModelService . createModelReference ( uri ) ;
262
+ ref . object . textEditorModel . setMode ( languageId ) ;
263
+ ref . dispose ( ) ;
264
+ }
265
+
266
+ await Promise . all ( [
267
+ setLanguageId ( baseUri , content . languageId ) ,
268
+ setLanguageId ( input1Uri , content . languageId ) ,
269
+ setLanguageId ( input2Uri , content . languageId ) ,
270
+ setLanguageId ( resultUri , content . languageId ) ,
271
+ ] ) ;
272
+
273
+ const input = instaService . createInstance (
274
+ MergeEditorInput ,
275
+ baseUri ,
276
+ { uri : input1Uri , description : 'Input 1' , detail : '(from JSON)' } ,
277
+ { uri : input2Uri , description : 'Input 2' , detail : '(from JSON)' } ,
278
+ resultUri ,
279
+ ) ;
280
+ editorService . openEditor ( input ) ;
281
+ }
282
+ } ) ;
283
+
284
+ interface MergeEditorContents {
285
+ languageId : string ;
286
+ base : string ;
287
+ input1 : string ;
288
+ input2 : string ;
289
+ result : string ;
290
+ }
0 commit comments