export async function activate()

in src/extension/index.ts [19:92]


export async function activate(context: ExtensionContext) {
    // Borrowed from: https://github.com/Microsoft/vscode-languageserver-node/blob/db0f0f8c06b89923f96a8a5aebc8a4b5bb3018ad/client/src/main.ts#L217
    const isDebugOrTestMode =
        process.execArgv.some(arg => /^--extensionTestsPath=?/.test(arg)) // Debug
        || process.execArgv.some(arg => /^--(debug|debug-brk|inspect|inspect-brk)=?/.test(arg)); // Test

    if (!isDebugOrTestMode) Telemetry.activate();

    const disposables = context.subscriptions;
    Store.globalState = context.globalState;
    disposables.push(commands.registerCommand('sarif.clearState', () => {
        context.globalState.update('view', undefined);
        commands.executeCommand('workbench.action.reloadWindow');
    }));
    const store = new Store();

    // Basing
    //
    // `findFiles` performance assuming '**':
    //     files     ms
    //     1000      200ms
    //     4000      200-500ms
    //     8000      500-600ms
    //     20000     600ms
    //     1 of 20K  100ms (Only 1 file matches, but 20K need to be searched)
    //     Note: `File: Exclude` setting is respected.
    //     Hardware: 2020 MacBook Pro i7
    const urisNonSarif = await workspace.findFiles('**', '.sarif', 10000); // Ignore folders?
    const fileAndUris = urisNonSarif.map(uri => [platformUriNormalize(uri.path).file, uri.toString(true /* skipEncoding */)]) as [string, string][];
    const baser = new UriRebaser(mapDistinct(fileAndUris), store);

    // Panel
    const panel = new Panel(context, baser, store);
    disposables.push(commands.registerCommand('sarif.showPanel', () => panel.show()));

    // General Activation
    activateDiagnostics(disposables, store, baser);
    activateWatchDocuments(disposables, store, panel);
    activateDecorations(disposables, store);
    activateVirtualDocuments(disposables, store);
    activateSelectionSync(disposables, panel);

    // Check for Updates
    if (!isDebugOrTestMode) {
        disposables.push(workspace.onDidChangeConfiguration(event => {
            if (!event.affectsConfiguration(updateChannelConfigSection)) return;
            update();
        }));
        update();
    }

    // API
    return {
        async openLogs(logs: Uri[], _options: unknown, cancellationToken?: CancellationToken) {
            store.logs.push(...await loadLogs(logs, cancellationToken));
            if (cancellationToken?.isCancellationRequested) return;
            if (store.results.length) panel.show();
        },
        async closeLogs(logs: Uri[]) {
            for (const uri of logs) {
                store.logs.removeFirst(log => log._uri === uri.toString());
            }
        },
        async closeAllLogs() {
            store.logs.splice(0);
        },
        get uriBases() {
            return baser.uriBases.map(uri => Uri.file(uri)) as ReadonlyArray<Uri>;
        },
        set uriBases(values) {
            baser.uriBases = values.map(uri => uri.toString());
        },
    };
}