From 89de5418db1d7e5f60bc698e4fd1912cb4b2b4de Mon Sep 17 00:00:00 2001 From: Dennis Huebner Date: Tue, 5 Dec 2023 15:10:55 +0100 Subject: [PATCH] Added payload information for response messages --- .../package-lock.json | 24 +++++++++---------- .../src/devtool-ext.ts | 2 +- .../webview-ui/src/components/event-table.tsx | 5 ++-- .../webview-ui/src/devtools-view.tsx | 16 ++++++------- .../vscode-messenger/src/diagnostic-api.ts | 9 ++++++- packages/vscode-messenger/src/messenger.ts | 10 ++++++-- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/vscode-messenger-devtools/package-lock.json b/packages/vscode-messenger-devtools/package-lock.json index 0ef86f3..411692c 100644 --- a/packages/vscode-messenger-devtools/package-lock.json +++ b/packages/vscode-messenger-devtools/package-lock.json @@ -1366,9 +1366,9 @@ } }, "node_modules/semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -1570,9 +1570,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -2560,9 +2560,9 @@ } }, "semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "requires": { "lru-cache": "^6.0.0" @@ -2706,9 +2706,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "wrappy": { diff --git a/packages/vscode-messenger-devtools/src/devtool-ext.ts b/packages/vscode-messenger-devtools/src/devtool-ext.ts index 852808a..56ca417 100644 --- a/packages/vscode-messenger-devtools/src/devtool-ext.ts +++ b/packages/vscode-messenger-devtools/src/devtool-ext.ts @@ -70,7 +70,7 @@ export function activate(context: vscode.ExtensionContext) { listenToNotifications(compatibleExtensions()); }); console.debug('Messenger Devtools activated.'); - return msg.diagnosticApi({ withParameterData: true }); + return msg.diagnosticApi({ withParameterData: true, withResponseData: true}); } export function deactivate(): void { diff --git a/packages/vscode-messenger-devtools/webview-ui/src/components/event-table.tsx b/packages/vscode-messenger-devtools/webview-ui/src/components/event-table.tsx index ce8d590..0227e8b 100644 --- a/packages/vscode-messenger-devtools/webview-ui/src/components/event-table.tsx +++ b/packages/vscode-messenger-devtools/webview-ui/src/components/event-table.tsx @@ -16,13 +16,14 @@ const columnDefs: ColDef[] = [ const rowType = params.data.type ?? 'unknown'; const error = params.data.error ? : undefined; return
{params.value}{error}
; - } + }, + tooltipField: 'payloadInfo' }, { field: 'sender', initialWidth: 180 }, { field: 'receiver', initialWidth: 180 }, { field: 'method', initialWidth: 135, - tooltipField: 'methodTooltip' + tooltipField: 'payloadInfo' }, { field: 'size', headerName: 'Size (Time)', initialWidth: 135, diff --git a/packages/vscode-messenger-devtools/webview-ui/src/devtools-view.tsx b/packages/vscode-messenger-devtools/webview-ui/src/devtools-view.tsx index 63cbdcc..8fc347b 100644 --- a/packages/vscode-messenger-devtools/webview-ui/src/devtools-view.tsx +++ b/packages/vscode-messenger-devtools/webview-ui/src/devtools-view.tsx @@ -37,7 +37,7 @@ export interface ExtensionData { } export interface ExtendedMessengerEvent extends MessengerEvent { timeAfterRequest?: number - methodTooltip?: string + payloadInfo?: string } const MESSENGER_EXTENSION_ID = 'TypeFox.vscode-messenger-devtools'; @@ -210,8 +210,8 @@ class DevtoolsComponent extends React.Component, DevtoolsCom const extensionData = this.state.datasetSrc.get(dataEvent.extension)!; const highlight: HighlightData[] = []; - - if (dataEvent.event.type === 'response' && dataEvent.event.timestamp) { + const isResponse = dataEvent.event.type === 'response'; + if (isResponse && dataEvent.event.timestamp) { // Take max 200 entries to look-up const request = extensionData.events.slice(0, 200).find(event => event.type === 'request' && event.id === dataEvent.event.id); if (request && request.timestamp) { @@ -220,12 +220,10 @@ class DevtoolsComponent extends React.Component, DevtoolsCom } } - if (dataEvent.event.type === 'notification' || dataEvent.event.type === 'request') { - if (dataEvent.event.parameter) { - dataEvent.event.methodTooltip = `Parameter (max 500 chars):\n ${JSON.stringify(dataEvent.event.parameter, undefined, ' ').substring(0, 499)}`; - } else { - dataEvent.event.methodTooltip = 'Parameters are empty or suppressed using diagnostic API options.'; - } + if (dataEvent.event.parameter) { + dataEvent.event.payloadInfo = `${isResponse?'Response':'Parameter'} (max 500 chars):\n ${JSON.stringify(dataEvent.event.parameter, undefined, ' ').substring(0, 499)}`; + } else { + dataEvent.event.payloadInfo = 'Payload information is empty or suppressed using diagnostic API options.'; } extensionData.events.unshift(dataEvent.event); diff --git a/packages/vscode-messenger/src/diagnostic-api.ts b/packages/vscode-messenger/src/diagnostic-api.ts index a0a337b..9d3b11b 100644 --- a/packages/vscode-messenger/src/diagnostic-api.ts +++ b/packages/vscode-messenger/src/diagnostic-api.ts @@ -85,6 +85,13 @@ export interface DiagnosticOptions { * If `true` request/notification parameter will be added to the diagnostic MessengerEvent as payload. * If you don't want to expose potential sensible Data to public API set it to false. * Default is: `false` - */ + */ withParameterData?: boolean + + /** + * If `true` response value will be added to the diagnostic MessengerEvent as payload. + * If you don't want to expose potential sensible Data to public API set it to false. + * Default is: `false` + */ + withResponseData?: boolean } diff --git a/packages/vscode-messenger/src/messenger.ts b/packages/vscode-messenger/src/messenger.ts index 61f6b79..b57d4f4 100644 --- a/packages/vscode-messenger/src/messenger.ts +++ b/packages/vscode-messenger/src/messenger.ts @@ -430,6 +430,7 @@ export class Messenger implements MessengerAPI { event.type = 'response'; event.id = msg.id; event.size = JSON.stringify(msg.result)?.length ?? 0; + event.parameter = msg.result; if (msg.error) { event.error = msg.error?.message ? msg.error?.message : 'No error message provided'; if (msg.error.data) { @@ -440,8 +441,13 @@ export class Messenger implements MessengerAPI { event.error = `Unknown message to ${msg.receiver}`; } this.eventListeners.forEach((options, listener) => { - if (!options?.withParameterData) { - // Clear parameter if user don't want to expose potential sensible Data to public API + if(isResponseMessage(msg)) { + if(!options?.withResponseData) { + // Clear response value if user don't want to expose it + event.parameter = undefined; + } + } else if (!options?.withParameterData) { + // Clear parameter if user don't want to expose it event.parameter = undefined; } listener(event);