undoRedoService.ts ×83

Frontier kind: Code frontier

unlabeled · c_7ceed7309bcf

666 tests · 7361 LOC · 40 files · introduces 0 tests · 299 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
91 ranges299 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
924 ranges7361 lines · 40 files · Browse complete extent
All tests (intent)
666 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 299 introduced LOC across 91 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/undoRedo/common/undoRedoService.ts 266 introduced LOC · 83 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- undoRedoService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { onUnexpectedError } from '../../../base/common/errors.js';
7 > import { Disposable, IDisposable, isDisposable } from '../../../base/common/lifecycle.js';
8 > import { Schemas } from '../../../base/common/network.js';
9 > import Severity from '../../../base/common/severity.js';
10 > import { URI } from '../../../base/common/uri.js';
11 > import * as nls from '../../../nls.js';
12 > import { IDialogService } from '../../dialogs/common/dialogs.js';
13 > import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js';
14 > import { INotificationService } from '../../notification/common/notification.js';
15 > import { IPastFutureElements, IResourceUndoRedoElement, IUndoRedoElement, IUndoRedoService, IWorkspaceUndoRedoElement, ResourceEditStackSnapshot, UndoRedoElementType, UndoRedoGroup, UndoRedoSource, UriComparisonKeyComputer } from './undoRedo.js';
16 >
17 > const DEBUG = false;
18 >
19 function getResourceLabel(resource: URI): string {
20 return resource.scheme === Schemas.file ? resource.fsPath : resource.path;
21 }
23 > let stackElementCounter = 0;
24 >
25 > class ResourceStackElement {
26 > public readonly id = (++stackElementCounter);
27 > public readonly type = UndoRedoElementType.Resource;
28 > public readonly actual: IUndoRedoElement;
29 > public readonly label: string;
30 > public readonly confirmBeforeUndo: boolean;
31 >
32 > public readonly resourceLabel: string;
33 > public readonly strResource: string;
34 > public readonly resourceLabels: string[];
35 > public readonly strResources: string[];
36 > public readonly groupId: number;
37 > public readonly groupOrder: number;
38 > public readonly sourceId: number;
39 > public readonly sourceOrder: number;
40 > public isValid: boolean;
41 >
42 > constructor(actual: IUndoRedoElement, resourceLabel: string, strResource: string, groupId: number, groupOrder: number, sourceId: number, sourceOrder: number) {
43 this.actual = actual;
44 this.label = actual.label;
54 this.isValid = true;
55 }
57 > public setValid(isValid: boolean): void {
58 this.isValid = isValid;
59 }
61 > public toString(): string {
62 return `[id:${this.id}] [group:${this.groupId}] [${this.isValid ? ' VALID' : 'INVALID'}] ${this.actual.constructor.name} - ${this.actual}`;
63 }
65 >
66 > const enum RemovedResourceReason {
67 > ExternalRemoval = 0,
68 > NoParallelUniverses = 1
69 > }
70 >
71 > class ResourceReasonPair {
72 > constructor(
73 public readonly resourceLabel: string,
74 public readonly reason: RemovedResourceReason
75 ) { }
77 >
78 class RemovedResources {
79 private readonly elements = new Map<string, ResourceReasonPair>();
81 > public createMessage(): string {
82 const externalRemoval: string[] = [];
83 const noParallelUniverses: string[] = [];
109 return messages.join('\n');
110 }
112 > public get size(): number {
113 return this.elements.size;
114 }
116 > public has(strResource: string): boolean {
117 return this.elements.has(strResource);
118 }
120 > public set(strResource: string, value: ResourceReasonPair): void {
121 this.elements.set(strResource, value);
122 }
124 > public delete(strResource: string): boolean {
125 return this.elements.delete(strResource);
126 }
128 >
129 > class WorkspaceStackElement {
130 > public readonly id = (++stackElementCounter);
131 > public readonly type = UndoRedoElementType.Workspace;
132 > public readonly actual: IWorkspaceUndoRedoElement;
133 > public readonly label: string;
134 > public readonly confirmBeforeUndo: boolean;
135 >
136 > public readonly resourceLabels: string[];
137 > public readonly strResources: string[];
138 > public readonly groupId: number;
139 > public readonly groupOrder: number;
140 > public readonly sourceId: number;
141 > public readonly sourceOrder: number;
142 > public removedResources: RemovedResources | null;
143 > public invalidatedResources: RemovedResources | null;
144 >
145 > constructor(actual: IWorkspaceUndoRedoElement, resourceLabels: string[], strResources: string[], groupId: number, groupOrder: number, sourceId: number, sourceOrder: number) {
146 this.actual = actual;
147 this.label = actual.label;
156 this.invalidatedResources = null;
157 }
159 > public canSplit(): this is WorkspaceStackElement & { actual: { split(): IResourceUndoRedoElement[] } } {
160 return (typeof this.actual.split === 'function');
161 }
163 > public removeResource(resourceLabel: string, strResource: string, reason: RemovedResourceReason): void {
164 if (!this.removedResources) {
165 this.removedResources = new RemovedResources();
169 }
170 }
172 > public setValid(resourceLabel: string, strResource: string, isValid: boolean): void {
173 if (isValid) {
174 if (this.invalidatedResources) {
187 }
188 }
190 > public toString(): string {
191 return `[id:${this.id}] [group:${this.groupId}] [${this.invalidatedResources ? 'INVALID' : ' VALID'}] ${this.actual.constructor.name} - ${this.actual}`;
192 }
194 >
195 > type StackElement = ResourceStackElement | WorkspaceStackElement;
196 >
197 > class ResourceEditStack {
198 > public readonly resourceLabel: string;
199 > private readonly strResource: string;
200 > private _past: StackElement[];
201 > private _future: StackElement[];
202 > public locked: boolean;
203 > public versionId: number;
204 >
205 > constructor(resourceLabel: string, strResource: string) {
206 > this.resourceLabel = resourceLabel;
207 > this.strResource = strResource;
208 > this._past = [];
209 > this._future = [];
210 > this.locked = false;
211 > this.versionId = 1;
212 > }
213 >
214 > public dispose(): void {
215 for (const element of this._past) {
216 if (element.type === UndoRedoElementType.Workspace) {
225 this.versionId++;
226 }
228 > public toString(): string {
229 const result: string[] = [];
230 result.push(`* ${this.strResource}:`);
237 return result.join('\n');
238 }
240 > public flushAllElements(): void {
241 this._past = [];
242 this._future = [];
243 this.versionId++;
244 }
246 > public setElementsIsValid(isValid: boolean): void {
247 for (const element of this._past) {
248 if (element.type === UndoRedoElementType.Workspace) {
260 }
261 }
263 > private _setElementValidFlag(element: StackElement, isValid: boolean): void {
264 if (element.type === UndoRedoElementType.Workspace) {
265 element.setValid(this.resourceLabel, this.strResource, isValid);
268 }
269 }
271 > public setElementsValidFlag(isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void {
272 for (const element of this._past) {
273 if (filter(element.actual)) {
281 }
282 }
284 > public pushElement(element: StackElement): void {
285 // remove the future
286 for (const futureElement of this._future) {
293 this.versionId++;
294 }
296 > public createSnapshot(resource: URI): ResourceEditStackSnapshot {
297 const elements: number[] = [];
298
306 return new ResourceEditStackSnapshot(resource, elements);
307 }
309 > public restoreSnapshot(snapshot: ResourceEditStackSnapshot): void {
310 const snapshotLength = snapshot.elements.length;
311 let isOK = true;
341 this.versionId++;
342 }
344 > public getElements(): IPastFutureElements {
345 const past: IUndoRedoElement[] = [];
346 const future: IUndoRedoElement[] = [];
355 return { past, future };
356 }
358 > public getClosestPastElement(): StackElement | null {
359 if (this._past.length === 0) {
360 return null;
362 return this._past[this._past.length - 1];
363 }
365 > public getSecondClosestPastElement(): StackElement | null {
366 if (this._past.length < 2) {
367 return null;
369 return this._past[this._past.length - 2];
370 }
372 > public getClosestFutureElement(): StackElement | null {
373 if (this._future.length === 0) {
374 return null;
376 return this._future[this._future.length - 1];
377 }
379 > public hasPastElements(): boolean {
380 return (this._past.length > 0);
381 }
383 > public hasFutureElements(): boolean {
384 return (this._future.length > 0);
385 }
387 > public splitPastWorkspaceElement(toRemove: WorkspaceStackElement, individualMap: Map<string, ResourceStackElement>): void {
388 for (let j = this._past.length - 1; j >= 0; j--) {
389 if (this._past[j] === toRemove) {
400 this.versionId++;
401 }
403 > public splitFutureWorkspaceElement(toRemove: WorkspaceStackElement, individualMap: Map<string, ResourceStackElement>): void {
404 for (let j = this._future.length - 1; j >= 0; j--) {
405 if (this._future[j] === toRemove) {
416 this.versionId++;
417 }
419 > public moveBackward(element: StackElement): void {
420 this._past.pop();
421 this._future.push(element);
422 this.versionId++;
423 }
425 > public moveForward(element: StackElement): void {
426 this._future.pop();
427 this._past.push(element);
428 this.versionId++;
429 }
431 >
432 > class EditStackSnapshot {
433 >
434 > public readonly editStacks: ResourceEditStack[];
435 > private readonly _versionIds: number[];
436 >
437 > constructor(editStacks: ResourceEditStack[]) {
438 this.editStacks = editStacks;
439 this._versionIds = [];
442 }
443 }
445 > public isValid(): boolean {
446 for (let i = 0, len = this.editStacks.length; i < len; i++) {
447 if (this._versionIds[i] !== this.editStacks[i].versionId) {
451 return true;
452 }
454 >
455 > const missingEditStack = new ResourceEditStack('', '');
456 > missingEditStack.locked = true;
457 >
458 > export class UndoRedoService implements IUndoRedoService {
459 > declare readonly _serviceBrand: undefined;
460 >
461 > private readonly _editStacks: Map<string, ResourceEditStack>;
462 > private readonly _uriComparisonKeyComputers: [string, UriComparisonKeyComputer][];
463 >
464 > constructor(
465 @IDialogService private readonly _dialogService: IDialogService,
466 @INotificationService private readonly _notificationService: INotificationService,
469 this._uriComparisonKeyComputers = [];
470 }
472 > public registerUriComparisonKeyComputer(scheme: string, uriComparisonKeyComputer: UriComparisonKeyComputer): IDisposable {
473 this._uriComparisonKeyComputers.push([scheme, uriComparisonKeyComputer]);
474 return {
483 };
484 }
486 > public getUriComparisonKey(resource: URI): string {
487 for (const uriComparisonKeyComputer of this._uriComparisonKeyComputers) {
488 if (uriComparisonKeyComputer[0] === resource.scheme) {
492 return resource.toString();
493 }
495 > private _print(label: string): void {
496 console.log(`------------------------------------`);
497 console.log(`AFTER ${label}: `);
502 console.log(str.join('\n'));
503 }
505 > public pushElement(element: IUndoRedoElement, group: UndoRedoGroup = UndoRedoGroup.None, source: UndoRedoSource = UndoRedoSource.None): void {
506 if (element.type === UndoRedoElementType.Resource) {
507 const resourceLabel = getResourceLabel(element.resource);
534 }
535 }
537 > private _pushElement(element: StackElement): void {
538 for (let i = 0, len = element.strResources.length; i < len; i++) {
539 const resourceLabel = element.resourceLabels[i];
551 }
552 }
554 > public getLastElement(resource: URI): IUndoRedoElement | null {
555 const strResource = this.getUriComparisonKey(resource);
556 if (this._editStacks.has(strResource)) {
564 return null;
565 }
567 > private _splitPastWorkspaceElement(toRemove: WorkspaceStackElement & { actual: { split(): IResourceUndoRedoElement[] } }, ignoreResources: RemovedResources | null): void {
568 const individualArr = toRemove.actual.split();
569 const individualMap = new Map<string, ResourceStackElement>();
583 }
584 }
586 > private _splitFutureWorkspaceElement(toRemove: WorkspaceStackElement & { actual: { split(): IResourceUndoRedoElement[] } }, ignoreResources: RemovedResources | null): void {
587 const individualArr = toRemove.actual.split();
588 const individualMap = new Map<string, ResourceStackElement>();
602 }
603 }
605 > public removeElements(resource: URI | string): void {
606 const strResource = typeof resource === 'string' ? resource : this.getUriComparisonKey(resource);
607 if (this._editStacks.has(strResource)) {
614 }
615 }
617 > public setElementsValidFlag(resource: URI, isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void {
618 const strResource = this.getUriComparisonKey(resource);
619 if (this._editStacks.has(strResource)) {
625 }
626 }
628 > public hasElements(resource: URI): boolean {
629 const strResource = this.getUriComparisonKey(resource);
630 if (this._editStacks.has(strResource)) {
634 return false;
635 }
637 > public createSnapshot(resource: URI): ResourceEditStackSnapshot {
638 const strResource = this.getUriComparisonKey(resource);
639 if (this._editStacks.has(strResource)) {
643 return new ResourceEditStackSnapshot(resource, []);
644 }
646 > public restoreSnapshot(snapshot: ResourceEditStackSnapshot): void {
647 const strResource = this.getUriComparisonKey(snapshot.resource);
648 if (this._editStacks.has(strResource)) {
660 }
661 }
663 > public getElements(resource: URI): IPastFutureElements {
664 const strResource = this.getUriComparisonKey(resource);
665 if (this._editStacks.has(strResource)) {
669 return { past: [], future: [] };
670 }
672 > private _findClosestUndoElementWithSource(sourceId: number): [StackElement | null, string | null] {
673 if (!sourceId) {
674 return [null, null];
694 return [matchedElement, matchedStrResource];
695 }
697 > public canUndo(resourceOrSource: URI | UndoRedoSource): boolean {
698 if (resourceOrSource instanceof UndoRedoSource) {
699 const [, matchedStrResource] = this._findClosestUndoElementWithSource(resourceOrSource.id);
707 return false;
708 }
710 > private _onError(err: Error, element: StackElement): void {
711 onUnexpectedError(err);
712 // An error occurred while undoing or redoing => drop the undo/redo stack for all affected resources
716 this._notificationService.error(err);
717 }
719 > private _acquireLocks(editStackSnapshot: EditStackSnapshot): () => void {
720 // first, check if all locks can be acquired
721 for (const editStack of editStackSnapshot.editStacks) {
737 };
738 }
740 > private _safeInvokeWithLocks(element: StackElement, invoke: () => Promise<void> | void, editStackSnapshot: EditStackSnapshot, cleanup: IDisposable, continuation: () => Promise<void> | void): Promise<void> | void {
741 const releaseLocks = this._acquireLocks(editStackSnapshot);
742
771 }
772 }
774 > private async _invokeWorkspacePrepare(element: WorkspaceStackElement): Promise<IDisposable> {
775 if (typeof element.actual.prepareUndoRedo === 'undefined') {
776 return Disposable.None;
782 return result;
783 }
785 > private _invokeResourcePrepare(element: ResourceStackElement, callback: (disposable: IDisposable) => Promise<void> | void): void | Promise<void> {
786 if (element.actual.type !== UndoRedoElementType.Workspace || typeof element.actual.prepareUndoRedo === 'undefined') {
787 // no preparation needed
803 });
804 }
806 > private _getAffectedEditStacks(element: WorkspaceStackElement): EditStackSnapshot {
807 const affectedEditStacks: ResourceEditStack[] = [];
808 for (const strResource of element.strResources) {
811 return new EditStackSnapshot(affectedEditStacks);
812 }
814 > private _tryToSplitAndUndo(strResource: string, element: WorkspaceStackElement, ignoreResources: RemovedResources | null, message: string): WorkspaceVerificationError {
815 if (element.canSplit()) {
816 this._splitPastWorkspaceElement(element, ignoreResources);
826 }
827 }
829 > private _checkWorkspaceUndo(strResource: string, element: WorkspaceStackElement, editStackSnapshot: EditStackSnapshot, checkInvalidatedResources: boolean): WorkspaceVerificationError | null {
830 if (element.removedResources) {
831 return this._tryToSplitAndUndo(
903 return null;
904 }
906 > private _workspaceUndo(strResource: string, element: WorkspaceStackElement, undoConfirmed: boolean): Promise<void> | void {
907 const affectedEditStacks = this._getAffectedEditStacks(element);
908 const verificationError = this._checkWorkspaceUndo(strResource, element, affectedEditStacks, /*invalidated resources will be checked after the prepare call*/false);
912 return this._confirmAndExecuteWorkspaceUndo(strResource, element, affectedEditStacks, undoConfirmed);
913 }
915 > private _isPartOfUndoGroup(element: WorkspaceStackElement): boolean {
916 if (!element.groupId) {
917 return false;
937 return false;
938 }
940 > private async _confirmAndExecuteWorkspaceUndo(strResource: string, element: WorkspaceStackElement, editStackSnapshot: EditStackSnapshot, undoConfirmed: boolean): Promise<void> {
941
942 if (element.canSplit() && !this._isPartOfUndoGroup(element)) {
1009 return this._safeInvokeWithLocks(element, () => element.actual.undo(), editStackSnapshot, cleanup, () => this._continueUndoInGroup(element.groupId, undoConfirmed));
1010 }
1012 > private _resourceUndo(editStack: ResourceEditStack, element: ResourceStackElement, undoConfirmed: boolean): Promise<void> | void {
1013 if (!element.isValid) {
1014 // invalid element => immediately flush edit stack!
1029 });
1030 }
1032 > private _findClosestUndoElementInGroup(groupId: number): [StackElement | null, string | null] {
1033 if (!groupId) {
1034 return [null, null];
1054 return [matchedElement, matchedStrResource];
1055 }
1057 > private _continueUndoInGroup(groupId: number, undoConfirmed: boolean): Promise<void> | void {
1058 if (!groupId) {
1059 return;
1065 }
1066 }
1068 > public undo(resourceOrSource: URI | UndoRedoSource): Promise<void> | void {
1069 if (resourceOrSource instanceof UndoRedoSource) {
1070 const [, matchedStrResource] = this._findClosestUndoElementWithSource(resourceOrSource.id);
1076 return this._undo(this.getUriComparisonKey(resourceOrSource), 0, false);
1077 }
1079 > private _undo(strResource: string, sourceId: number = 0, undoConfirmed: boolean): Promise<void> | void {
1080 if (!this._editStacks.has(strResource)) {
1081 return;
1115 }
1116 }
1118 > private async _confirmAndContinueUndo(strResource: string, sourceId: number, element: StackElement): Promise<void> {
1119 const result = await this._dialogService.confirm({
1120 message: nls.localize('confirmDifferentSource', "Would you like to undo '{0}'?", element.label),
1129 return this._undo(strResource, sourceId, true);
1130 }
1132 > private _findClosestRedoElementWithSource(sourceId: number): [StackElement | null, string | null] {
1133 if (!sourceId) {
1134 return [null, null];
1154 return [matchedElement, matchedStrResource];
1155 }
1157 > public canRedo(resourceOrSource: URI | UndoRedoSource): boolean {
1158 if (resourceOrSource instanceof UndoRedoSource) {
1159 const [, matchedStrResource] = this._findClosestRedoElementWithSource(resourceOrSource.id);
1167 return false;
1168 }
1170 > private _tryToSplitAndRedo(strResource: string, element: WorkspaceStackElement, ignoreResources: RemovedResources | null, message: string): WorkspaceVerificationError {
1171 if (element.canSplit()) {
1172 this._splitFutureWorkspaceElement(element, ignoreResources);
1182 }
1183 }
1185 > private _checkWorkspaceRedo(strResource: string, element: WorkspaceStackElement, editStackSnapshot: EditStackSnapshot, checkInvalidatedResources: boolean): WorkspaceVerificationError | null {
1186 if (element.removedResources) {
1187 return this._tryToSplitAndRedo(
1259 return null;
1260 }
1262 > private _workspaceRedo(strResource: string, element: WorkspaceStackElement): Promise<void> | void {
1263 const affectedEditStacks = this._getAffectedEditStacks(element);
1264 const verificationError = this._checkWorkspaceRedo(strResource, element, affectedEditStacks, /*invalidated resources will be checked after the prepare call*/false);
1268 return this._executeWorkspaceRedo(strResource, element, affectedEditStacks);
1269 }
1271 > private async _executeWorkspaceRedo(strResource: string, element: WorkspaceStackElement, editStackSnapshot: EditStackSnapshot): Promise<void> {
1272 // prepare
1273 let cleanup: IDisposable;
1290 return this._safeInvokeWithLocks(element, () => element.actual.redo(), editStackSnapshot, cleanup, () => this._continueRedoInGroup(element.groupId));
1291 }
1293 > private _resourceRedo(editStack: ResourceEditStack, element: ResourceStackElement): Promise<void> | void {
1294 if (!element.isValid) {
1295 // invalid element => immediately flush edit stack!
1311 });
1312 }
1314 > private _findClosestRedoElementInGroup(groupId: number): [StackElement | null, string | null] {
1315 if (!groupId) {
1316 return [null, null];
1336 return [matchedElement, matchedStrResource];
1337 }
1339 > private _continueRedoInGroup(groupId: number): Promise<void> | void {
1340 if (!groupId) {
1341 return;
1347 }
1348 }
1350 > public redo(resourceOrSource: URI | UndoRedoSource | string): Promise<void> | void {
1351 if (resourceOrSource instanceof UndoRedoSource) {
1352 const [, matchedStrResource] = this._findClosestRedoElementWithSource(resourceOrSource.id);
1358 return this._redo(this.getUriComparisonKey(resourceOrSource));
1359 }
1361 > private _redo(strResource: string): Promise<void> | void {
1362 if (!this._editStacks.has(strResource)) {
1363 return;
1391 }
1392 }
1394 >
1395 > class WorkspaceVerificationError {
1396 > constructor(public readonly returnValue: Promise<void> | void) { }
1397 > }
1398 >
1399 > registerSingleton(IUndoRedoService, UndoRedoService, InstantiationType.Delayed);
src/vs/platform/dialogs/test/common/testDialogService.ts 33 introduced LOC · 8 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- testDialogService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Event } from '../../../../base/common/event.js';
7 > import Severity from '../../../../base/common/severity.js';
8 > import { IConfirmation, IConfirmationResult, IDialogService, IInputResult, IPrompt, IPromptBaseButton, IPromptResult, IPromptResultWithCancel, IPromptWithCustomCancel, IPromptWithDefaultCancel } from '../../common/dialogs.js';
9 >
10 > export class TestDialogService implements IDialogService {
11 >
12 > declare readonly _serviceBrand: undefined;
13 >
14 > readonly onWillShowDialog = Event.None;
15 > readonly onDidShowDialog = Event.None;
16 >
17 > constructor(
18 private defaultConfirmResult: IConfirmationResult | undefined = undefined,
19 private defaultPromptResult: IPromptResult<unknown> | undefined = undefined
21
22 private confirmResult: IConfirmationResult | undefined = undefined;
23 > setConfirmResult(result: IConfirmationResult) { testDialogService.ts
24 this.confirmResult = result;
25 }
27 > async confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
28 if (this.confirmResult) {
29 const confirmResult = this.confirmResult;
35 return this.defaultConfirmResult ?? { confirmed: false };
36 }
38 > prompt<T>(prompt: IPromptWithCustomCancel<T>): Promise<IPromptResultWithCancel<T>>;
39 > prompt<T>(prompt: IPromptWithDefaultCancel<T>): Promise<IPromptResult<T>>;
40 > prompt<T>(prompt: IPrompt<T>): Promise<IPromptResult<T>>;
41 > async prompt<T>(prompt: IPrompt<T> | IPromptWithCustomCancel<T>): Promise<IPromptResult<T> | IPromptResultWithCancel<T>> {
42 if (this.defaultPromptResult) {
43 return this.defaultPromptResult as IPromptResult<T>;
50 return { result: await promptButtons[0]?.run({ checkboxChecked: false }) };
51 }
52 > async info(message: string, detail?: string): Promise<void> { testDialogService.ts
53 await this.prompt({ type: Severity.Info, message, detail });
54 }
56 > async warn(message: string, detail?: string): Promise<void> {
57 await this.prompt({ type: Severity.Warning, message, detail });
58 }
60 > async error(message: string, detail?: string): Promise<void> {
61 await this.prompt({ type: Severity.Error, message, detail });
62 }
63 > async input(): Promise<IInputResult> { { return { confirmed: true, values: [] }; } } testDialogService.ts
64 > async about(): Promise<void> { }
65 > }