@codingame/monaco-vscode-bulk-edit-service-override 37.2.0 → 37.3.1

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.
@@ -1,393 +0,0 @@
1
-
2
- import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
- import { ITextModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService.service';
4
- import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
5
- import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service';
6
- import { IModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service';
7
- import { createTextBufferFactoryFromSnapshot } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model/textModel';
8
- import { DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
9
- import { coalesceInPlace } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
10
- import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
11
- import { EditOperation } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/editOperation';
12
- import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
13
- import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
14
- import { Emitter, Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
15
- import { ConflictDetector } from '../conflicts.js';
16
- import { ResourceMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
17
- import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
18
- import { extUri } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
19
- import { ResourceTextEdit, ResourceFileEdit } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService';
20
- import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
21
- import { generateUuid } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
22
- import { SnippetParser } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/snippet/browser/snippetParser';
23
- import { MicrotaskDelay } from '@codingame/monaco-vscode-api/vscode/vs/base/common/symbols';
24
- import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
25
-
26
- var BulkFileOperations_1, BulkEditPreviewProvider_1;
27
- class CheckedStates {
28
- constructor() {
29
- this._states = ( new WeakMap());
30
- this._checkedCount = 0;
31
- this._onDidChange = ( new Emitter());
32
- this.onDidChange = this._onDidChange.event;
33
- }
34
- dispose() {
35
- this._onDidChange.dispose();
36
- }
37
- get checkedCount() {
38
- return this._checkedCount;
39
- }
40
- isChecked(obj) {
41
- return this._states.get(obj) ?? false;
42
- }
43
- updateChecked(obj, value) {
44
- const valueNow = this._states.get(obj);
45
- if (valueNow === value) {
46
- return;
47
- }
48
- if (valueNow === undefined) {
49
- if (value) {
50
- this._checkedCount += 1;
51
- }
52
- } else {
53
- if (value) {
54
- this._checkedCount += 1;
55
- } else {
56
- this._checkedCount -= 1;
57
- }
58
- }
59
- this._states.set(obj, value);
60
- this._onDidChange.fire(obj);
61
- }
62
- }
63
- class BulkTextEdit {
64
- constructor(parent, textEdit) {
65
- this.parent = parent;
66
- this.textEdit = textEdit;
67
- }
68
- }
69
- var BulkFileOperationType;
70
- (function(BulkFileOperationType) {
71
- BulkFileOperationType[BulkFileOperationType["TextEdit"] = 1] = "TextEdit";
72
- BulkFileOperationType[BulkFileOperationType["Create"] = 2] = "Create";
73
- BulkFileOperationType[BulkFileOperationType["Delete"] = 4] = "Delete";
74
- BulkFileOperationType[BulkFileOperationType["Rename"] = 8] = "Rename";
75
- })(BulkFileOperationType || (BulkFileOperationType = {}));
76
- class BulkFileOperation {
77
- constructor(uri, parent) {
78
- this.uri = uri;
79
- this.parent = parent;
80
- this.type = 0;
81
- this.textEdits = [];
82
- this.originalEdits = ( new Map());
83
- }
84
- addEdit(index, type, edit) {
85
- this.type |= type;
86
- this.originalEdits.set(index, edit);
87
- if (edit instanceof ResourceTextEdit) {
88
- this.textEdits.push(( new BulkTextEdit(this, edit)));
89
- } else if (type === BulkFileOperationType.Rename) {
90
- this.newUri = edit.newResource;
91
- }
92
- }
93
- needsConfirmation() {
94
- for (const [, edit] of this.originalEdits) {
95
- if (!this.parent.checked.isChecked(edit)) {
96
- return true;
97
- }
98
- }
99
- return false;
100
- }
101
- }
102
- class BulkCategory {
103
- static {
104
- this._defaultMetadata = ( Object.freeze({
105
- label: ( localize(5392, "Other")),
106
- icon: Codicon.symbolFile,
107
- needsConfirmation: false
108
- }));
109
- }
110
- static keyOf(metadata) {
111
- return metadata?.label || "<default>";
112
- }
113
- constructor(metadata = BulkCategory._defaultMetadata) {
114
- this.metadata = metadata;
115
- this.operationByResource = ( new Map());
116
- }
117
- get fileOperations() {
118
- return ( this.operationByResource.values());
119
- }
120
- }
121
- let BulkFileOperations = BulkFileOperations_1 = class BulkFileOperations {
122
- static async create(accessor, bulkEdit) {
123
- const result = accessor.get(IInstantiationService).createInstance(BulkFileOperations_1, bulkEdit);
124
- return await result._init();
125
- }
126
- constructor(_bulkEdit, _fileService, instaService) {
127
- this._bulkEdit = _bulkEdit;
128
- this._fileService = _fileService;
129
- this.checked = ( new CheckedStates());
130
- this.fileOperations = [];
131
- this.categories = [];
132
- this.conflicts = instaService.createInstance(ConflictDetector, _bulkEdit);
133
- }
134
- dispose() {
135
- this.checked.dispose();
136
- this.conflicts.dispose();
137
- }
138
- async _init() {
139
- const operationByResource = ( new Map());
140
- const operationByCategory = ( new Map());
141
- const newToOldUri = ( new ResourceMap());
142
- for (let idx = 0; idx < this._bulkEdit.length; idx++) {
143
- const edit = this._bulkEdit[idx];
144
- let uri;
145
- let type;
146
- this.checked.updateChecked(edit, !edit.metadata?.needsConfirmation);
147
- if (edit instanceof ResourceTextEdit) {
148
- type = BulkFileOperationType.TextEdit;
149
- uri = edit.resource;
150
- } else if (edit instanceof ResourceFileEdit) {
151
- if (edit.newResource && edit.oldResource) {
152
- type = BulkFileOperationType.Rename;
153
- uri = edit.oldResource;
154
- if (edit.options?.overwrite === undefined && edit.options?.ignoreIfExists && (await this._fileService.exists(uri))) {
155
- continue;
156
- }
157
- newToOldUri.set(edit.newResource, uri);
158
- } else if (edit.oldResource) {
159
- type = BulkFileOperationType.Delete;
160
- uri = edit.oldResource;
161
- if (edit.options?.ignoreIfNotExists && !(await this._fileService.exists(uri))) {
162
- continue;
163
- }
164
- } else if (edit.newResource) {
165
- type = BulkFileOperationType.Create;
166
- uri = edit.newResource;
167
- if (edit.options?.overwrite === undefined && edit.options?.ignoreIfExists && (await this._fileService.exists(uri))) {
168
- continue;
169
- }
170
- } else {
171
- continue;
172
- }
173
- } else {
174
- continue;
175
- }
176
- const insert = (uri, map) => {
177
- let key = extUri.getComparisonKey(uri, true);
178
- let operation = map.get(key);
179
- if (!operation && ( newToOldUri.has(uri))) {
180
- uri = newToOldUri.get(uri);
181
- key = extUri.getComparisonKey(uri, true);
182
- operation = map.get(key);
183
- }
184
- if (!operation) {
185
- operation = ( new BulkFileOperation(uri, this));
186
- map.set(key, operation);
187
- }
188
- operation.addEdit(idx, type, edit);
189
- };
190
- insert(uri, operationByResource);
191
- const key = BulkCategory.keyOf(edit.metadata);
192
- let category = operationByCategory.get(key);
193
- if (!category) {
194
- category = ( new BulkCategory(edit.metadata));
195
- operationByCategory.set(key, category);
196
- }
197
- insert(uri, category.operationByResource);
198
- }
199
- operationByResource.forEach(value => this.fileOperations.push(value));
200
- operationByCategory.forEach(value => this.categories.push(value));
201
- for (const file of this.fileOperations) {
202
- if (file.type !== BulkFileOperationType.TextEdit) {
203
- let checked = true;
204
- for (const edit of ( file.originalEdits.values())) {
205
- if (edit instanceof ResourceFileEdit) {
206
- checked = checked && this.checked.isChecked(edit);
207
- }
208
- }
209
- if (!checked) {
210
- for (const edit of ( file.originalEdits.values())) {
211
- this.checked.updateChecked(edit, checked);
212
- }
213
- }
214
- }
215
- }
216
- this.categories.sort((a, b) => {
217
- if (a.metadata.needsConfirmation === b.metadata.needsConfirmation) {
218
- return a.metadata.label.localeCompare(b.metadata.label);
219
- } else if (a.metadata.needsConfirmation) {
220
- return -1;
221
- } else {
222
- return 1;
223
- }
224
- });
225
- return this;
226
- }
227
- getWorkspaceEdit() {
228
- const result = [];
229
- let allAccepted = true;
230
- for (let i = 0; i < this._bulkEdit.length; i++) {
231
- const edit = this._bulkEdit[i];
232
- if (this.checked.isChecked(edit)) {
233
- result[i] = edit;
234
- continue;
235
- }
236
- allAccepted = false;
237
- }
238
- if (allAccepted) {
239
- return this._bulkEdit;
240
- }
241
- coalesceInPlace(result);
242
- return result;
243
- }
244
- async getFileEditOperation(edit) {
245
- const content = await edit.options.contents;
246
- if (!content) {
247
- return undefined;
248
- }
249
- return EditOperation.replaceMove(Range.lift({
250
- startLineNumber: 0,
251
- startColumn: 0,
252
- endLineNumber: Number.MAX_VALUE,
253
- endColumn: 0
254
- }), ( content.toString()));
255
- }
256
- async getFileEdits(uri) {
257
- for (const file of this.fileOperations) {
258
- if (( file.uri.toString()) === ( uri.toString())) {
259
- const result = [];
260
- let ignoreAll = false;
261
- for (const edit of ( file.originalEdits.values())) {
262
- if (edit instanceof ResourceFileEdit) {
263
- result.push(this.getFileEditOperation(edit));
264
- } else if (edit instanceof ResourceTextEdit) {
265
- if (this.checked.isChecked(edit)) {
266
- result.push(Promise.resolve(EditOperation.replaceMove(
267
- Range.lift(edit.textEdit.range),
268
- !edit.textEdit.insertAsSnippet ? edit.textEdit.text : SnippetParser.asInsertText(edit.textEdit.text)
269
- )));
270
- }
271
- } else if (!this.checked.isChecked(edit)) {
272
- ignoreAll = true;
273
- }
274
- }
275
- if (ignoreAll) {
276
- return [];
277
- }
278
- return (await Promise.all(result)).filter(r => r !== undefined).sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range));
279
- }
280
- }
281
- return [];
282
- }
283
- getUriOfEdit(edit) {
284
- for (const file of this.fileOperations) {
285
- for (const value of ( file.originalEdits.values())) {
286
- if (value === edit) {
287
- return file.uri;
288
- }
289
- }
290
- }
291
- throw ( new Error("invalid edit"));
292
- }
293
- };
294
- BulkFileOperations = BulkFileOperations_1 = ( __decorate([( __param(1, IFileService)), ( __param(2, IInstantiationService))], BulkFileOperations));
295
- let BulkEditPreviewProvider = class BulkEditPreviewProvider {
296
- static {
297
- BulkEditPreviewProvider_1 = this;
298
- }
299
- static {
300
- this.Schema = "vscode-bulkeditpreview-editor";
301
- }
302
- static {
303
- this.emptyPreview = ( URI.from({
304
- scheme: this.Schema,
305
- fragment: "empty"
306
- }));
307
- }
308
- static fromPreviewUri(uri) {
309
- return ( URI.parse(uri.query));
310
- }
311
- constructor(_operations, _languageService, _modelService, _textModelResolverService) {
312
- this._operations = _operations;
313
- this._languageService = _languageService;
314
- this._modelService = _modelService;
315
- this._textModelResolverService = _textModelResolverService;
316
- this._disposables = ( new DisposableStore());
317
- this._modelPreviewEdits = ( new Map());
318
- this._instanceId = generateUuid();
319
- this._disposables.add(
320
- this._textModelResolverService.registerTextModelContentProvider(BulkEditPreviewProvider_1.Schema, this)
321
- );
322
- this._ready = this._init();
323
- }
324
- dispose() {
325
- this._disposables.dispose();
326
- }
327
- asPreviewUri(uri) {
328
- const path = uri.scheme === Schemas.untitled ? `/${uri.path}` : uri.path;
329
- return ( URI.from({
330
- scheme: BulkEditPreviewProvider_1.Schema,
331
- authority: this._instanceId,
332
- path,
333
- query: ( uri.toString())
334
- }));
335
- }
336
- async _init() {
337
- for (const operation of this._operations.fileOperations) {
338
- await this._applyTextEditsToPreviewModel(operation.uri);
339
- }
340
- this._disposables.add(
341
- Event.debounce(this._operations.checked.onDidChange, (_last, e) => e, MicrotaskDelay)(e => {
342
- const uri = this._operations.getUriOfEdit(e);
343
- this._applyTextEditsToPreviewModel(uri);
344
- })
345
- );
346
- }
347
- async _applyTextEditsToPreviewModel(uri) {
348
- const model = await this._getOrCreatePreviewModel(uri);
349
- const undoEdits = this._modelPreviewEdits.get(model.id);
350
- if (undoEdits) {
351
- model.applyEdits(undoEdits);
352
- }
353
- const newEdits = await this._operations.getFileEdits(uri);
354
- const newUndoEdits = model.applyEdits(newEdits, true);
355
- this._modelPreviewEdits.set(model.id, newUndoEdits);
356
- }
357
- async _getOrCreatePreviewModel(uri) {
358
- const previewUri = this.asPreviewUri(uri);
359
- let model = this._modelService.getModel(previewUri);
360
- if (!model) {
361
- try {
362
- const ref = await this._textModelResolverService.createModelReference(uri);
363
- const sourceModel = ref.object.textEditorModel;
364
- model = this._modelService.createModel(
365
- createTextBufferFactoryFromSnapshot(sourceModel.createSnapshot()),
366
- this._languageService.createById(sourceModel.getLanguageId()),
367
- previewUri
368
- );
369
- ref.dispose();
370
- } catch {
371
- model = this._modelService.createModel(
372
- "",
373
- this._languageService.createByFilepathOrFirstLine(previewUri),
374
- previewUri
375
- );
376
- }
377
- queueMicrotask(async () => {
378
- this._disposables.add(await this._textModelResolverService.createModelReference(model.uri));
379
- });
380
- }
381
- return model;
382
- }
383
- async provideTextContent(previewUri) {
384
- if (( previewUri.toString()) === ( BulkEditPreviewProvider_1.emptyPreview.toString())) {
385
- return this._modelService.createModel("", null, previewUri);
386
- }
387
- await this._ready;
388
- return this._modelService.getModel(previewUri);
389
- }
390
- };
391
- BulkEditPreviewProvider = BulkEditPreviewProvider_1 = ( __decorate([( __param(1, ILanguageService)), ( __param(2, IModelService)), ( __param(3, ITextModelService))], BulkEditPreviewProvider));
392
-
393
- export { BulkCategory, BulkEditPreviewProvider, BulkFileOperation, BulkFileOperationType, BulkFileOperations, BulkTextEdit, CheckedStates };
@@ -1,132 +0,0 @@
1
- import { IAsyncDataSource, ITreeRenderer, ITreeNode, ITreeSorter } from "@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/tree/tree";
2
- import { ITextModelService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService.service";
3
- import { FuzzyScore } from "@codingame/monaco-vscode-api/vscode/vs/base/common/filters";
4
- import { ResourceLabels } from "@codingame/monaco-vscode-api/vscode/vs/workbench/browser/labels";
5
- import { IIdentityProvider, IListVirtualDelegate, IKeyboardNavigationLabelProvider } from "@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/list/list";
6
- import { BulkFileOperations, BulkFileOperation, BulkTextEdit, BulkCategory } from "./bulkEditPreview.js";
7
- import { ILabelService } from "@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service";
8
- import type { IListAccessibilityProvider } from "@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/list/listWidget";
9
- import { IconLabel } from "@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/iconLabel/iconLabel";
10
- import { IThemeService } from "@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService.service";
11
- import { AriaRole } from "@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/aria/aria";
12
- import { IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
13
- export interface ICheckable {
14
- isChecked(): boolean;
15
- setChecked(value: boolean): void;
16
- }
17
- export declare class CategoryElement implements ICheckable {
18
- readonly parent: BulkFileOperations;
19
- readonly category: BulkCategory;
20
- constructor(parent: BulkFileOperations, category: BulkCategory);
21
- isChecked(): boolean;
22
- setChecked(value: boolean): void;
23
- }
24
- export declare class FileElement implements ICheckable {
25
- readonly parent: CategoryElement | BulkFileOperations;
26
- readonly edit: BulkFileOperation;
27
- constructor(parent: CategoryElement | BulkFileOperations, edit: BulkFileOperation);
28
- isChecked(): boolean;
29
- setChecked(value: boolean): void;
30
- isDisabled(): boolean;
31
- }
32
- export declare class TextEditElement implements ICheckable {
33
- readonly parent: FileElement;
34
- readonly idx: number;
35
- readonly edit: BulkTextEdit;
36
- readonly prefix: string;
37
- readonly selecting: string;
38
- readonly inserting: string;
39
- readonly suffix: string;
40
- constructor(parent: FileElement, idx: number, edit: BulkTextEdit, prefix: string, selecting: string, inserting: string, suffix: string);
41
- isChecked(): boolean;
42
- setChecked(value: boolean): void;
43
- isDisabled(): boolean;
44
- }
45
- export type BulkEditElement = CategoryElement | FileElement | TextEditElement;
46
- export declare class BulkEditDataSource implements IAsyncDataSource<BulkFileOperations, BulkEditElement> {
47
- private readonly _textModelService;
48
- private readonly _instantiationService;
49
- groupByFile: boolean;
50
- constructor(_textModelService: ITextModelService, _instantiationService: IInstantiationService);
51
- hasChildren(element: BulkFileOperations | BulkEditElement): boolean;
52
- getChildren(element: BulkFileOperations | BulkEditElement): Promise<BulkEditElement[]>;
53
- }
54
- export declare class BulkEditSorter implements ITreeSorter<BulkEditElement> {
55
- compare(a: BulkEditElement, b: BulkEditElement): number;
56
- }
57
- export declare function compareBulkFileOperations(a: BulkFileOperation, b: BulkFileOperation): number;
58
- export declare class BulkEditAccessibilityProvider implements IListAccessibilityProvider<BulkEditElement> {
59
- private readonly _labelService;
60
- constructor(_labelService: ILabelService);
61
- getWidgetAriaLabel(): string;
62
- getRole(_element: BulkEditElement): AriaRole;
63
- getAriaLabel(element: BulkEditElement): string | null;
64
- }
65
- export declare class BulkEditIdentityProvider implements IIdentityProvider<BulkEditElement> {
66
- getId(element: BulkEditElement): {
67
- toString(): string;
68
- };
69
- }
70
- declare class CategoryElementTemplate {
71
- readonly icon: HTMLDivElement;
72
- readonly label: IconLabel;
73
- constructor(container: HTMLElement);
74
- }
75
- export declare class CategoryElementRenderer implements ITreeRenderer<CategoryElement, FuzzyScore, CategoryElementTemplate> {
76
- private readonly _themeService;
77
- static readonly id: string;
78
- readonly templateId: string;
79
- constructor(_themeService: IThemeService);
80
- renderTemplate(container: HTMLElement): CategoryElementTemplate;
81
- renderElement(node: ITreeNode<CategoryElement, FuzzyScore>, _index: number, template: CategoryElementTemplate): void;
82
- disposeTemplate(template: CategoryElementTemplate): void;
83
- }
84
- declare class FileElementTemplate {
85
- private readonly _labelService;
86
- private readonly _disposables;
87
- private readonly _localDisposables;
88
- private readonly _checkbox;
89
- private readonly _label;
90
- private readonly _details;
91
- constructor(container: HTMLElement, resourceLabels: ResourceLabels, _labelService: ILabelService);
92
- dispose(): void;
93
- set(element: FileElement, score: FuzzyScore | undefined): void;
94
- }
95
- export declare class FileElementRenderer implements ITreeRenderer<FileElement, FuzzyScore, FileElementTemplate> {
96
- private readonly _resourceLabels;
97
- private readonly _labelService;
98
- static readonly id: string;
99
- readonly templateId: string;
100
- constructor(_resourceLabels: ResourceLabels, _labelService: ILabelService);
101
- renderTemplate(container: HTMLElement): FileElementTemplate;
102
- renderElement(node: ITreeNode<FileElement, FuzzyScore>, _index: number, template: FileElementTemplate): void;
103
- disposeTemplate(template: FileElementTemplate): void;
104
- }
105
- declare class TextEditElementTemplate {
106
- private readonly _themeService;
107
- private readonly _disposables;
108
- private readonly _localDisposables;
109
- private readonly _checkbox;
110
- private readonly _icon;
111
- private readonly _label;
112
- constructor(container: HTMLElement, _themeService: IThemeService);
113
- dispose(): void;
114
- set(element: TextEditElement): void;
115
- }
116
- export declare class TextEditElementRenderer implements ITreeRenderer<TextEditElement, FuzzyScore, TextEditElementTemplate> {
117
- private readonly _themeService;
118
- static readonly id = "TextEditElementRenderer";
119
- readonly templateId: string;
120
- constructor(_themeService: IThemeService);
121
- renderTemplate(container: HTMLElement): TextEditElementTemplate;
122
- renderElement({ element }: ITreeNode<TextEditElement, FuzzyScore>, _index: number, template: TextEditElementTemplate): void;
123
- disposeTemplate(template: TextEditElementTemplate): void;
124
- }
125
- export declare class BulkEditDelegate implements IListVirtualDelegate<BulkEditElement> {
126
- getHeight(): number;
127
- getTemplateId(element: BulkEditElement): string;
128
- }
129
- export declare class BulkEditNaviLabelProvider implements IKeyboardNavigationLabelProvider<BulkEditElement> {
130
- getKeyboardNavigationLabel(element: BulkEditElement): string | undefined;
131
- }
132
- export {};