notifications.ts ×58

Frontier kind: Code frontier

unlabeled · c_844d8e265c70

3 tests · 8452 LOC · 40 files · introduces 0 tests · 436 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
59 ranges436 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1170 ranges8452 lines · 40 files · Browse complete extent
All tests (intent)
3 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.

Introduced files, introduced tests, and structurally relevant concept specializationnotifications.ts ×23 · 137 introduced LOCnotifications.ts ×23notifications.ts ×17 · 59 introduced LOCnotifications.ts ×17notifications.ts ×25 · 82 introduced LOCnotifications.ts ×25notifications.ts ×1 · 2 introduced LOCnotifications.ts ×1notifications.ts ×1 · 2 introduced LOCnotifications.ts ×1errors.ts ×2 · 3 introduced LOCerrors.ts ×2async.ts ×202 · 1247 introduced LOCasync.ts ×202notification.ts ×1 · 5 introduced LOCnotification.ts ×1notification.ts ×3 · 464 introduced LOCnotification.ts ×3actions.ts ×25 · 151 introduced LOCactions.ts ×25resources.ts ×23 · 253 introduced LOCresources.ts ×23severity.ts ×3 · 32 introduced LOCseverity.ts ×3network.ts ×20 · 292 introduced LOCnetwork.ts ×20strings.test|title=Strings trimWhitespace|occurrence=1 · 0 introduced LOCstrings.test|title=Strin…extpath.ts ×17 · 91 introduced LOCextpath.ts ×17strings.ts ×101 · 542 introduced LOCstrings.ts ×101event.ts ×1 · 2 introduced LOCevent.ts ×1event.ts ×2 · 5 introduced LOCevent.ts ×2linkedText.ts ×3 · 39 introduced LOClinkedText.ts ×3decorators.ts ×1 · 4 introduced LOCdecorators.ts ×1event.ts ×2 · 15 introduced LOCevent.ts ×2cancellation.test|title=CancellationToken None|occurrence=1 · 0 introduced LOCcancellation.test|title=…event.ts ×3 · 6 introduced LOCevent.ts ×3decorators.ts ×5 · 11 introduced LOCdecorators.ts ×5lifecycle.test|title=No Leakage Utilities ensureNoDisposablesAreLeakedInTest Basic Test|occurrence=1 · 0 introduced LOClifecycle.test|title=No …decorators.ts ×5 · 17 introduced LOCdecorators.ts ×5event.ts ×8 · 30 introduced LOCevent.ts ×8event.ts ×3 · 19 introduced LOCevent.ts ×3cancelPreviousCalls.ts ×1 · 87 introduced LOCcancelPreviousCalls.ts ×…cancellation.ts ×18 · 90 introduced LOCcancellation.ts ×18lifecycle.ts ×2 · 3 introduced LOClifecycle.ts ×2lifecycle.test|title=Lifecycle dispose disposable array|occurrence=1, lifecycle.test|title=Lifecycle Action bar has broken accessibility #100273|occurrence=1 · 0 introduced LOClifecycle.test|title=Lif…event.ts ×3 · 4 introduced LOCevent.ts ×3event.ts ×1 · 1 introduced LOCevent.ts ×1lifecycle.ts ×3 · 6 introduced LOClifecycle.ts ×3event.ts ×4 · 9 introduced LOCevent.ts ×4event.ts ×2 · 4 introduced LOCevent.ts ×2lifecycle.ts ×2 · 6 introduced LOClifecycle.ts ×2event.ts ×2 · 6 introduced LOCevent.ts ×2event.ts ×93 · 864 introduced LOCevent.ts ×93lifecycle.ts ×1 · 6 introduced LOClifecycle.ts ×1languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication disposes entries no longer in model|occurrence=1 · 0 introduced LOClanguageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication mixed unique and duplicate IDs|occurrence=1, languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication creates new entry when none exists|occurrence=1, +4 · 0 introduced LOClanguageStatusDedupe.tes…uri.test|title=URI URI#file, win-speciale|occurrence=1, charCode.test|title=CharCode has good values|occurrence=1, +2 · 0 introduced LOCuri.test|title=URI URI#f…utils.ts ×3 · 9 introduced LOCutils.ts ×3errorMessage.ts ×6 · 29 introduced LOCerrorMessage.ts ×6lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1linkedList.ts ×13 · 44 introduced LOClinkedList.ts ×13instantiation.ts ×5 · 111 introduced LOCinstantiation.ts ×5lifecycle.ts ×1 · 4 introduced LOClifecycle.ts ×1lifecycle.ts ×2 · 6 introduced LOClifecycle.ts ×2lifecycle.ts ×2 · 4 introduced LOClifecycle.ts ×2lifecycle.ts ×1 · 6 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 1 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1lifecycle.ts ×3 · 9 introduced LOClifecycle.ts ×3lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 7 introduced LOClifecycle.ts ×1lifecycle.ts ×4 · 7 introduced LOClifecycle.ts ×4lifecycle.ts ×4 · 8 introduced LOClifecycle.ts ×4lifecycle.ts ×6 · 16 introduced LOClifecycle.ts ×6lifecycle.ts ×2 · 2 introduced LOClifecycle.ts ×2lazy.ts ×1 · 2 introduced LOClazy.ts ×1lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1lifecycle.ts ×3 · 3 introduced LOClifecycle.ts ×3lazy.ts ×3 · 37 introduced LOClazy.ts ×3lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1uint.ts ×2 · 43 introduced LOCuint.ts ×2iterator.ts ×1 · 2 introduced LOCiterator.ts ×1lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1map.ts ×97 · 3334 introduced LOCmap.ts ×97src/vs/base/common/actions.ts · 294 LOCcommon/actions.tssrc/vs/base/common/arrays.ts · 949 LOCcommon/arrays.tssrc/vs/base/common/arraysFind.ts · 226 LOCcommon/arraysFind.tssrc/vs/base/common/assert.ts · 91 LOCcommon/assert.tssrc/vs/base/common/async.ts · 2749 LOCcommon/async.tssrc/vs/base/common/cache.ts · 153 LOCcommon/cache.tssrc/vs/base/common/cancellation.ts · 206 LOCcommon/cancellation.tssrc/vs/base/common/charCode.ts · 450 LOCcommon/charCode.tssrc/vs/base/common/collections.ts · 176 LOCcommon/collections.tssrc/vs/base/common/decorators.ts · 131 LOCcommon/decorators.tssrc/vs/base/common/decorators/cancelPreviousCalls.ts · 168 LOCdecorators/cancelPreviou…src/vs/base/common/errorMessage.ts · 113 LOCcommon/errorMessage.tssrc/vs/base/common/errors.ts · 357 LOCcommon/errors.tssrc/vs/base/common/event.ts · 1964 LOCcommon/event.tssrc/vs/base/common/extpath.ts · 433 LOCcommon/extpath.tssrc/vs/base/common/functional.ts · 32 LOCcommon/functional.tssrc/vs/base/common/iterator.ts · 194 LOCcommon/iterator.tssrc/vs/base/common/lazy.ts · 57 LOCcommon/lazy.tssrc/vs/base/common/lifecycle.ts · 974 LOCcommon/lifecycle.tssrc/vs/base/common/linkedList.ts · 151 LOCcommon/linkedList.tssrc/vs/base/common/linkedText.ts · 55 LOCcommon/linkedText.tssrc/vs/base/common/map.ts · 1016 LOCcommon/map.tssrc/vs/base/common/marshallingIds.ts · 33 LOCcommon/marshallingIds.tssrc/vs/base/common/network.ts · 440 LOCcommon/network.tssrc/vs/base/common/path.ts · 1589 LOCcommon/path.tssrc/vs/base/common/platform.ts · 281 LOCcommon/platform.tssrc/vs/base/common/process.ts · 76 LOCcommon/process.tssrc/vs/base/common/resources.ts · 444 LOCcommon/resources.tssrc/vs/base/common/severity.ts · 56 LOCcommon/severity.tssrc/vs/base/common/stopwatch.ts · 41 LOCcommon/stopwatch.tssrc/vs/base/common/strings.ts · 1413 LOCcommon/strings.tssrc/vs/base/common/symbols.ts · 9 LOCcommon/symbols.tssrc/vs/base/common/types.ts · 410 LOCcommon/types.tssrc/vs/base/common/uint.ts · 59 LOCcommon/uint.tssrc/vs/base/common/uri.ts · 754 LOCcommon/uri.tssrc/vs/base/test/common/utils.ts · 107 LOCcommon/utils.tssrc/vs/nls.ts · 244 LOCvs/nls.tssrc/vs/platform/instantiation/common/instantiation.ts · 130 LOCcommon/instantiation.tssrc/vs/platform/notification/common/notification.ts · 491 LOCcommon/notification.tssrc/vs/workbench/common/notifications.ts · 818 LOCcommon/notifications.tscancellation.test|title=CancellationToken None|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/cancellation.test|title=CancellationToken None|occurrence=1cancellation.test|title=…charCode.test|title=CharCode has good values|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/charCode.test|title=CharCode has good values|occurrence=1charCode.test|title=Char…lifecycle.test|title=Lifecycle Action bar has broken accessibility #100273|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/lifecycle.test|title=Lifecycle Action bar has broken accessibility #100273|occurrence=1lifecycle.test|title=Lif…lifecycle.test|title=Lifecycle dispose disposable array|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/lifecycle.test|title=Lifecycle dispose disposable array|occurrence=1lifecycle.test|title=Lif…lifecycle.test|title=No Leakage Utilities ensureNoDisposablesAreLeakedInTest Basic Test|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/lifecycle.test|title=No Leakage Utilities ensureNoDisposablesAreLeakedInTest Basic Test|occurrence=1lifecycle.test|title=No …path.test|title=Paths (Node Implementation) path|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/path.test|title=Paths (Node Implementation) path|occurrence=1path.test|title=Paths (N…strings.test|title=Strings trimWhitespace|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/strings.test|title=Strings trimWhitespace|occurrence=1strings.test|title=Strin…uri.test|title=URI File paths containing apostrophes break URI parsing and cannot be opened #276075|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI File paths containing apostrophes break URI parsing and cannot be opened #276075|occurrence=1uri.test|title=URI File …uri.test|title=URI URI#file, win-speciale|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI URI#file, win-speciale|occurrence=1uri.test|title=URI URI#f…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication creates new entry when none exists|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication creates new entry when none exists|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication disposes entries no longer in model|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication disposes entries no longer in model|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate IDs with existing entry - fixed version reuses existing|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate IDs with existing entry - fixed version reuses existing|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate status IDs - buggy version leaks entry|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate status IDs - buggy version leaks entry|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate status IDs - fixed version reuses entry from current update|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication duplicate status IDs - fixed version reuses entry from current update|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication mixed unique and duplicate IDs|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication mixed unique and duplicate IDs|occurrence=1languageStatusDedupe.tes…languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication reuses existing entry from previous update|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/languageStatus/test/common/languageStatusDedupe.test|title=LanguageStatus - Dedicated Entry Deduplication reuses existing entry from previous update|occurrence=1languageStatusDedupe.tes…notifications.test|title=Notifications Items - does not fire changed when message did not change (content, severity)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/test/common/notifications.test|title=Notifications Items - does not fire changed when message did not change (content, severity)|occurrence=1notifications.test|title…notifications.test|title=Notifications Items|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/test/common/notifications.test|title=Notifications Items|occurrence=1notifications.test|title…notifications.test|title=Notifications Model|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/test/common/notifications.test|title=Notifications Model|occurrence=1notifications.test|title…Focused concept · notifications.ts ×58 · 436 introduced LOCnotifications.ts ×58

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: 436 introduced LOC across 59 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/common/notifications.ts 432 introduced LOC · 58 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- notifications.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 { INotification, INotificationHandle, INotificationActions, INotificationProgress, NoOpNotification, Severity, NotificationMessage, IPromptChoice, IStatusMessageOptions, NotificationsFilter, INotificationProgressProperties, IPromptChoiceWithMenu, NotificationPriority, INotificationSource, isNotificationSource, IStatusHandle } from '../../platform/notification/common/notification.js';
7 > import { toErrorMessage, isErrorWithActions } from '../../base/common/errorMessage.js';
8 > import { Event, Emitter } from '../../base/common/event.js';
9 > import { Disposable } from '../../base/common/lifecycle.js';
10 > import { isCancellationError } from '../../base/common/errors.js';
11 > import { Action } from '../../base/common/actions.js';
12 > import { equals } from '../../base/common/arrays.js';
13 > import { parseLinkedText, LinkedText } from '../../base/common/linkedText.js';
14 > import { mapsStrictEqualIgnoreOrder } from '../../base/common/map.js';
15 > import { IConfigurationService } from '../../platform/configuration/common/configuration.js';
16 >
17 > export interface INotificationsModel {
18 >
19 > //#region Notifications as Toasts/Center
20 >
21 > readonly notifications: INotificationViewItem[];
22 >
23 > readonly onDidChangeNotification: Event<INotificationChangeEvent>;
24 > readonly onDidChangeFilter: Event<Partial<INotificationsFilter>>;
25 >
26 > addNotification(notification: INotification): INotificationHandle;
27 >
28 > setFilter(filter: Partial<INotificationsFilter>): void;
29 >
30 > //#endregion
31 >
32 >
33 > //#region Notifications as Status
34 >
35 > readonly statusMessage: IStatusMessageViewItem | undefined;
36 >
37 > readonly onDidChangeStatusMessage: Event<IStatusMessageChangeEvent>;
38 >
39 > showStatusMessage(message: NotificationMessage, options?: IStatusMessageOptions): IStatusHandle;
40 >
41 > //#endregion
42 > }
43 >
44 > export const enum NotificationChangeType {
45 >
46 > /**
47 > * A notification was added.
48 > */
49 > ADD,
50 >
51 > /**
52 > * A notification changed. Check `detail` property
53 > * on the event for additional information.
54 > */
55 > CHANGE,
56 >
57 > /**
58 > * A notification expanded or collapsed.
59 > */
60 > EXPAND_COLLAPSE,
61 >
62 > /**
63 > * A notification was removed.
64 > */
65 > REMOVE
66 > }
67 >
68 > export interface INotificationChangeEvent {
69 >
70 > /**
71 > * The index this notification has in the list of notifications.
72 > */
73 > index: number;
74 >
75 > /**
76 > * The notification this change is about.
77 > */
78 > item: INotificationViewItem;
79 >
80 > /**
81 > * The kind of notification change.
82 > */
83 > kind: NotificationChangeType;
84 >
85 > /**
86 > * Additional detail about the item change. Only applies to
87 > * `NotificationChangeType.CHANGE`.
88 > */
89 > detail?: NotificationViewItemContentChangeKind;
90 > }
91 >
92 > export const enum StatusMessageChangeType {
93 > ADD,
94 > REMOVE
95 > }
96 >
97 > export interface IStatusMessageViewItem {
98 > message: string;
99 > options?: IStatusMessageOptions;
100 > }
101 >
102 > export interface IStatusMessageChangeEvent {
103 >
104 > /**
105 > * The status message item this change is about.
106 > */
107 > item: IStatusMessageViewItem;
108 >
109 > /**
110 > * The kind of status message change.
111 > */
112 > kind: StatusMessageChangeType;
113 > }
114 >
115 > export class NotificationHandle extends Disposable implements INotificationHandle {
116 >
117 > private readonly _onDidClose = this._register(new Emitter<void>());
118 > readonly onDidClose = this._onDidClose.event;
119 >
120 > private readonly _onDidChangeVisibility = this._register(new Emitter<boolean>());
121 > readonly onDidChangeVisibility = this._onDidChangeVisibility.event;
122 >
123 > constructor(private readonly item: INotificationViewItem, private readonly onClose: (item: INotificationViewItem) => void) {
124 super();
125
126 this.registerListeners();
127 }
129 > private registerListeners(): void {
130
131 // Visibility
139 });
140 }
142 > get progress(): INotificationProgress {
143 return this.item.progress;
144 }
146 > updateSeverity(severity: Severity): void {
147 this.item.updateSeverity(severity);
148 }
150 > updateMessage(message: NotificationMessage): void {
151 this.item.updateMessage(message);
152 }
154 > updateActions(actions?: INotificationActions): void {
155 this.item.updateActions(actions);
156 }
158 > close(): void {
159 this.onClose(this.item);
160
161 this.dispose();
162 }
164 >
165 > export interface INotificationsFilter {
166 > readonly global: NotificationsFilter;
167 > readonly sources: Map<string, NotificationsFilter>;
168 > }
169 >
170 > export class NotificationsModel extends Disposable implements INotificationsModel {
171
172 private static readonly NO_OP_NOTIFICATION = new NoOpNotification();
191 sources: new Map<string, NotificationsFilter>()
192 };
194 > setFilter(filter: Partial<INotificationsFilter>): void {
195 let globalChanged = false;
196 if (typeof filter.global === 'number') {
212 }
213 }
215 > addNotification(notification: INotification): INotificationHandle {
216 const item = this.createViewItem(notification);
217 if (!item) {
232 return new NotificationHandle(item, item => this.onClose(item));
233 }
235 > private onClose(item: INotificationViewItem): void {
236 const liveItem = this.findNotification(item);
237 if (liveItem && liveItem !== item) {
241 }
242 }
244 > private findNotification(item: INotificationViewItem): INotificationViewItem | undefined {
245 return this._notifications.find(notification => notification.equals(item));
246 }
248 > private createViewItem(notification: INotification): INotificationViewItem | undefined {
249 const item = NotificationViewItem.create(notification, this.filter);
250 if (!item) {
276 return item;
277 }
279 > showStatusMessage(message: NotificationMessage, options?: IStatusMessageOptions): IStatusHandle {
280 const item = StatusMessageViewItem.create(message, options);
281 if (!item) {
295 };
296 }
298 >
299 > export interface INotificationViewItem {
300 > readonly id: string | undefined;
301 > readonly severity: Severity;
302 > readonly sticky: boolean;
303 > readonly priority: NotificationPriority;
304 > readonly message: INotificationMessage;
305 > readonly source: string | undefined;
306 > readonly sourceId: string | undefined;
307 > readonly actions: INotificationActions | undefined;
308 > readonly progress: INotificationViewItemProgress;
309 >
310 > readonly expanded: boolean;
311 > readonly visible: boolean;
312 > readonly canCollapse: boolean;
313 > readonly hasProgress: boolean;
314 >
315 > readonly onDidChangeExpansion: Event<void>;
316 > readonly onDidChangeVisibility: Event<boolean>;
317 > readonly onDidChangeContent: Event<INotificationViewItemContentChangeEvent>;
318 > readonly onDidClose: Event<void>;
319 >
320 > expand(): void;
321 > collapse(skipEvents?: boolean): void;
322 > toggle(): void;
323 >
324 > updateSeverity(severity: Severity): void;
325 > updateMessage(message: NotificationMessage): void;
326 > updateActions(actions?: INotificationActions): void;
327 >
328 > updateVisibility(visible: boolean): void;
329 >
330 > close(): void;
331 >
332 > equals(item: INotificationViewItem): boolean;
333 > }
334 >
335 > export function isNotificationViewItem(obj: unknown): obj is INotificationViewItem {
336 return obj instanceof NotificationViewItem;
337 }
339 > export const enum NotificationViewItemContentChangeKind {
340 > SEVERITY,
341 > MESSAGE,
342 > ACTIONS,
343 > PROGRESS
344 > }
345 >
346 > export interface INotificationViewItemContentChangeEvent {
347 > kind: NotificationViewItemContentChangeKind;
348 > }
349 >
350 > export interface INotificationViewItemProgressState {
351 > infinite?: boolean;
352 > total?: number;
353 > worked?: number;
354 > done?: boolean;
355 > }
356 >
357 > export interface INotificationViewItemProgress extends INotificationProgress {
358 > readonly state: INotificationViewItemProgressState;
359 >
360 > dispose(): void;
361 > }
362 >
363 > export class NotificationViewItemProgress extends Disposable implements INotificationViewItemProgress {
364 > private readonly _state: INotificationViewItemProgressState;
365 >
366 > private readonly _onDidChange = this._register(new Emitter<void>());
367 > readonly onDidChange = this._onDidChange.event;
368 >
369 > constructor() {
370 super();
371
372 this._state = Object.create(null);
373 }
375 > get state(): INotificationViewItemProgressState {
376 return this._state;
377 }
379 > infinite(): void {
380 if (this._state.infinite) {
381 return;
390 this._onDidChange.fire();
391 }
393 > done(): void {
394 if (this._state.done) {
395 return;
404 this._onDidChange.fire();
405 }
407 > total(value: number): void {
408 if (this._state.total === value) {
409 return;
417 this._onDidChange.fire();
418 }
420 > worked(value: number): void {
421 if (typeof this._state.worked === 'number') {
422 this._state.worked += value;
430 this._onDidChange.fire();
431 }
433 >
434 > export interface IMessageLink {
435 > href: string;
436 > name: string;
437 > title: string;
438 > offset: number;
439 > length: number;
440 > }
441 >
442 > export interface INotificationMessage {
443 > raw: string;
444 > original: NotificationMessage;
445 > linkedText: LinkedText;
446 > }
447 >
448 > export class NotificationViewItem extends Disposable implements INotificationViewItem {
449 >
450 > private static readonly MAX_MESSAGE_LENGTH = 1000;
451 >
452 > private _expanded: boolean | undefined;
453 > private _visible: boolean = false;
454 >
455 > private _actions: INotificationActions | undefined;
456 > private _progress: NotificationViewItemProgress | undefined;
457 >
458 > private readonly _onDidChangeExpansion = this._register(new Emitter<void>());
459 > readonly onDidChangeExpansion = this._onDidChangeExpansion.event;
460 >
461 > private readonly _onDidClose = this._register(new Emitter<void>());
462 > readonly onDidClose = this._onDidClose.event;
463 >
464 > private readonly _onDidChangeContent = this._register(new Emitter<INotificationViewItemContentChangeEvent>());
465 > readonly onDidChangeContent = this._onDidChangeContent.event;
466 >
467 > private readonly _onDidChangeVisibility = this._register(new Emitter<boolean>());
468 > readonly onDidChangeVisibility = this._onDidChangeVisibility.event;
469 >
470 > static create(notification: INotification, filter: INotificationsFilter): INotificationViewItem | undefined {
471 > if (!notification?.message || isCancellationError(notification.message)) {
472 return undefined; // we need a message to show
473 }
475 > let severity: Severity;
476 > if (typeof notification.severity === 'number') {
477 > severity = notification.severity;
478 > } else {
479 severity = Severity.Info;
480 }
482 > const message = NotificationViewItem.parseNotificationMessage(notification.message);
483 > if (!message) {
484 return undefined; // we need a message to show
485 }
487 > let actions: INotificationActions | undefined;
488 > if (notification.actions) {
489 actions = notification.actions;
490 > } else if (isErrorWithActions(notification.message)) { notifications.ts
491 actions = { primary: notification.message.actions };
492 }
494 > let priority = notification.priority ?? NotificationPriority.DEFAULT;
495 > if ((priority === NotificationPriority.DEFAULT || priority === NotificationPriority.OPTIONAL) && severity !== Severity.Error) {
496 if (filter.global === NotificationsFilter.ERROR) {
497 priority = NotificationPriority.SILENT; // filtered globally
500 }
501 }
503 > return new NotificationViewItem(notification.id, severity, notification.sticky, priority, message, notification.source, notification.progress, actions);
504 > }
505 >
506 > private static parseNotificationMessage(input: NotificationMessage): INotificationMessage | undefined {
507 > let message: string | undefined;
508 > if (input instanceof Error) {
509 message = toErrorMessage(input, false);
510 > } else if (typeof input === 'string') { notifications.ts
511 > message = input;
512 > }
513 >
514 > if (!message) {
515 return undefined; // we need a message to show
516 }
518 > const raw = message;
519 >
520 > // Make sure message is in the limits
521 > if (message.length > NotificationViewItem.MAX_MESSAGE_LENGTH) {
522 message = `${message.substr(0, NotificationViewItem.MAX_MESSAGE_LENGTH)}...`;
523 }
525 > // Remove newlines from messages as we do not support that and it makes link parsing hard
526 > message = message.replace(/(\r\n|\n|\r)/gm, ' ').trim();
527 >
528 > // Parse Links
529 > const linkedText = parseLinkedText(message);
530 >
531 > return { raw, linkedText, original: input };
532 > }
533 >
534 > private constructor(
535 > readonly id: string | undefined,
536 > private _severity: Severity,
537 > private _sticky: boolean | undefined,
538 > private _priority: NotificationPriority,
539 > private _message: INotificationMessage,
540 > private _source: string | INotificationSource | undefined,
541 > progress: INotificationProgressProperties | undefined,
542 > actions?: INotificationActions
543 > ) {
544 > super();
545 >
546 > if (progress) {
547 this.setProgress(progress);
548 }
550 > this.setActions(actions);
551 > }
552 >
553 > private setProgress(progress: INotificationProgressProperties): void {
554 if (progress.infinite) {
555 this.progress.infinite();
562 }
563 }
565 > private setActions(actions: INotificationActions = { primary: [], secondary: [] }): void {
566 > this._actions = {
567 > primary: Array.isArray(actions.primary) ? actions.primary : [],
568 > secondary: Array.isArray(actions.secondary) ? actions.secondary : []
569 > };
570 >
571 > this._expanded = actions.primary && actions.primary.length > 0;
572 > }
573 >
574 > get canCollapse(): boolean {
575 return !this.hasActions;
576 }
578 > get expanded(): boolean {
579 return !!this._expanded;
580 }
582 > get severity(): Severity {
583 return this._severity;
584 }
586 > get sticky(): boolean {
587 if (this._sticky) {
588 return true; // explicitly sticky
600 return false; // not sticky
601 }
603 > get priority(): NotificationPriority {
604 return this._priority;
605 }
607 > private get hasActions(): boolean {
608 if (!this._actions) {
609 return false;
616 return this._actions.primary.length > 0;
617 }
619 > get hasProgress(): boolean {
620 return !!this._progress;
621 }
623 > get progress(): INotificationViewItemProgress {
624 if (!this._progress) {
625 this._progress = this._register(new NotificationViewItemProgress());
629 return this._progress;
630 }
632 > get message(): INotificationMessage {
633 return this._message;
634 }
636 > get source(): string | undefined {
637 return typeof this._source === 'string' ? this._source : (this._source ? this._source.label : undefined);
638 }
640 > get sourceId(): string | undefined {
641 return (this._source && typeof this._source !== 'string' && 'id' in this._source) ? this._source.id : undefined;
642 }
644 > get actions(): INotificationActions | undefined {
645 return this._actions;
646 }
648 > get visible(): boolean {
649 return this._visible;
650 }
652 > updateSeverity(severity: Severity): void {
653 > if (severity === this._severity) {
654 return;
655 }
657 this._severity = severity;
658 this._onDidChangeContent.fire({ kind: NotificationViewItemContentChangeKind.SEVERITY });
660 >
661 > updateMessage(input: NotificationMessage): void {
662 > const message = NotificationViewItem.parseNotificationMessage(input);
663 > if (!message || message.raw === this._message.raw) {
664 return;
665 }
667 this._message = message;
668 this._onDidChangeContent.fire({ kind: NotificationViewItemContentChangeKind.MESSAGE });
670 >
671 > updateActions(actions?: INotificationActions): void {
672 this.setActions(actions);
673 this._onDidChangeContent.fire({ kind: NotificationViewItemContentChangeKind.ACTIONS });
674 }
676 > updateVisibility(visible: boolean): void {
677 if (this._visible !== visible) {
678 this._visible = visible;
681 }
682 }
684 > expand(): void {
685 if (this._expanded || !this.canCollapse) {
686 return;
690 this._onDidChangeExpansion.fire();
691 }
693 > collapse(skipEvents?: boolean): void {
694 if (!this._expanded || !this.canCollapse) {
695 return;
702 }
703 }
705 > toggle(): void {
706 if (this._expanded) {
707 this.collapse();
710 }
711 }
713 > close(): void {
714 > this._onDidClose.fire();
715 >
716 > this.dispose();
717 > }
718 >
719 > equals(other: INotificationViewItem): boolean {
720 if (this.hasProgress || other.hasProgress) {
721 return false;
742 return equals(primaryActions, otherPrimaryActions, (action, otherAction) => (action.id + action.label) === (otherAction.id + otherAction.label));
743 }
745 >
746 > export class ChoiceAction extends Action {
747 >
748 > private readonly _onDidRun = this._register(new Emitter<void>());
749 > readonly onDidRun = this._onDidRun.event;
750 >
751 > private readonly _keepOpen: boolean;
752 > private readonly _menu: ChoiceAction[] | undefined;
753 >
754 > constructor(id: string, choice: IPromptChoice) {
755 super(id, choice.label, undefined, true, async () => {
756
765 this._menu = !choice.isSecondary && (<IPromptChoiceWithMenu>choice).menu ? (<IPromptChoiceWithMenu>choice).menu.map((c, index) => new ChoiceAction(`${id}.${index}`, c)) : undefined;
766 }
768 > get menu(): ChoiceAction[] | undefined {
769 return this._menu;
770 }
772 > get keepOpen(): boolean {
773 return this._keepOpen;
774 }
776 >
777 > class StatusMessageViewItem {
778 >
779 > static create(notification: NotificationMessage, options?: IStatusMessageOptions): IStatusMessageViewItem | undefined {
780 if (!notification || isCancellationError(notification)) {
781 return undefined; // we need a message to show
795 return { message, options };
796 }
798 >
799 > export const enum NotificationsSettings {
800 > NOTIFICATIONS_POSITION = 'workbench.notifications.position',
801 > NOTIFICATIONS_BUTTON = 'workbench.notifications.showInTitleBar'
802 > }
803 >
804 > export const enum NotificationsPosition {
805 > BOTTOM_RIGHT = 'bottom-right',
806 > BOTTOM_LEFT = 'bottom-left',
807 > TOP_RIGHT = 'top-right'
808 > }
809 >
810 > export function getNotificationsPosition(configurationService: IConfigurationService): NotificationsPosition {
811 const position = configurationService.getValue<NotificationsPosition>(NotificationsSettings.NOTIFICATIONS_POSITION);
812
src/vs/base/common/errorMessage.ts 4 introduced LOC · 1 range

Open complete file

95
96 export function isErrorWithActions(obj: unknown): obj is IErrorWithActions {
97 > const candidate = obj as IErrorWithActions | undefined; errorMessage.ts
98 >
99 > return candidate instanceof Error && Array.isArray(candidate.actions);
100 > }
101
102 export function createErrorWithActions(messageOrError: string | Error, actions: IAction[]): IErrorWithActions {