<commit_before>import * as vscode from 'vscode';
import { SvgDocumentContentProvider } from '../svgProvider';
import { SvgPreview, ViewSettings, SvgView } from './svgPreview';
import { SvgExport } from './svgExport';
import { ExportDocumentContentProvider } from '../exportProvider';

abstract class WebviewManager implements vscode.WebviewPanelSerializer {
    protected abstract readonly views: SvgView[];
    abstract deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any);

    protected readonly disposables: vscode.Disposable[] = [];

    public refresh() {
        for (const preview of this.views) {
            preview.refresh();
        }
    }

    public dispose(): void {
        while (this.disposables.length) {
            const item = this.disposables.pop();
            if (item) {
                item.dispose();
            }
        }
        while (this.views.length) {
            const item = this.views.pop();
            if (item) {
                item.dispose();
            }
        }
    }
}
export class SvgWebviewManager extends WebviewManager {
    protected readonly views: SvgPreview[] = [];
    public constructor(
        protected readonly contentProvider: SvgDocumentContentProvider
    ) {
        super();
        this.disposables.push(vscode.window.registerWebviewPanelSerializer(SvgPreview.viewType, this));
    }

    public view(
        resource: vscode.Uri,
        viewSettings: ViewSettings
    ): void {
        let view = this.getExistingView(resource);
        if (view) {
            view.reveal();
        } else {
            view = this.createView(resource, viewSettings);
        }

        view.update(resource);
    }


    public async deserializeWebviewPanel(
        webview: vscode.WebviewPanel,
        state: any
    ): Promise<void> {
        const preview = await SvgPreview.revive(
            webview,
            state,
            this.contentProvider);

        this.registerView(preview);
    }

    private getExistingView(
        resource: vscode.Uri
    ): SvgPreview | undefined {
        return this.views.find(preview =>
            preview.matchesResource(resource));
    }

    private createView(
        resource: vscode.Uri,
        previewSettings: ViewSettings
    ): SvgPreview {
        const preview = SvgPreview.create(
            resource,
            previewSettings.viewColumn,
            this.contentProvider);

        this.setViewActiveContext(true);<commit_msg>起動時の重複表示対応<commit_after>import * as vscode from 'vscode';
import { SvgDocumentContentProvider } from '../svgProvider';
import { SvgPreview, ViewSettings, SvgView } from './svgPreview';
import { SvgExport } from './svgExport';
import { ExportDocumentContentProvider } from '../exportProvider';

abstract class WebviewManager implements vscode.WebviewPanelSerializer {
    protected abstract readonly views: SvgView[];
    abstract deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any);

    protected readonly disposables: vscode.Disposable[] = [];

    public refresh() {
        for (const preview of this.views) {
            preview.refresh();
        }
    }

    public dispose(): void {
        while (this.disposables.length) {
            const item = this.disposables.pop();
            if (item) {
                item.dispose();
            }
        }
        while (this.views.length) {
            const item = this.views.pop();
            if (item) {
                item.dispose();
            }
        }
    }
}
export class SvgWebviewManager extends WebviewManager {
    protected readonly views: SvgPreview[] = [];
    public constructor(
        protected readonly contentProvider: SvgDocumentContentProvider
    ) {
        super();
        this.disposables.push(vscode.window.registerWebviewPanelSerializer(SvgPreview.viewType, this));
    }

    public view(
        resource: vscode.Uri,
        viewSettings: ViewSettings
    ): void {
        let view = this.getExistingView(resource);
        if (view) {
            view.reveal();
        } else {
            view = this.createView(resource, viewSettings);
        }

        view.update(resource);
    }


    public async deserializeWebviewPanel(
        webview: vscode.WebviewPanel,
        state: any
    ): Promise<void> {
        const duplicate = this.getExistingView(vscode.Uri.parse(state.resource));

        if (duplicate) {
            webview.dispose();
            duplicate.update(vscode.Uri.parse(state.resource));
        }
        const preview = await SvgPreview.revive(
            webview,
            state,
            this.contentProvider);

        this.registerView(preview);
    }

    private getExistingView(
        resource: vscode.Uri
    ): SvgPreview | undefined {
        return this.views.find(preview =>
            preview.matchesResource(resource));
    }

    private createView(
        resource: vscode.Uri,
        previewSettings: ViewSettings
    ): SvgPreview {
        const preview = SvgPreview.create(
            resource,
            previewSettings.viewColumn,
            this.contentProvider);

        this.setViewActiveContext(true);
{'fraction_non_alphanumeric': 0.0989159891598916, 'fraction_numerical': 0.0, 'mean_word_length': 2.1757836508912107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2866947', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1368, 'n_words': 294}