@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,391 +0,0 @@
1
-
2
- import { registerCss } from '@codingame/monaco-vscode-api/css';
3
- import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
4
- import { ButtonBar } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/button/button';
5
- import { LRUCachedFunction, CachedFunction } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cache';
6
- import { DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
7
- import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
8
- import * as bulkEdit from './bulkEdit.css';
9
- import { ITextModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService.service';
10
- import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
11
- import { MenuId } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions';
12
- import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
13
- import { RawContextKey } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey';
14
- import { IContextKeyService } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey.service';
15
- import { IContextMenuService } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextview/browser/contextView.service';
16
- import { IDialogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/dialogs/common/dialogs.service';
17
- import { IHoverService } from '@codingame/monaco-vscode-api/vscode/vs/platform/hover/browser/hover.service';
18
- import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
19
- import { IKeybindingService } from '@codingame/monaco-vscode-api/vscode/vs/platform/keybinding/common/keybinding.service';
20
- import { ILabelService } from '@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service';
21
- import { WorkbenchAsyncDataTree } from '@codingame/monaco-vscode-api/vscode/vs/platform/list/browser/listService';
22
- import { IOpenerService } from '@codingame/monaco-vscode-api/vscode/vs/platform/opener/common/opener.service';
23
- import { StorageScope, StorageTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
24
- import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
25
- import { defaultButtonStyles } from '@codingame/monaco-vscode-api/vscode/vs/platform/theme/browser/defaultStyles';
26
- import { IThemeService } from '@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService.service';
27
- import { ResourceLabels } from '@codingame/monaco-vscode-api/vscode/vs/workbench/browser/labels';
28
- import { ViewPane } from '@codingame/monaco-vscode-api/vscode/vs/workbench/browser/parts/views/viewPane';
29
- import { IViewDescriptorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/views.service';
30
- import { BulkFileOperationType, BulkEditPreviewProvider, BulkFileOperations } from './bulkEditPreview.js';
31
- import { compareBulkFileOperations, BulkEditDataSource, BulkEditDelegate, TextEditElementRenderer, FileElementRenderer, CategoryElementRenderer, BulkEditSorter, BulkEditNaviLabelProvider, BulkEditIdentityProvider, BulkEditAccessibilityProvider, FileElement, CategoryElement, TextEditElement } from './bulkEditTree.js';
32
- import { SIDE_GROUP, ACTIVE_GROUP } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService';
33
- import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
34
- import { createElement } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/dom';
35
-
36
- var BulkEditPane_1;
37
- registerCss(bulkEdit);
38
- var State;
39
- (function(State) {
40
- State["Data"] = "data";
41
- State["Message"] = "message";
42
- })(State || (State = {}));
43
- let BulkEditPane = class BulkEditPane extends ViewPane {
44
- static {
45
- BulkEditPane_1 = this;
46
- }
47
- static {
48
- this.ID = "refactorPreview";
49
- }
50
- static {
51
- this.Schema = "vscode-bulkeditpreview-multieditor";
52
- }
53
- static {
54
- this.ctxHasCategories = ( new RawContextKey("refactorPreview.hasCategories", false));
55
- }
56
- static {
57
- this.ctxGroupByFile = ( new RawContextKey("refactorPreview.groupByFile", true));
58
- }
59
- static {
60
- this.ctxHasCheckedChanges = ( new RawContextKey("refactorPreview.hasCheckedChanges", true));
61
- }
62
- static {
63
- this._memGroupByFile = `${this.ID}.groupByFile`;
64
- }
65
- constructor(
66
- options,
67
- _instaService,
68
- _editorService,
69
- _labelService,
70
- _textModelService,
71
- _dialogService,
72
- _contextMenuService,
73
- _storageService,
74
- contextKeyService,
75
- viewDescriptorService,
76
- keybindingService,
77
- contextMenuService,
78
- configurationService,
79
- openerService,
80
- themeService,
81
- hoverService
82
- ) {
83
- super({
84
- ...options,
85
- titleMenuId: MenuId.BulkEditTitle
86
- }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, _instaService, openerService, themeService, hoverService);
87
- this._instaService = _instaService;
88
- this._editorService = _editorService;
89
- this._labelService = _labelService;
90
- this._textModelService = _textModelService;
91
- this._dialogService = _dialogService;
92
- this._contextMenuService = _contextMenuService;
93
- this._storageService = _storageService;
94
- this._treeViewStates = ( new Map());
95
- this._disposables = ( new DisposableStore());
96
- this._sessionDisposables = ( new DisposableStore());
97
- this._computeResourceDiffEditorInputs = ( new LRUCachedFunction(async fileOperations => {
98
- const computeDiffEditorInput = ( new CachedFunction(async fileOperation => {
99
- const fileOperationUri = fileOperation.uri;
100
- const previewUri = this._currentProvider.asPreviewUri(fileOperationUri);
101
- if (fileOperation.type & BulkFileOperationType.Delete) {
102
- return {
103
- original: {
104
- resource: URI.revive(previewUri)
105
- },
106
- modified: {
107
- resource: undefined
108
- },
109
- goToFileResource: fileOperation.uri
110
- };
111
- }
112
- else {
113
- let leftResource;
114
- try {
115
- (await this._textModelService.createModelReference(fileOperationUri)).dispose();
116
- leftResource = fileOperationUri;
117
- } catch {
118
- leftResource = BulkEditPreviewProvider.emptyPreview;
119
- }
120
- return {
121
- original: {
122
- resource: URI.revive(leftResource)
123
- },
124
- modified: {
125
- resource: URI.revive(previewUri)
126
- },
127
- goToFileResource: leftResource
128
- };
129
- }
130
- }));
131
- const sortedFileOperations = fileOperations.slice().sort(compareBulkFileOperations);
132
- const resources = [];
133
- for (const operation of sortedFileOperations) {
134
- resources.push(await computeDiffEditorInput.get(operation));
135
- }
136
- const getResourceDiffEditorInputIdOfOperation = async operation => {
137
- const resource = await computeDiffEditorInput.get(operation);
138
- return {
139
- original: resource.original.resource,
140
- modified: resource.modified.resource
141
- };
142
- };
143
- return {
144
- resources,
145
- getResourceDiffEditorInputIdOfOperation
146
- };
147
- }));
148
- this.element.classList.add("bulk-edit-panel", "show-file-icons");
149
- this._ctxHasCategories = BulkEditPane_1.ctxHasCategories.bindTo(contextKeyService);
150
- this._ctxGroupByFile = BulkEditPane_1.ctxGroupByFile.bindTo(contextKeyService);
151
- this._ctxHasCheckedChanges = BulkEditPane_1.ctxHasCheckedChanges.bindTo(contextKeyService);
152
- }
153
- dispose() {
154
- this._tree.dispose();
155
- this._disposables.dispose();
156
- this._sessionDisposables.dispose();
157
- super.dispose();
158
- }
159
- renderBody(parent) {
160
- super.renderBody(parent);
161
- const resourceLabels = this._instaService.createInstance(ResourceLabels, {
162
- onDidChangeVisibility: this.onDidChangeBodyVisibility
163
- });
164
- this._disposables.add(resourceLabels);
165
- const contentContainer = createElement("div");
166
- contentContainer.className = "content";
167
- parent.appendChild(contentContainer);
168
- const treeContainer = createElement("div");
169
- contentContainer.appendChild(treeContainer);
170
- this._treeDataSource = this._instaService.createInstance(BulkEditDataSource);
171
- this._treeDataSource.groupByFile = this._storageService.getBoolean(BulkEditPane_1._memGroupByFile, StorageScope.PROFILE, true);
172
- this._ctxGroupByFile.set(this._treeDataSource.groupByFile);
173
- this._tree = this._instaService.createInstance(WorkbenchAsyncDataTree, this.id, treeContainer, ( new BulkEditDelegate()), [
174
- this._instaService.createInstance(TextEditElementRenderer),
175
- this._instaService.createInstance(FileElementRenderer, resourceLabels),
176
- this._instaService.createInstance(CategoryElementRenderer)
177
- ], this._treeDataSource, {
178
- accessibilityProvider: this._instaService.createInstance(BulkEditAccessibilityProvider),
179
- identityProvider: ( new BulkEditIdentityProvider()),
180
- expandOnlyOnTwistieClick: true,
181
- multipleSelectionSupport: false,
182
- keyboardNavigationLabelProvider: ( new BulkEditNaviLabelProvider()),
183
- sorter: ( new BulkEditSorter()),
184
- selectionNavigation: true
185
- });
186
- this._disposables.add(this._tree.onContextMenu(this._onContextMenu, this));
187
- this._disposables.add(this._tree.onDidOpen(e => this._openElementInMultiDiffEditor(e)));
188
- const buttonsContainer = createElement("div");
189
- buttonsContainer.className = "buttons";
190
- contentContainer.appendChild(buttonsContainer);
191
- const buttonBar = ( new ButtonBar(buttonsContainer));
192
- this._disposables.add(buttonBar);
193
- const btnConfirm = buttonBar.addButton({
194
- supportIcons: true,
195
- ...defaultButtonStyles
196
- });
197
- btnConfirm.label = ( localize(5387, "Apply"));
198
- btnConfirm.onDidClick(() => this.accept(), this, this._disposables);
199
- const btnCancel = buttonBar.addButton({
200
- ...defaultButtonStyles,
201
- secondary: true
202
- });
203
- btnCancel.label = ( localize(5388, "Discard"));
204
- btnCancel.onDidClick(() => this.discard(), this, this._disposables);
205
- this._message = createElement("span");
206
- this._message.className = "message";
207
- this._message.innerText = ( localize(
208
- 5389,
209
- "Invoke a code action, like rename, to see a preview of its changes here."
210
- ));
211
- parent.appendChild(this._message);
212
- this._setState(State.Message);
213
- }
214
- layoutBody(height, width) {
215
- super.layoutBody(height, width);
216
- const treeHeight = height - 50;
217
- this._tree.getHTMLElement().parentElement.style.height = `${treeHeight}px`;
218
- this._tree.layout(treeHeight, width);
219
- }
220
- _setState(state) {
221
- this.element.dataset["state"] = state;
222
- }
223
- async setInput(edit, token) {
224
- this._setState(State.Data);
225
- this._sessionDisposables.clear();
226
- this._treeViewStates.clear();
227
- if (this._currentResolve) {
228
- this._currentResolve(undefined);
229
- this._currentResolve = undefined;
230
- }
231
- const input = await this._instaService.invokeFunction(BulkFileOperations.create, edit);
232
- this._currentProvider = this._instaService.createInstance(BulkEditPreviewProvider, input);
233
- this._sessionDisposables.add(this._currentProvider);
234
- this._sessionDisposables.add(input);
235
- const hasCategories = input.categories.length > 1;
236
- this._ctxHasCategories.set(hasCategories);
237
- this._treeDataSource.groupByFile = !hasCategories || this._treeDataSource.groupByFile;
238
- this._ctxHasCheckedChanges.set(input.checked.checkedCount > 0);
239
- this._currentInput = input;
240
- return ( new Promise(resolve => {
241
- token.onCancellationRequested(() => resolve(undefined));
242
- this._currentResolve = resolve;
243
- this._setTreeInput(input);
244
- this._sessionDisposables.add(input.checked.onDidChange(() => {
245
- this._tree.updateChildren();
246
- this._ctxHasCheckedChanges.set(input.checked.checkedCount > 0);
247
- }));
248
- }));
249
- }
250
- hasInput() {
251
- return Boolean(this._currentInput);
252
- }
253
- async _setTreeInput(input) {
254
- const viewState = this._treeViewStates.get(this._treeDataSource.groupByFile);
255
- await this._tree.setInput(input, viewState);
256
- this._tree.domFocus();
257
- if (viewState) {
258
- return;
259
- }
260
- const expand = [...this._tree.getNode(input).children].slice(0, 10);
261
- while (expand.length > 0) {
262
- const {
263
- element
264
- } = expand.shift();
265
- if (element instanceof FileElement) {
266
- await this._tree.expand(element, true);
267
- }
268
- if (element instanceof CategoryElement) {
269
- await this._tree.expand(element, true);
270
- expand.push(...this._tree.getNode(element).children);
271
- }
272
- }
273
- }
274
- accept() {
275
- const conflicts = this._currentInput?.conflicts.list();
276
- if (!conflicts || conflicts.length === 0) {
277
- this._done(true);
278
- return;
279
- }
280
- let message;
281
- if (conflicts.length === 1) {
282
- message = ( localize(
283
- 5390,
284
- "Cannot apply refactoring because '{0}' has changed in the meantime.",
285
- this._labelService.getUriLabel(conflicts[0], {
286
- relative: true
287
- })
288
- ));
289
- } else {
290
- message = ( localize(
291
- 5391,
292
- "Cannot apply refactoring because {0} other files have changed in the meantime.",
293
- conflicts.length
294
- ));
295
- }
296
- this._dialogService.warn(message).finally(() => this._done(false));
297
- }
298
- discard() {
299
- this._done(false);
300
- }
301
- _done(accept) {
302
- this._currentResolve?.(accept ? this._currentInput?.getWorkspaceEdit() : undefined);
303
- this._currentInput = undefined;
304
- this._setState(State.Message);
305
- this._sessionDisposables.clear();
306
- }
307
- toggleChecked() {
308
- const [first] = this._tree.getFocus();
309
- if ((first instanceof FileElement || first instanceof TextEditElement) && !first.isDisabled()) {
310
- first.setChecked(!first.isChecked());
311
- } else if (first instanceof CategoryElement) {
312
- first.setChecked(!first.isChecked());
313
- }
314
- }
315
- groupByFile() {
316
- if (!this._treeDataSource.groupByFile) {
317
- this.toggleGrouping();
318
- }
319
- }
320
- groupByType() {
321
- if (this._treeDataSource.groupByFile) {
322
- this.toggleGrouping();
323
- }
324
- }
325
- toggleGrouping() {
326
- const input = this._tree.getInput();
327
- if (input) {
328
- const oldViewState = this._tree.getViewState();
329
- this._treeViewStates.set(this._treeDataSource.groupByFile, oldViewState);
330
- this._treeDataSource.groupByFile = !this._treeDataSource.groupByFile;
331
- this._setTreeInput(input);
332
- this._storageService.store(
333
- BulkEditPane_1._memGroupByFile,
334
- this._treeDataSource.groupByFile,
335
- StorageScope.PROFILE,
336
- StorageTarget.USER
337
- );
338
- this._ctxGroupByFile.set(this._treeDataSource.groupByFile);
339
- }
340
- }
341
- async _openElementInMultiDiffEditor(e) {
342
- const fileOperations = this._currentInput?.fileOperations;
343
- if (!fileOperations) {
344
- return;
345
- }
346
- let selection = undefined;
347
- let fileElement;
348
- if (e.element instanceof TextEditElement) {
349
- fileElement = e.element.parent;
350
- selection = e.element.edit.textEdit.textEdit.range;
351
- } else if (e.element instanceof FileElement) {
352
- fileElement = e.element;
353
- selection = e.element.edit.textEdits[0]?.textEdit.textEdit.range;
354
- } else {
355
- return;
356
- }
357
- const result = await this._computeResourceDiffEditorInputs.get(fileOperations);
358
- const resourceId = await result.getResourceDiffEditorInputIdOfOperation(fileElement.edit);
359
- const options = {
360
- ...e.editorOptions,
361
- viewState: {
362
- revealData: {
363
- resource: resourceId,
364
- range: selection
365
- }
366
- }
367
- };
368
- const multiDiffSource = ( URI.from({
369
- scheme: BulkEditPane_1.Schema
370
- }));
371
- const label = "Refactor Preview";
372
- this._editorService.openEditor({
373
- multiDiffSource,
374
- label,
375
- options,
376
- isTransient: true,
377
- description: label,
378
- resources: result.resources
379
- }, e.sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
380
- }
381
- _onContextMenu(e) {
382
- this._contextMenuService.showContextMenu({
383
- menuId: MenuId.BulkEditContext,
384
- contextKeyService: this.contextKeyService,
385
- getAnchor: () => e.anchor
386
- });
387
- }
388
- };
389
- BulkEditPane = BulkEditPane_1 = ( __decorate([( __param(1, IInstantiationService)), ( __param(2, IEditorService)), ( __param(3, ILabelService)), ( __param(4, ITextModelService)), ( __param(5, IDialogService)), ( __param(6, IContextMenuService)), ( __param(7, IStorageService)), ( __param(8, IContextKeyService)), ( __param(9, IViewDescriptorService)), ( __param(10, IKeybindingService)), ( __param(11, IContextMenuService)), ( __param(12, IConfigurationService)), ( __param(13, IOpenerService)), ( __param(14, IThemeService)), ( __param(15, IHoverService))], BulkEditPane));
390
-
391
- export { BulkEditPane };
@@ -1,88 +0,0 @@
1
- import { ITextModelContentProvider } from "@codingame/monaco-vscode-model-service-override/vscode/vs/editor/common/services/resolverService";
2
- import { ITextModelService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService.service";
3
- import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri";
4
- import { ILanguageService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service";
5
- import { IModelService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service";
6
- import { WorkspaceEditMetadata } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/languages";
7
- import { ISingleEditOperation } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/editOperation";
8
- import { ServicesAccessor, IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
9
- import { IFileService } from "@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service";
10
- import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event";
11
- import { ConflictDetector } from "../conflicts.js";
12
- import { ResourceEdit, ResourceFileEdit, ResourceTextEdit } from "@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService";
13
- export declare class CheckedStates<T extends object> {
14
- private readonly _states;
15
- private _checkedCount;
16
- private readonly _onDidChange;
17
- readonly onDidChange: Event<T>;
18
- dispose(): void;
19
- get checkedCount(): number;
20
- isChecked(obj: T): boolean;
21
- updateChecked(obj: T, value: boolean): void;
22
- }
23
- export declare class BulkTextEdit {
24
- readonly parent: BulkFileOperation;
25
- readonly textEdit: ResourceTextEdit;
26
- constructor(parent: BulkFileOperation, textEdit: ResourceTextEdit);
27
- }
28
- export declare enum BulkFileOperationType {
29
- TextEdit = 1,
30
- Create = 2,
31
- Delete = 4,
32
- Rename = 8
33
- }
34
- export declare class BulkFileOperation {
35
- readonly uri: URI;
36
- readonly parent: BulkFileOperations;
37
- type: number;
38
- textEdits: BulkTextEdit[];
39
- originalEdits: Map<number, ResourceFileEdit | ResourceTextEdit>;
40
- newUri?: URI;
41
- constructor(uri: URI, parent: BulkFileOperations);
42
- addEdit(index: number, type: BulkFileOperationType, edit: ResourceTextEdit | ResourceFileEdit): void;
43
- needsConfirmation(): boolean;
44
- }
45
- export declare class BulkCategory {
46
- readonly metadata: WorkspaceEditMetadata;
47
- private static readonly _defaultMetadata;
48
- static keyOf(metadata?: WorkspaceEditMetadata): string;
49
- readonly operationByResource: Map<string, BulkFileOperation>;
50
- constructor(metadata?: WorkspaceEditMetadata);
51
- get fileOperations(): IterableIterator<BulkFileOperation>;
52
- }
53
- export declare class BulkFileOperations {
54
- private readonly _bulkEdit;
55
- private readonly _fileService;
56
- static create(accessor: ServicesAccessor, bulkEdit: ResourceEdit[]): Promise<BulkFileOperations>;
57
- readonly checked: CheckedStates<ResourceEdit>;
58
- readonly fileOperations: BulkFileOperation[];
59
- readonly categories: BulkCategory[];
60
- readonly conflicts: ConflictDetector;
61
- constructor(_bulkEdit: ResourceEdit[], _fileService: IFileService, instaService: IInstantiationService);
62
- dispose(): void;
63
- _init(): Promise<this>;
64
- getWorkspaceEdit(): ResourceEdit[];
65
- private getFileEditOperation;
66
- getFileEdits(uri: URI): Promise<ISingleEditOperation[]>;
67
- getUriOfEdit(edit: ResourceEdit): URI;
68
- }
69
- export declare class BulkEditPreviewProvider implements ITextModelContentProvider {
70
- private readonly _operations;
71
- private readonly _languageService;
72
- private readonly _modelService;
73
- private readonly _textModelResolverService;
74
- private static readonly Schema;
75
- static emptyPreview: URI;
76
- static fromPreviewUri(uri: URI): URI;
77
- private readonly _disposables;
78
- private readonly _ready;
79
- private readonly _modelPreviewEdits;
80
- private readonly _instanceId;
81
- constructor(_operations: BulkFileOperations, _languageService: ILanguageService, _modelService: IModelService, _textModelResolverService: ITextModelService);
82
- dispose(): void;
83
- asPreviewUri(uri: URI): URI;
84
- private _init;
85
- private _applyTextEditsToPreviewModel;
86
- private _getOrCreatePreviewModel;
87
- provideTextContent(previewUri: URI): Promise<import("@codingame/monaco-vscode-api/vscode/vs/editor/common/model").ITextModel | null>;
88
- }