1- import { readFile } from "node:fs/promises" ;
2- import path from "node:path" ;
3-
41import ms from "ms" ;
5- import {
6- commands ,
7- EventEmitter ,
8- StatusBarAlignment ,
9- ThemeColor ,
10- ThemeIcon ,
11- TreeItem ,
12- TreeItemCollapsibleState ,
13- Uri ,
14- ViewColumn ,
15- window ,
16- } from "vscode" ;
17- import type {
18- ExtensionContext ,
19- ProviderResult ,
20- TreeDataProvider ,
21- Event ,
22- } from "vscode" ;
2+ import { StatusBarAlignment , window } from "vscode" ;
3+ import type { ExtensionContext } from "vscode" ;
234
5+ import appInspectorWebview from "./plugins/app-inspector-webview.ts" ;
246import configureAws from "./plugins/configure-aws.ts" ;
257import logs from "./plugins/logs.ts" ;
268import manage from "./plugins/manage.ts" ;
@@ -29,7 +11,6 @@ import statusBar from "./plugins/status-bar.ts";
2911import { PluginManager } from "./plugins.ts" ;
3012import { createContainerStatusTracker } from "./utils/container-status.ts" ;
3113import { createLocalStackStatusTracker } from "./utils/localstack-status.ts" ;
32- import type { LocalStackStatusTracker } from "./utils/localstack-status.ts" ;
3314import { getOrCreateExtensionSessionId } from "./utils/manage.ts" ;
3415import { createSetupStatusTracker } from "./utils/setup-status.ts" ;
3516import { createTelemetry } from "./utils/telemetry.ts" ;
@@ -41,6 +22,7 @@ const plugins = new PluginManager([
4122 manage ,
4223 statusBar ,
4324 logs ,
25+ appInspectorWebview ,
4426] ) ;
4527
4628export async function activate ( context : ExtensionContext ) {
@@ -127,302 +109,8 @@ export async function activate(context: ExtensionContext) {
127109 timeTracker,
128110 } ) ;
129111 } ) ;
130-
131- context . subscriptions . push (
132- commands . registerCommand ( "localstack.openAppInspector" , async ( ) => {
133- const panel = window . createWebviewPanel (
134- "webviewOpener" ,
135- `App Inspector` ,
136- ViewColumn . Active ,
137- {
138- enableScripts : true ,
139- retainContextWhenHidden : true ,
140- } ,
141- ) ;
142-
143- // panel.webview.asWebviewUri
144-
145- const appInspectorDist = path . resolve (
146- import . meta. dirname ,
147- "../resources/app-inspector/dist" ,
148- ) ;
149- outputChannel . debug ( `appInspectorDist=${ appInspectorDist } ` ) ;
150- const html = await readFile (
151- path . join ( appInspectorDist , "index.html" ) ,
152- "utf-8" ,
153- ) ;
154- outputChannel . debug ( `html=${ html } ` ) ;
155- // webview.asWebviewUri(vscode.Uri.joinPath(dist, entry.file))
156- panel . webview . html = html . replaceAll (
157- / " ( \/ .* ?\. (?: j s | c s s ) ) " / g,
158- ( _ , asset : string ) => {
159- return JSON . stringify (
160- panel . webview
161- . asWebviewUri (
162- Uri . joinPath (
163- context . extensionUri ,
164- "resources/app-inspector/dist" ,
165- asset ,
166- ) ,
167- )
168- . toString ( ) ,
169- ) ;
170- } ,
171- ) ;
172- outputChannel . debug ( `html=${ panel . webview . html } ` ) ;
173-
174- panel . onDidDispose ( ( ) => {
175- // Clean up resources if needed
176- } ) ;
177- } ) ,
178- ) ;
179-
180- const provider = new ExampleTreeDataProvider ( {
181- localStackStatusTracker,
182- } ) ;
183-
184- // const interval = setInterval(() => {
185- // provider.refresh();
186- // }, 1000);
187- // context.subscriptions.push({
188- // dispose() {
189- // clearInterval(interval);
190- // },
191- // });
192-
193- // Register the provider under the view ID defined in package.json
194- const instancesTreeView = window . createTreeView ( "localstack.instances" , {
195- treeDataProvider : provider ,
196- showCollapseAll : false ,
197- } ) ;
198112}
199113
200114export async function deactivate ( ) {
201115 await plugins . deactivate ( ) ;
202116}
203-
204- class ExampleTreeItem extends TreeItem {
205- children ?: ExampleTreeItem [ ] ;
206- }
207-
208- interface ExampleTreeDataProviderOptions {
209- localStackStatusTracker : LocalStackStatusTracker ;
210- }
211-
212- class ExampleTreeDataProvider implements TreeDataProvider < ExampleTreeItem > {
213- readonly #onDidChangeTreeData = new EventEmitter <
214- ExampleTreeItem | undefined | void
215- > ( ) ;
216-
217- readonly onDidChangeTreeData : Event < ExampleTreeItem | undefined | void > =
218- this . #onDidChangeTreeData. event ;
219-
220- #rootItems: ExampleTreeItem [ ] = [ ] ;
221-
222- constructor ( options : ExampleTreeDataProviderOptions ) {
223- // const one = new ExampleTreeItem("Item One", "one");
224- // items.push(one);
225-
226- // if (this.showTwoItems) {
227- // const two = new ExampleTreeItem("Item Two", "two");
228- // items.push(two);
229- // }
230-
231- const appInspectorItem = new ExampleTreeItem (
232- "App Inspector" ,
233- TreeItemCollapsibleState . None ,
234- ) ;
235- // appInspectorItem.tooltip = "App Inspector →";
236- appInspectorItem . description = "Click to open ↗" ;
237- // appInspectorItem.iconPath = new ThemeIcon("search");
238- // appInspectorItem.iconPath = new ThemeIcon("book");
239- // appInspectorItem.iconPath = new ThemeIcon("plug");
240- appInspectorItem . command = {
241- title : "Open App Inspector" ,
242- command : "localstack.openAppInspector" ,
243- } ;
244-
245- // const endpointItem = new ExampleTreeItem(
246- // "Endpoint",
247- // TreeItemCollapsibleState.None,
248- // );
249- // endpointItem.description = "https://localhost.localstack.cloud:4566";
250- // endpointItem.tooltip = "Click to copy";
251- // // endpointItem.iconPath = new ThemeIcon("globe");
252-
253- const instanceItem = new ExampleTreeItem (
254- "localhost.localstack.cloud" ,
255- TreeItemCollapsibleState . Expanded ,
256- ) ;
257- // instanceEndpointItem.description = "stopped";
258- instanceItem . iconPath =
259- options . localStackStatusTracker . status ( ) === "running"
260- ? new ThemeIcon ( "circle-filled" )
261- : new ThemeIcon ( "circle-outline" , new ThemeColor ( "disabledForeground" ) ) ;
262- instanceItem . children = [
263- // (() => {
264- // const item = new ExampleTreeItem(
265- // "LocalStack is not running",
266- // TreeItemCollapsibleState.None,
267- // );
268- // // item.description = "Running";
269- // // item.tooltip = "Click to copy";
270- // // item.iconPath = new ThemeIcon(
271- // // "error",
272- // // new ThemeColor("errorForeground"),
273- // // );
274-
275- // return item;
276- // })(),
277- ( ( ) => {
278- const item = new ExampleTreeItem (
279- "Status" ,
280- TreeItemCollapsibleState . None ,
281- ) ;
282- // item.description = options.localStackStatusTracker.status();
283- // item.tooltip = "Click to copy";
284- // item.iconPath = new ThemeIcon("globe");
285- options . localStackStatusTracker . onChange ( ( status ) => {
286- item . description = status ;
287- // item.iconPath =
288- // status === "running"
289- // ? new ThemeIcon("circle-filled")
290- // : new ThemeIcon(
291- // "circle-outline",
292- // new ThemeColor("disabledForeground"),
293- // );
294- this . #onDidChangeTreeData. fire ( item ) ;
295- } ) ;
296-
297- return item ;
298- } ) ( ) ,
299- // endpointItem,
300- appInspectorItem ,
301- ] ;
302-
303- // instanceEndpointItem.tooltip = "tooltip";
304- // instanceEndpointItem.description =
305- // "localhost.localstack.cloud";
306- // instanceEndpointItem.iconPath = new ThemeIcon("globe");
307-
308- this . #rootItems. push ( instanceItem ) ;
309-
310- options . localStackStatusTracker . onChange ( ( status ) => {
311- instanceItem . iconPath =
312- status === "running"
313- ? new ThemeIcon ( "circle-filled" )
314- : new ThemeIcon (
315- "circle-outline" ,
316- new ThemeColor ( "disabledForeground" ) ,
317- ) ;
318- this . #onDidChangeTreeData. fire ( instanceItem ) ;
319- } ) ;
320-
321- // this.#interval = setInterval(() => {
322- // const status: "running" | "stopped" =
323- // Math.random() * 100 > 50 ? "running" : "stopped";
324- // instanceEndpointItem.iconPath =
325- // status === "running"
326- // ? new ThemeIcon("circle-filled")
327- // : new ThemeIcon(
328- // "circle-outline",
329- // new ThemeColor("disabledForeground"),
330- // );
331- // this.#_onDidChangeTreeData.fire(instanceEndpointItem);
332- // }, 1000);
333- }
334-
335- // /**
336- // * Triggers a refresh of the tree view.
337- // */
338- // refresh(): void {
339- // this.#_onDidChangeTreeData.fire();
340- // }
341-
342- /**
343- * Returns children of a given element or root.
344- * Root returns 1–2 items; no nested children in this minimal example.
345- */
346- getChildren ( element ?: ExampleTreeItem ) : ProviderResult < ExampleTreeItem [ ] > {
347- if ( element ) {
348- return element . children ;
349- }
350-
351- return this . #rootItems;
352- // const appInspectorItem = new ExampleTreeItem(
353- // "App Inspector ↗",
354- // TreeItemCollapsibleState.None,
355- // );
356- // // appInspectorItem.tooltip = "App Inspector →";
357- // // appInspectorItem.description = "Click to open";
358- // // appInspectorItem.iconPath = new ThemeIcon("search");
359- // // appInspectorItem.iconPath = new ThemeIcon("book");
360- // // appInspectorItem.iconPath = new ThemeIcon("plug");
361- // appInspectorItem.command = {
362- // title: "Open App Inspector",
363- // command: "localstack.openAppInspector",
364- // };
365-
366- // // const endpointItem = new ExampleTreeItem(
367- // // "Endpoint",
368- // // TreeItemCollapsibleState.None,
369- // // );
370- // // endpointItem.description = "https://localhost.localstack.cloud:4566";
371- // // endpointItem.tooltip = "Click to copy";
372- // // // endpointItem.iconPath = new ThemeIcon("globe");
373-
374- // const status: "running" | "stopped" =
375- // Math.random() * 100 > 50 ? "running" : "stopped";
376-
377- // const instanceEndpointItem = new ExampleTreeItem(
378- // "localhost.localstack.cloud",
379- // TreeItemCollapsibleState.Expanded,
380- // );
381- // // instanceEndpointItem.description = "stopped";
382- // instanceEndpointItem.iconPath =
383- // status === "running"
384- // ? new ThemeIcon("circle-filled")
385- // : new ThemeIcon("circle-outline", new ThemeColor("disabledForeground"));
386- // instanceEndpointItem.children = [
387- // (() => {
388- // const item = new ExampleTreeItem(
389- // "LocalStack is not running",
390- // TreeItemCollapsibleState.None,
391- // );
392- // // item.description = "Running";
393- // // item.tooltip = "Click to copy";
394- // // item.iconPath = new ThemeIcon(
395- // // "error",
396- // // new ThemeColor("errorForeground"),
397- // // );
398-
399- // return item;
400- // })(),
401- // // (() => {
402- // // const item = new ExampleTreeItem(
403- // // "Status",
404- // // TreeItemCollapsibleState.None,
405- // // );
406- // // item.description = "Running";
407- // // // item.tooltip = "Click to copy";
408- // // item.iconPath = new ThemeIcon("globe");
409- // // return item;
410- // // })(),
411- // // endpointItem,
412- // // appInspectorItem,
413- // ];
414- // // instanceEndpointItem.tooltip = "tooltip";
415- // // instanceEndpointItem.description =
416- // // "localhost.localstack.cloud";
417- // // instanceEndpointItem.iconPath = new ThemeIcon("globe");
418-
419- // return [instanceEndpointItem];
420- }
421-
422- /**
423- * Returns a TreeItem to render in the view.
424- */
425- getTreeItem ( element : ExampleTreeItem ) : TreeItem {
426- return element ;
427- }
428- }
0 commit comments