UNPKG

6.35 kBTypeScriptView Raw
1import { MessageClient, MessageType, MessageOptions, Progress, ProgressMessage } from './message-service-protocol';
2/**
3 * Service to log and categorize messages, show progress information and offer actions.
4 *
5 * The messages are processed by this service and forwarded to an injected {@link MessageClient}.
6 * For example "@theia/messages" provides such a client, rendering messages as notifications
7 * in the frontend.
8 *
9 * ### Example usage
10 *
11 * ```typescript
12 * @inject(MessageService)
13 * protected readonly messageService: MessageService;
14 *
15 * messageService.warn("Typings not available");
16 *
17 * messageService.error("Could not restore state", ["Rollback", "Ignore"])
18 * .then(action => action === "Rollback" && rollback());
19 * ```
20 */
21export declare class MessageService {
22 protected readonly client: MessageClient;
23 constructor(client: MessageClient);
24 /**
25 * Logs the message and, if given, offers actions to act on it.
26 * @param message the message to log.
27 * @param actions the actions to offer. Can be omitted.
28 *
29 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
30 */
31 log<T extends string>(message: string, ...actions: T[]): Promise<T | undefined>;
32 /**
33 * Logs the message and, if given, offers actions to act on it.
34 * @param message the message to log.
35 * @param options additional options. Can be omitted
36 * @param actions the actions to offer. Can be omitted.
37 *
38 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
39 */
40 log<T extends string>(message: string, options?: MessageOptions, ...actions: T[]): Promise<T | undefined>;
41 /**
42 * Logs the message as "info" and, if given, offers actions to act on it.
43 * @param message the message to log.
44 * @param actions the actions to offer. Can be omitted.
45 *
46 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
47 */
48 info<T extends string>(message: string, ...actions: T[]): Promise<T | undefined>;
49 /**
50 * Logs the message as "info" and, if given, offers actions to act on it.
51 * @param message the message to log.
52 * @param options additional options. Can be omitted
53 * @param actions the actions to offer. Can be omitted.
54 *
55 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
56 */
57 info<T extends string>(message: string, options?: MessageOptions, ...actions: T[]): Promise<T | undefined>;
58 /**
59 * Logs the message as "warning" and, if given, offers actions to act on it.
60 * @param message the message to log.
61 * @param actions the actions to offer. Can be omitted.
62 *
63 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
64 */
65 warn<T extends string>(message: string, ...actions: T[]): Promise<T | undefined>;
66 /**
67 * Logs the message as "warning" and, if given, offers actions to act on it.
68 * @param message the message to log.
69 * @param options additional options. Can be omitted
70 * @param actions the actions to offer. Can be omitted.
71 *
72 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
73 */
74 warn<T extends string>(message: string, options?: MessageOptions, ...actions: T[]): Promise<T | undefined>;
75 /**
76 * Logs the message as "error" and, if given, offers actions to act on it.
77 * @param message the message to log.
78 * @param actions the actions to offer. Can be omitted.
79 *
80 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
81 */
82 error<T extends string>(message: string, ...actions: T[]): Promise<T | undefined>;
83 /**
84 * Logs the message as "error" and, if given, offers actions to act on it.
85 * @param message the message to log.
86 * @param options additional options. Can be omitted
87 * @param actions the actions to offer. Can be omitted.
88 *
89 * @returns the selected action if there is any, `undefined` when there was no action or none was selected.
90 */
91 error<T extends string>(message: string, options?: MessageOptions, ...actions: T[]): Promise<T | undefined>;
92 protected processMessage(type: MessageType, text: string, args?: any[]): Promise<string | undefined>;
93 /**
94 * Shows the given message as a progress.
95 *
96 * @param message the message to show for the progress.
97 * @param onDidCancel an optional callback which will be invoked if the progress indicator was canceled.
98 *
99 * @returns a promise resolving to a {@link Progress} object with which the progress can be updated.
100 *
101 * ### Example usage
102 *
103 * ```typescript
104 * @inject(MessageService)
105 * protected readonly messageService: MessageService;
106 *
107 * // this will show "Progress" as a cancelable message
108 * this.messageService.showProgress({text: 'Progress'});
109 *
110 * // this will show "Rolling back" with "Cancel" and an additional "Skip" action
111 * this.messageService.showProgress({
112 * text: `Rolling back`,
113 * actions: ["Skip"],
114 * },
115 * () => console.log("canceled"))
116 * .then((progress) => {
117 * // register if interested in the result (only necessary for custom actions)
118 * progress.result.then((result) => {
119 * // will be 'Cancel', 'Skip' or `undefined`
120 * console.log("result is", result);
121 * });
122 * progress.report({message: "Cleaning references", work: {done: 10, total: 100}});
123 * progress.report({message: "Restoring previous state", work: {done: 80, total: 100}});
124 * progress.report({message: "Complete", work: {done: 100, total: 100}});
125 * // we are done so we can cancel the progress message, note that this will also invoke `onDidCancel`
126 * progress.cancel();
127 * });
128 * ```
129 */
130 showProgress(message: ProgressMessage, onDidCancel?: () => void): Promise<Progress>;
131 private progressIdPrefix;
132 private counter;
133 protected newProgressId(): string;
134}
135//# sourceMappingURL=message-service.d.ts.map
\No newline at end of file