// The module 'vscode' contains the VS Code extensibility API import * as vscode from 'vscode'; /** * WebviewViewProvider implementation for the RA.Aid panel */ class RAWebviewViewProvider implements vscode.WebviewViewProvider { constructor(private readonly _extensionUri: vscode.Uri) {} /** * Called when a view is first created to initialize the webview */ public resolveWebviewView( webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken ) { // Set options for the webview webviewView.webview.options = { // Enable JavaScript in the webview enableScripts: true, // Restrict the webview to only load resources from the extension's directory localResourceRoots: [this._extensionUri] }; // Set the HTML content of the webview webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); } /** * Creates HTML content for the webview with proper security policies */ private _getHtmlForWebview(webview: vscode.Webview): string { // Create a URI to the extension's assets directory const logoUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'assets', 'RA.png')); // Create a URI to the script file // const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'dist', 'webview.js')); // Use a nonce to whitelist scripts const nonce = getNonce(); return ` RA.Aid

RA.Aid

Your research and development assistant.

More features coming soon!

`; } } /** * Generates a random nonce for CSP */ function getNonce() { let text = ''; const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (let i = 0; i < 32; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } // This method is called when your extension is activated export function activate(context: vscode.ExtensionContext) { // Use the console to output diagnostic information (console.log) and errors (console.error) console.log('Congratulations, your extension "ra-aid" is now active!'); // Register the WebviewViewProvider const provider = new RAWebviewViewProvider(context.extensionUri); const viewRegistration = vscode.window.registerWebviewViewProvider( 'ra-aid.view', // Must match the view id in package.json provider ); context.subscriptions.push(viewRegistration); // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json const disposable = vscode.commands.registerCommand('ra-aid.helloWorld', () => { // The code you place here will be executed every time your command is executed // Display a message box to the user vscode.window.showInformationMessage('Hello World from RA.Aid!'); }); context.subscriptions.push(disposable); } // This method is called when your extension is deactivated export function deactivate() {}