(message: NotificationMessage)
| 649 | } |
| 650 | |
| 651 | function handleNotification(message: NotificationMessage) { |
| 652 | if (isDisposed()) { |
| 653 | // See handle request. |
| 654 | return; |
| 655 | } |
| 656 | let type: MessageType | undefined = undefined; |
| 657 | let notificationHandler: GenericNotificationHandler | undefined; |
| 658 | if (message.method === CancelNotification.type.method) { |
| 659 | notificationHandler = (params: CancelParams) => { |
| 660 | let id = params.id; |
| 661 | let source = requestTokens[String(id)]; |
| 662 | if (source) { |
| 663 | source.cancel(); |
| 664 | } |
| 665 | } |
| 666 | } else { |
| 667 | let element = notificationHandlers[message.method]; |
| 668 | if (element) { |
| 669 | notificationHandler = element.handler; |
| 670 | type = element.type; |
| 671 | } |
| 672 | } |
| 673 | if (notificationHandler || starNotificationHandler) { |
| 674 | try { |
| 675 | traceReceivedNotification(message); |
| 676 | if (message.params === void 0 || (type !== void 0 && type.numberOfParams === 0)) { |
| 677 | notificationHandler ? notificationHandler() : starNotificationHandler!(message.method); |
| 678 | } else if (Is.array(message.params) && (type === void 0 || type.numberOfParams > 1)) { |
| 679 | notificationHandler ? notificationHandler(...message.params) : starNotificationHandler!(message.method, ...message.params); |
| 680 | } else { |
| 681 | notificationHandler ? notificationHandler(message.params) : starNotificationHandler!(message.method, message.params); |
| 682 | } |
| 683 | } catch (error) { |
| 684 | if (error.message) { |
| 685 | logger.error(`Notification handler '${message.method}' failed with message: ${error.message}`); |
| 686 | } else { |
| 687 | logger.error(`Notification handler '${message.method}' failed unexpectedly.`); |
| 688 | } |
| 689 | } |
| 690 | } else { |
| 691 | unhandledNotificationEmitter.fire(message); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | function handleInvalidMessage(message: Message) { |
| 696 | if (!message) { |
no test coverage detected