Skip to content

Commit 5d68876

Browse files
chore: pass the VS Code (and extension) version to App Inspector (#143)
1 parent 6bc0f89 commit 5d68876

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/app-inspector/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</head>
1515
<body style="height: 100vh; margin: 0">
1616
<div id="root" style="height: 100%; display: flex; flex-direction: column"></div>
17+
<script>window.__APP_INSPECTOR_CONTEXT__ = null;</script>
1718
<script type="module" src="./main.tsx"></script>
1819
</body>
1920
</html>

src/app-inspector/main.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DeploymentContainer } from "@localstack/appinspector-ui";
12
import {
23
AppInspectorContextProvider,
34
pages,
@@ -14,8 +15,26 @@ import {
1415
Routes,
1516
} from "react-router-dom";
1617

18+
/* Passed by the VS Code extension when App Inspector is launched. */
19+
declare global {
20+
interface Window {
21+
__APP_INSPECTOR_CONTEXT__: {
22+
source: "vscode";
23+
ideVersion: string;
24+
extensionVersion: string;
25+
} | null;
26+
}
27+
}
28+
1729
const APPINSPECTOR_ROUTE_PREFIX = "/appinspector";
1830

31+
const deploymentContainer: DeploymentContainer =
32+
window.__APP_INSPECTOR_CONTEXT__ ?? {
33+
source: "vscode",
34+
ideVersion: "unknown",
35+
extensionVersion: "unknown",
36+
};
37+
1938
render(
2039
<StrictMode>
2140
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
@@ -29,6 +48,7 @@ render(
2948
>
3049
<LocalStackThemeProvider useExtensionLayout={false}>
3150
<AppInspectorContextProvider
51+
deploymentContainer={deploymentContainer}
3252
linkComponent={(props) => (
3353
<Link to={props.to}>{props.children}</Link>
3454
)}

src/plugins/app-inspector-webview.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
TreeItem,
1212
TreeItemCollapsibleState,
1313
Uri,
14+
extensions,
15+
version as vscodeVersion,
1416
} from "vscode";
1517
import type {
1618
ProviderResult,
@@ -61,9 +63,15 @@ export default createPlugin(
6163
"utf-8",
6264
);
6365
outputChannel.debug(`html=${html}`);
64-
panel.webview.html = html.replaceAll(
65-
/"(\/.*?\.(?:js|css))"/g,
66-
(_, asset: string) => {
66+
const extensionVersion =
67+
(
68+
extensions.getExtension("localstack.localstack")?.packageJSON as {
69+
version?: string;
70+
}
71+
)?.version ?? "unknown";
72+
73+
panel.webview.html = html
74+
.replaceAll(/"(\/.*?\.(?:js|css))"/g, (_, asset: string) => {
6775
return JSON.stringify(
6876
panel.webview
6977
.asWebviewUri(
@@ -75,8 +83,15 @@ export default createPlugin(
7583
)
7684
.toString(),
7785
);
78-
},
79-
);
86+
})
87+
.replace(
88+
"window.__APP_INSPECTOR_CONTEXT__ = null;",
89+
`window.__APP_INSPECTOR_CONTEXT__ = ${JSON.stringify({
90+
source: "vscode",
91+
ideVersion: vscodeVersion,
92+
extensionVersion,
93+
})};`,
94+
);
8095
outputChannel.debug(`html=${panel.webview.html}`);
8196
}),
8297
);

0 commit comments

Comments
 (0)