Skip to content

Commit

Permalink
WIP: #500 NotificationService
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Aug 1, 2023
1 parent f8d4410 commit 6a9a5e6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
78 changes: 78 additions & 0 deletions packages/examples/main/src/langium/notificationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import { INotificationService, initialize, NotificationMessage, INotification, INotificationHandle, INotificationActions, IPromptChoice, IPromptChoiceWithMenu, IPromptOptions, IStatusMessageOptions, Severity } from 'vscode/services';
import { IDisposable } from 'monaco-editor/esm/vs/editor/editor.api.js';

class MyCustomNotificationService implements INotificationService {
onDidAddNotification: any;
onDidRemoveNotification: any;
onDidChangeDoNotDisturbMode: any;
_serviceBrand: undefined;
doNotDisturbMode: boolean;

constructor() {
console.log('Yahoo!');
}

info(message: NotificationMessage | NotificationMessage[]): void {
console.log(`info: ${message}`);
}

warn(message: NotificationMessage | NotificationMessage[]): void {
console.log(`warn: ${message}`);
}

error(message: NotificationMessage | NotificationMessage[]): void {
console.log(`error: ${message}`);
}

notify(notification: INotification): MyNotificationHandle {
console.log(`notify: ${notification}`);
return new MyNotificationHandle();
}

prompt(severity: Severity, message: string, choices: (IPromptChoice | IPromptChoiceWithMenu)[], options?: IPromptOptions): INotificationHandle {
console.log(`prompt: ${severity}, ${message}, ${choices}, ${options}`);
throw new Error('Method not implemented.');
}

status(message: NotificationMessage, options?: IStatusMessageOptions): IDisposable {
console.log(`status: ${message}, ${options}`);
throw new Error('Method not implemented.');
}
}

class MyNotificationHandle implements INotificationHandle {
onDidClose: any;
onDidChangeVisibility: any;
progress: any;

updateSeverity(severity: Severity): void {
console.log(`updateSeverity: ${severity}`);
throw new Error('Method not implemented.');
}

updateMessage(message: NotificationMessage): void {
console.log(`updateMessage: ${message}`);
throw new Error('Method not implemented.');
}

updateActions(actions?: INotificationActions): void {
console.log(`updateActions: ${actions}`);
throw new Error('Method not implemented.');
}

close(): void {
throw new Error('Method not implemented.');
}
}

export const initMyNotificationService = async () => {
await initialize({
get [INotificationService.toString()]() {
return new MyCustomNotificationService();
}
});
};
4 changes: 3 additions & 1 deletion packages/examples/main/src/langium/statemachineClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import getAccessibilityServiceOverride from 'vscode/service-override/accessibili
import { LogLevel } from 'vscode/services';
// import { renderPanelPart } from 'vscode/service-override/views';
import 'vscode/default-extensions/theme-defaults';
import { initMyNotificationService } from './notificationService.js';

import { buildWorkerDefinition } from 'monaco-editor-workers';
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers/', new URL('', window.location.href).href, false);
Expand Down Expand Up @@ -147,7 +148,8 @@ try {
enableAccessibilityService: false,
userServices: {
// manually add the accessibility service
...getAccessibilityServiceOverride()
...getAccessibilityServiceOverride(),
...initMyNotificationService()
},
debugLogging: true,
logLevel: LogLevel.Info
Expand Down

0 comments on commit 6a9a5e6

Please sign in to comment.