@codingame/monaco-vscode-bulk-edit-service-override 25.1.1 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-bulk-edit-service-override",
3
- "version": "25.1.1",
3
+ "version": "26.0.0",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - bulk-edit service-override",
6
6
  "keywords": [],
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-api": "25.1.1"
18
+ "@codingame/monaco-vscode-api": "26.0.0"
19
19
  },
20
20
  "main": "index.js",
21
21
  "module": "index.js",
@@ -41,11 +41,23 @@ function liftEdits(edits) {
41
41
  if (ResourceAttachmentEdit.is(edit)) {
42
42
  return ResourceAttachmentEdit.lift(edit);
43
43
  }
44
- throw ( new Error('Unsupported edit'));
44
+ throw ( new Error("Unsupported edit"));
45
45
  }));
46
46
  }
47
47
  let BulkEdit = class BulkEdit {
48
- constructor(_label, _code, _editor, _progress, _token, _edits, _undoRedoGroup, _undoRedoSource, _confirmBeforeUndo, _instaService, _logService) {
48
+ constructor(
49
+ _label,
50
+ _code,
51
+ _editor,
52
+ _progress,
53
+ _token,
54
+ _edits,
55
+ _undoRedoGroup,
56
+ _undoRedoSource,
57
+ _confirmBeforeUndo,
58
+ _instaService,
59
+ _logService
60
+ ) {
49
61
  this._label = _label;
50
62
  this._code = _code;
51
63
  this._editor = _editor;
@@ -66,30 +78,26 @@ let BulkEdit = class BulkEdit {
66
78
  if (edit instanceof ResourceTextEdit) {
67
79
  textEditCount += 1;
68
80
  textEditResources.set(edit.resource, true);
69
- }
70
- else if (edit instanceof ResourceFileEdit) {
81
+ } else if (edit instanceof ResourceFileEdit) {
71
82
  otherResources.set(edit.oldResource ?? edit.newResource, true);
72
83
  }
73
84
  }
74
85
  if (this._edits.length === 0) {
75
- return localize(4506, "Made no edits");
76
- }
77
- else if (otherResources.size === 0) {
86
+ return localize(4516, "Made no edits");
87
+ } else if (otherResources.size === 0) {
78
88
  if (textEditCount > 1 && textEditResources.size > 1) {
79
89
  return localize(
80
- 4507,
90
+ 4517,
81
91
  "Made {0} text edits in {1} files",
82
92
  textEditCount,
83
93
  textEditResources.size
84
94
  );
95
+ } else {
96
+ return localize(4518, "Made {0} text edits in one file", textEditCount);
85
97
  }
86
- else {
87
- return localize(4508, "Made {0} text edits in one file", textEditCount);
88
- }
89
- }
90
- else {
98
+ } else {
91
99
  return localize(
92
- 4509,
100
+ 4519,
93
101
  "Made {0} text edits in {1} files, also created or deleted {2} files",
94
102
  textEditCount,
95
103
  textEditResources.size,
@@ -105,14 +113,20 @@ let BulkEdit = class BulkEdit {
105
113
  for (let i = 1; i < this._edits.length; i++) {
106
114
  if (Object.getPrototypeOf(this._edits[i - 1]) === Object.getPrototypeOf(this._edits[i])) {
107
115
  ranges[ranges.length - 1]++;
108
- }
109
- else {
116
+ } else {
110
117
  ranges.push(1);
111
118
  }
112
119
  }
113
120
  const increment = this._edits.length > 1 ? 0 : undefined;
114
- this._progress.report({ increment, total: 100 });
115
- const progress = { report: _ => this._progress.report({ increment: 100 / this._edits.length }) };
121
+ this._progress.report({
122
+ increment,
123
+ total: 100
124
+ });
125
+ const progress = {
126
+ report: _ => this._progress.report({
127
+ increment: 100 / this._edits.length
128
+ })
129
+ };
116
130
  const resources = [];
117
131
  let index = 0;
118
132
  for (const range of ranges) {
@@ -121,51 +135,64 @@ let BulkEdit = class BulkEdit {
121
135
  }
122
136
  const group = this._edits.slice(index, index + range);
123
137
  if (group[0] instanceof ResourceFileEdit) {
124
- resources.push(await this._performFileEdits(group, this._undoRedoGroup, this._undoRedoSource, this._confirmBeforeUndo, progress));
125
- }
126
- else if (group[0] instanceof ResourceTextEdit) {
127
- resources.push(await this._performTextEdits(group, this._undoRedoGroup, this._undoRedoSource, progress, reason));
128
- }
129
- else if (group[0] instanceof ResourceNotebookCellEdit) {
130
- resources.push(await this._performCellEdits(group, this._undoRedoGroup, this._undoRedoSource, progress));
131
- }
132
- else if (group[0] instanceof ResourceAttachmentEdit) {
133
- resources.push(await this._performOpaqueEdits(group, this._undoRedoGroup, this._undoRedoSource, progress));
134
- }
135
- else {
136
- console.log('UNKNOWN EDIT');
138
+ resources.push(await this._performFileEdits(
139
+ group,
140
+ this._undoRedoGroup,
141
+ this._undoRedoSource,
142
+ this._confirmBeforeUndo,
143
+ progress
144
+ ));
145
+ } else if (group[0] instanceof ResourceTextEdit) {
146
+ resources.push(
147
+ await this._performTextEdits(group, this._undoRedoGroup, this._undoRedoSource, progress, reason)
148
+ );
149
+ } else if (group[0] instanceof ResourceNotebookCellEdit) {
150
+ resources.push(
151
+ await this._performCellEdits(group, this._undoRedoGroup, this._undoRedoSource, progress)
152
+ );
153
+ } else if (group[0] instanceof ResourceAttachmentEdit) {
154
+ resources.push(
155
+ await this._performOpaqueEdits(group, this._undoRedoGroup, this._undoRedoSource, progress)
156
+ );
157
+ } else {
158
+ console.log("UNKNOWN EDIT");
137
159
  }
138
160
  index = index + range;
139
161
  }
140
162
  return resources.flat();
141
163
  }
142
164
  async _performFileEdits(edits, undoRedoGroup, undoRedoSource, confirmBeforeUndo, progress) {
143
- this._logService.debug('_performFileEdits', JSON.stringify(edits));
144
- const model = this._instaService.createInstance(BulkFileEdits, this._label || ( localize(4510, "Workspace Edit")), this._code || 'undoredo.workspaceEdit', undoRedoGroup, undoRedoSource, confirmBeforeUndo, progress, this._token, edits);
165
+ this._logService.debug("_performFileEdits", JSON.stringify(edits));
166
+ const model = this._instaService.createInstance(BulkFileEdits, this._label || ( localize(4520, "Workspace Edit")), this._code || "undoredo.workspaceEdit", undoRedoGroup, undoRedoSource, confirmBeforeUndo, progress, this._token, edits);
145
167
  return await model.apply();
146
168
  }
147
169
  async _performTextEdits(edits, undoRedoGroup, undoRedoSource, progress, reason) {
148
- this._logService.debug('_performTextEdits', JSON.stringify(edits));
149
- const model = this._instaService.createInstance(BulkTextEdits, this._label || ( localize(4510, "Workspace Edit")), this._code || 'undoredo.workspaceEdit', this._editor, undoRedoGroup, undoRedoSource, progress, this._token, edits);
170
+ this._logService.debug("_performTextEdits", JSON.stringify(edits));
171
+ const model = this._instaService.createInstance(BulkTextEdits, this._label || ( localize(4520, "Workspace Edit")), this._code || "undoredo.workspaceEdit", this._editor, undoRedoGroup, undoRedoSource, progress, this._token, edits);
150
172
  return await model.apply(reason);
151
173
  }
152
174
  async _performCellEdits(edits, undoRedoGroup, undoRedoSource, progress) {
153
- this._logService.debug('_performCellEdits', JSON.stringify(edits));
175
+ this._logService.debug("_performCellEdits", JSON.stringify(edits));
154
176
  const model = this._instaService.createInstance(BulkCellEdits, undoRedoGroup, undoRedoSource, progress, this._token, edits);
155
177
  return await model.apply();
156
178
  }
157
179
  async _performOpaqueEdits(edits, undoRedoGroup, undoRedoSource, progress) {
158
- this._logService.debug('_performOpaqueEdits', JSON.stringify(edits));
180
+ this._logService.debug("_performOpaqueEdits", JSON.stringify(edits));
159
181
  const model = this._instaService.createInstance(OpaqueEdits, undoRedoGroup, undoRedoSource, progress, this._token, edits);
160
182
  return await model.apply();
161
183
  }
162
184
  };
163
- BulkEdit = ( __decorate([
164
- ( __param(9, IInstantiationService)),
165
- ( __param(10, ILogService))
166
- ], BulkEdit));
185
+ BulkEdit = ( __decorate([( __param(9, IInstantiationService)), ( __param(10, ILogService))], BulkEdit));
167
186
  let BulkEditService = class BulkEditService {
168
- constructor(_instaService, _logService, _editorService, _lifecycleService, _dialogService, _workingCopyService, _configService) {
187
+ constructor(
188
+ _instaService,
189
+ _logService,
190
+ _editorService,
191
+ _lifecycleService,
192
+ _dialogService,
193
+ _workingCopyService,
194
+ _configService
195
+ ) {
169
196
  this._instaService = _instaService;
170
197
  this._logService = _logService;
171
198
  this._editorService = _editorService;
@@ -189,7 +216,10 @@ let BulkEditService = class BulkEditService {
189
216
  async apply(editsIn, options) {
190
217
  let edits = liftEdits(Array.isArray(editsIn) ? editsIn : editsIn.edits);
191
218
  if (edits.length === 0) {
192
- return { ariaSummary: ( localize(4511, "Made no edits")), isApplied: false };
219
+ return {
220
+ ariaSummary: ( localize(4521, "Made no edits")),
221
+ isApplied: false
222
+ };
193
223
  }
194
224
  if (this._previewHandler && (options?.showPreview || ( edits.some(value => value.metadata?.needsConfirmation)))) {
195
225
  edits = await this._previewHandler(edits, options);
@@ -199,8 +229,7 @@ let BulkEditService = class BulkEditService {
199
229
  const candidate = this._editorService.activeTextEditorControl;
200
230
  if (isCodeEditor(candidate)) {
201
231
  codeEditor = candidate;
202
- }
203
- else if (isDiffEditor(candidate)) {
232
+ } else if (isDiffEditor(candidate)) {
204
233
  codeEditor = candidate.getModifiedEditor();
205
234
  }
206
235
  }
@@ -208,8 +237,8 @@ let BulkEditService = class BulkEditService {
208
237
  codeEditor = undefined;
209
238
  }
210
239
  let undoRedoGroup;
211
- let undoRedoGroupRemove = () => { };
212
- if (typeof options?.undoRedoGroupId === 'number') {
240
+ let undoRedoGroupRemove = () => {};
241
+ if (typeof options?.undoRedoGroupId === "number") {
213
242
  for (const candidate of this._activeUndoRedoGroups) {
214
243
  if (candidate.id === options.undoRedoGroupId) {
215
244
  undoRedoGroup = candidate;
@@ -222,35 +251,47 @@ let BulkEditService = class BulkEditService {
222
251
  undoRedoGroupRemove = this._activeUndoRedoGroups.push(undoRedoGroup);
223
252
  }
224
253
  const label = options?.quotableLabel || options?.label;
225
- const bulkEdit = this._instaService.createInstance(BulkEdit, label, options?.code, codeEditor, options?.progress ?? Progress.None, options?.token ?? CancellationToken.None, edits, undoRedoGroup, options?.undoRedoSource, !!options?.confirmBeforeUndo);
254
+ const bulkEdit = this._instaService.createInstance(
255
+ BulkEdit,
256
+ label,
257
+ options?.code,
258
+ codeEditor,
259
+ options?.progress ?? Progress.None,
260
+ options?.token ?? CancellationToken.None,
261
+ edits,
262
+ undoRedoGroup,
263
+ options?.undoRedoSource,
264
+ !!options?.confirmBeforeUndo
265
+ );
226
266
  let listener;
227
267
  try {
228
- listener = this._lifecycleService.onBeforeShutdown(e => e.veto(this._shouldVeto(label, e.reason), 'veto.blukEditService'));
268
+ listener = this._lifecycleService.onBeforeShutdown(e => e.veto(this._shouldVeto(label, e.reason), "veto.blukEditService"));
229
269
  const resources = await bulkEdit.perform(options?.reason);
230
270
  if (options?.respectAutoSaveConfig && this._configService.getValue(autoSaveSetting) === true && resources.length > 1) {
231
271
  await this._saveAll(resources);
232
272
  }
233
- return { ariaSummary: bulkEdit.ariaMessage(), isApplied: edits.length > 0 };
234
- }
235
- catch (err) {
273
+ return {
274
+ ariaSummary: bulkEdit.ariaMessage(),
275
+ isApplied: edits.length > 0
276
+ };
277
+ } catch (err) {
236
278
  this._logService.error(err);
237
279
  throw err;
238
- }
239
- finally {
280
+ } finally {
240
281
  listener?.dispose();
241
282
  undoRedoGroupRemove();
242
283
  }
243
284
  }
244
285
  async _saveAll(resources) {
245
286
  const set = ( new ResourceSet(resources));
246
- const saves = ( this._workingCopyService.dirtyWorkingCopies.map(async (copy) => {
287
+ const saves = ( this._workingCopyService.dirtyWorkingCopies.map(async copy => {
247
288
  if (( set.has(copy.resource))) {
248
289
  await copy.save();
249
290
  }
250
291
  }));
251
292
  const result = await Promise.allSettled(saves);
252
293
  for (const item of result) {
253
- if (item.status === 'rejected') {
294
+ if (item.status === "rejected") {
254
295
  this._logService.warn(item.reason);
255
296
  }
256
297
  }
@@ -258,50 +299,42 @@ let BulkEditService = class BulkEditService {
258
299
  async _shouldVeto(label, reason) {
259
300
  let message;
260
301
  switch (reason) {
261
- case ShutdownReason.CLOSE:
262
- message = ( localize(4512, "Are you sure you want to close the window?"));
263
- break;
264
- case ShutdownReason.LOAD:
265
- message = ( localize(4513, "Are you sure you want to change the workspace?"));
266
- break;
267
- case ShutdownReason.RELOAD:
268
- message = ( localize(4514, "Are you sure you want to reload the window?"));
269
- break;
270
- default:
271
- message = isMacintosh ? ( localize(4515, "Are you sure you want to quit?")) : ( localize(4516, "Are you sure you want to exit?"));
272
- break;
302
+ case ShutdownReason.CLOSE:
303
+ message = ( localize(4522, "Are you sure you want to close the window?"));
304
+ break;
305
+ case ShutdownReason.LOAD:
306
+ message = ( localize(4523, "Are you sure you want to change the workspace?"));
307
+ break;
308
+ case ShutdownReason.RELOAD:
309
+ message = ( localize(4524, "Are you sure you want to reload the window?"));
310
+ break;
311
+ default:
312
+ message = isMacintosh ? ( localize(4525, "Are you sure you want to quit?")) : ( localize(4526, "Are you sure you want to exit?"));
313
+ break;
273
314
  }
274
315
  const result = await this._dialogService.confirm({
275
316
  message,
276
317
  detail: ( localize(
277
- 4517,
318
+ 4527,
278
319
  "'{0}' is in progress.",
279
- label || ( localize(4518, "File operation"))
280
- )),
320
+ label || ( localize(4528, "File operation"))
321
+ ))
281
322
  });
282
323
  return !result.confirmed;
283
324
  }
284
325
  };
285
- BulkEditService = ( __decorate([
286
- ( __param(0, IInstantiationService)),
287
- ( __param(1, ILogService)),
288
- ( __param(2, IEditorService)),
289
- ( __param(3, ILifecycleService)),
290
- ( __param(4, IDialogService)),
291
- ( __param(5, IWorkingCopyService)),
292
- ( __param(6, IConfigurationService))
293
- ], BulkEditService));
294
- const autoSaveSetting = 'files.refactoring.autoSave';
326
+ BulkEditService = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, ILogService)), ( __param(2, IEditorService)), ( __param(3, ILifecycleService)), ( __param(4, IDialogService)), ( __param(5, IWorkingCopyService)), ( __param(6, IConfigurationService))], BulkEditService));
327
+ const autoSaveSetting = "files.refactoring.autoSave";
295
328
  ( Registry.as(Extensions.Configuration)).registerConfiguration({
296
- id: 'files',
329
+ id: "files",
297
330
  properties: {
298
331
  [autoSaveSetting]: {
299
332
  description: ( localize(
300
- 4519,
333
+ 4529,
301
334
  "Controls if files that were part of a refactoring are saved automatically"
302
335
  )),
303
336
  default: true,
304
- type: 'boolean'
337
+ type: "boolean"
305
338
  }
306
339
  }
307
340
  });