Skip to content

Commit

Permalink
feat: Handle exportJSON message from AppMap
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilpin authored and ahtrotta committed Jan 31, 2024
1 parent 1d28787 commit ba10c68
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 30 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@
"yaml": "^2.1.1"
},
"dependencies": {
"@appland/appmap": "^3.119.0",
"@appland/appmap": "^3.121.0",
"@appland/client": "^1.14.1",
"@appland/components": "^3.27.1",
"@appland/components": "^3.30.0",
"@appland/diagrams": "^1.8.0",
"@appland/models": "^2.10.0",
"@appland/scanner": "^1.86.0",
Expand Down
71 changes: 50 additions & 21 deletions src/webviews/appmapMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as vscode from 'vscode';
import viewSource from './viewSource';
import { Telemetry, DEBUG_EXCEPTION } from '../telemetry';
import { Telemetry } from '../telemetry';
import FilterStore from './filterStore';
import ErrorCode from '../telemetry/definitions/errorCodes';
import { tmpdir } from 'node:os';
import { randomBytes } from 'node:crypto';
import { join } from 'node:path';
import { writeFile } from 'node:fs/promises';

type AppMapExport = {
metadata?: {
name: string;
};
};

export default function appmapMessageHandler(
filterStore: FilterStore,
workspace?: vscode.WorkspaceFolder
): (message: any) => Promise<void> {
const exportSVG = async (svgString?: string) => {
if (!svgString) return;

const comment =
'\n<!-- Save this SVG file with a .svg file extension ' +
'and then open it in a web browswer to view your appmap! -->\n\n';
const document = await vscode.workspace.openTextDocument({
language: 'svg',
content: comment + svgString,
});

vscode.window.showTextDocument(document);
};

const exportJSON = async (appmapData?: AppMapExport) => {
if (!appmapData) return;

const appmapName = appmapData.metadata?.name || randomBytes(16).toString('hex');
const appmapFileName = [
appmapName.replaceAll(/[^a-zA-Z0-9\-_ ]/g, '_').replaceAll(/_+/g, '_'),
'.appmap.json',
].join('');

const tempDir = tmpdir();
const tempFilePath = join(tempDir, appmapFileName);
await writeFile(tempFilePath, JSON.stringify(appmapData, null, 2));
const { remoteName } = vscode.env;
const command = remoteName === 'wsl' ? 'remote-wsl.revealInExplorer' : 'revealFileInOS';
vscode.commands.executeCommand(command, vscode.Uri.file(tempFilePath));
};

return async (message: any) => {
switch (message.command) {
case 'viewSource':
Expand All @@ -28,25 +68,14 @@ export default function appmapMessageHandler(
break;
case 'exportSVG':
{
try {
const { svgString } = message;
if (svgString) {
const comment =
'\n<!-- Save this SVG file with a .svg file extension ' +
'and then open it in a web browswer to view your appmap! -->\n\n';
const document = await vscode.workspace.openTextDocument({
language: 'svg',
content: comment + svgString,
});

vscode.window.showTextDocument(document);
}
} catch (e) {
Telemetry.sendEvent(DEBUG_EXCEPTION, {
exception: e as Error,
errorCode: ErrorCode.ExportSvgError,
});
}
const { svgString } = message;
exportSVG(svgString);
}
break;
case 'exportJSON':
{
const { appmapData } = message;
exportJSON(appmapData);
}
break;
case 'saveFilter': {
Expand Down
4 changes: 4 additions & 0 deletions web/src/handleAppMapMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default function handleAppMapMessages(app, vscode) {
vscode.postMessage({ command: 'exportSVG', svgString });
});

app.$on('exportJSON', (appmapData) => {
vscode.postMessage({ command: 'exportJSON', appmapData });
});

app.$on('saveFilter', (filter) => {
vscode.postMessage({ command: 'saveFilter', filter });
});
Expand Down
41 changes: 34 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ __metadata:
languageName: node
linkType: hard

"@appland/appmap@npm:^3.119.0":
version: 3.119.0
resolution: "@appland/appmap@npm:3.119.0"
"@appland/appmap@npm:^3.121.0":
version: 3.121.0
resolution: "@appland/appmap@npm:3.121.0"
dependencies:
"@appland/client": ^1.14.0
"@appland/components": ^3.21.2
Expand Down Expand Up @@ -130,7 +130,7 @@ __metadata:
optional: true
bin:
appmap: built/cli.js
checksum: 764229cafcb5d8d7ec913a4f6749437da149e385fe04032b639491bf91b1ee9bbd611dab82453462311ffcc762a52e1b5b813a130ee7668b10772de33d4fe6ff
checksum: d4a25fc7527f5410856b7309cb7eb7669166d05e9bd6e63db09af09f832969cc5ef4f359f7355ac78c685f3e0139abf2d6e070e6b479615741e04530aee612b6
languageName: node
linkType: hard

Expand All @@ -148,7 +148,7 @@ __metadata:
languageName: node
linkType: hard

"@appland/components@npm:^3.21.2, @appland/components@npm:^3.27.1":
"@appland/components@npm:^3.21.2":
version: 3.27.1
resolution: "@appland/components@npm:3.27.1"
dependencies:
Expand All @@ -175,6 +175,33 @@ __metadata:
languageName: node
linkType: hard

"@appland/components@npm:^3.30.0":
version: 3.30.0
resolution: "@appland/components@npm:3.30.0"
dependencies:
"@appland/client": ^1.12.0
"@appland/diagrams": ^1.7.0
"@appland/models": ^2.10.0
"@appland/rpc": ^1.1.0
"@appland/sequence-diagram": ^1.11.0
buffer: ^6.0.3
d3: ^7.8.4
d3-flame-graph: ^4.1.3
diff: ^5.1.0
dom-to-svg: ^0.12.2
dompurify: ^3.0.6
events: ^3.3.0
highlight.js: ^11.9.0
jayson: ^4.1.0
marked: ^10.0.0
marked-highlight: ^2.0.7
sql-formatter: ^4.0.2
vue: ^2.7.14
vuex: ^3.6.0
checksum: 9b733273fc8c6783b4ecfa1ad9fd2db03c5fcbd238480f5c680d0c6fcf4aa36f09411cc98c64a7453b7885007ccbe87da2536260cdae95fbd68103ad36d78cd5
languageName: node
linkType: hard

"@appland/diagrams@npm:^1.7.0, @appland/diagrams@npm:^1.8.0":
version: 1.8.0
resolution: "@appland/diagrams@npm:1.8.0"
Expand Down Expand Up @@ -3135,9 +3162,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "appmap@workspace:."
dependencies:
"@appland/appmap": ^3.119.0
"@appland/appmap": ^3.121.0
"@appland/client": ^1.14.1
"@appland/components": ^3.27.1
"@appland/components": ^3.30.0
"@appland/diagrams": ^1.8.0
"@appland/models": ^2.10.0
"@appland/scanner": ^1.86.0
Expand Down

0 comments on commit ba10c68

Please sign in to comment.