import * as vscode from 'vscode' ; export function activate ( context ) { console . log ( 'Congratulations, your extension "helloworld-sample" is now active!' ) ; let disposable = vscode . commands . registerCommand ( 'extension.helloWorld' , ( ) => { vscode . window . showInformationMessage ( 'Hello World!' ) ; } ) ; let webViewCommand = vscode . commands . registerCommand ( 'extension.webview' , async ( ) => { TestView . createOrShow ( ) ; } ) ; context . subscriptions . push ( disposable ) ; context . subscriptions . push ( webViewCommand ) ; } export function deactivate ( ) { } class TestView { private static instance : TestView | undefined ; public static readonly viewType = 'testView' ; private readonly _panel : vscode . WebviewPanel ; private _disposables : vscode . Disposable [ ] = [ ] ; public static createOrShow ( ) { const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ; if ( TestView . instance ) { TestView . instance . _panel . reveal ( column ) ; return ; } const panel = vscode . window . createWebviewPanel ( TestView . viewType , 'Test WebView' , column || vscode . ViewColumn . One ) ; TestView . instance = new TestView ( panel ) ; } private constructor ( panel ) { this . _panel = panel ; this . update ( ) ; this . _panel . onDidDispose ( ( ) => this . dispose ( ) , null , this . _disposables ) ; this . _panel . onDidChangeViewState ( e => { if ( this . _panel . visible ) { this . update ( ) ; } } , null , this . _disposables ) ; } public dispose ( ) { TestView . instance = undefined ; this . _panel . dispose ( ) ; while ( this . _disposables . length ) { const x = this . _disposables . pop ( ) ; if ( x ) { x . dispose ( ) ; } } } private update ( ) { this . _panel . title = 'Test WebView' ; this . _panel . webview . html = `<!DOCTYPE html>
		<html lang="en">
		<head>
			<meta charset="UTF-8">
			<meta name="viewport" content="width=device-width, initial-scale=1.0">
			<title>Test Webview</title>
		</head>
		<body>
			<h1>This is a web view</h1>
		</body>
		</html>` ; } }