All files / src/views ProfilePanel.ts

85.29% Statements 29/34
100% Branches 3/3
66.66% Functions 2/3
85.29% Lines 29/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x 1x 1x     2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x    
import * as vscode from 'vscode';
import * as fs from 'fs';
 
export class ProfilePanel {
    constructor(
        private readonly extensionUri: vscode.Uri, 
        private readonly context: vscode.ExtensionContext
    ) {}

    public async getHtml(webview: vscode.Webview): Promise<string> {
        const profileStyleUri = webview.asWebviewUri(
            vscode.Uri.joinPath(this.extensionUri, 'media', 'profilePanel.css')
        );
 
        const templatePath = vscode.Uri.joinPath(
            this.extensionUri, 
            'media', 
            'profilePanel.html'
        ).fsPath;
        
        let htmlTemplate = '';
        try {
            htmlTemplate = fs.readFileSync(templatePath, 'utf8');
        } catch (e) {
            console.error('Failed to read profilePanel.html:', e);
            return '<div>Failed to load profile panel.</div>';
        }
 
        const html = htmlTemplate
            .replace('{{PROFILE_STYLE_URI}}', profileStyleUri.toString());
 
        return html;
    }
}