import * as vscode from 'vscode'; export class AssistantPanelController { constructor(private context: vscode.ExtensionContext) { } private _panel: vscode.WebviewPanel | undefined; private cachedHtml: Map = new Map(); private getPanel(): vscode.WebviewPanel { if (this._panel) { return this._panel; } const panel = vscode.window.createWebviewPanel( 'pterodactylProofAssistant', 'Proof Assistant', { viewColumn: vscode.ViewColumn.Beside, preserveFocus: true }, { enableScripts: true, retainContextWhenHidden: true } ); panel.onDidDispose(() => { this._panel = undefined; }); this._panel = panel; return panel; } public update(editor?: vscode.TextEditor) { // Ignore non-text editors (e.g., clicking the panel itself) if (!editor?.document) { return; } const isPtero = editor.document.languageId === 'pterodactyl'; if (isPtero) { const panel = this.getPanel(); const uri = editor.document.uri.toString(); panel.webview.html = this.cachedHtml.get(uri) ?? this.getLoadingHtml(); panel.reveal(vscode.ViewColumn.Beside, true); } else { this._panel?.dispose(); } } public updateHtml(uri: string, html: string) { this.cachedHtml.set(uri, html); if (this._panel) { const activeUri = vscode.window.activeTextEditor?.document.uri.toString(); if (activeUri === uri) { this._panel.webview.html = html; } } } private getLoadingHtml() { return `

Proof Assistant

Loading...

`; } }