"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionContext = void 0;
exports.createExtensionsApiFactory = createExtensionsApiFactory;
const path_1 = require("@opensumi/ide-utils/lib/path");
const ext_types_1 = require("../../../common/vscode/ext-types");
const ext_host_secrets_1 = require("./ext.host.secrets");
const ext_host_storage_1 = require("./ext.host.storage");
class ExtensionContext {
    constructor(options) {
        this.subscriptions = [];
        const { extensionId, storageProxy, secretProxy, createExtension, isDevelopment, extensionLocation, extensionDescription, } = options;
        this.extensionId = extensionId;
        this._storage = storageProxy;
        this.createExtension = createExtension;
        this.extensionDescription = extensionDescription;
        this._extensionLocation = extensionLocation;
        this._isDevelopment = !!isDevelopment;
        this.workspaceState = new ext_host_storage_1.ExtensionMemento(extensionId, false, storageProxy);
        this.globalState = new ext_host_storage_1.ExtensionGlobalMemento(extensionId, true, storageProxy);
        this.secrets = new ext_host_secrets_1.ExtensionSecrets(extensionDescription, secretProxy);
        this.exthostTerminalService = options.exthostTerminal;
        this.componentProxy = options.extendProxy;
        this.registerExtendModuleService = options.registerExtendModuleService;
    }
    asAbsolutePath(relativePath) {
        return (0, path_1.join)(this._extensionLocation.fsPath, relativePath);
    }
    get extensionUri() {
        return this._extensionLocation;
    }
    get extensionPath() {
        return this._extensionLocation.fsPath;
    }
    get storageUri() {
        return this._storage.getExtensionStorageUri(this.extensionId);
    }
    get storagePath() {
        var _a;
        return (_a = this.storageUri) === null || _a === void 0 ? void 0 : _a.fsPath.toString();
    }
    get logUri() {
        return this._storage.getExtensionLogUri(this.extensionId);
    }
    get logPath() {
        return this.logUri.fsPath.toString();
    }
    get globalStorageUri() {
        return this._storage.getExtensionGlobalStorageUri(this.extensionId);
    }
    get globalStoragePath() {
        return this.globalStorageUri.fsPath.toString();
    }
    get extensionMode() {
        return this._isDevelopment ? ext_types_1.ExtensionMode.Development : ext_types_1.ExtensionMode.Production;
    }
    get environmentVariableCollection() {
        var _a;
        return (_a = this.exthostTerminalService) === null || _a === void 0 ? void 0 : _a.getEnvironmentVariableCollection(this.extensionDescription);
    }
    get extension() {
        return this.createExtension(this.extensionDescription);
    }
}
exports.ExtensionContext = ExtensionContext;
function createExtensionsApiFactory(extensionService) {
    return {
        all: (() => extensionService.getExtensions())(),
        // TODO: VS Code 目前支持多个 worker 插件进程，该 API 为获取当前插件进程可以访问的进程
        // anycode 最新版插件依赖改 API，先临时实现
        allAcrossExtensionHosts: (() => extensionService.getExtensions())(),
        get onDidChange() {
            return extensionService.extensionsChangeEmitter.event;
        },
        getExtension(extensionId) {
            return extensionService.getExtension(extensionId);
        },
    };
}
//# sourceMappingURL=ext.host.extensions.js.map