Something went wrong. Try again.
dependent-types proof-assistant
Something went wrong. Try again.
1.8 kB · 61 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import * as vscode from 'vscode';
export class AssistantPanelController { constructor(private context: vscode.ExtensionContext) { }
private _panel: vscode.WebviewPanel | undefined; private cachedHtml: Map<string, string> = 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 `<html> <body> <h2>Proof Assistant</h2> <p>Loading...</p> </body> </html>`; }}