import { Deferred, Disposable, Emitter, ExtHostSpawnOptions, ExtensionConnectOption, IDisposable, IExtensionLogger, IExtensionProps, IJSONSchema, ILogger, LifeCyclePhase, LinkedText, MaybePromise, URI, Uri, WithEventBus } from '@opensumi/ide-core-common';
import { IIconService, IconType, ThemeType } from '@opensumi/ide-theme/lib/common/theme.service';
import { ExtHostStorage } from '../hosted/api/vscode/ext.host.storage';
import { Extension } from '../hosted/vscode.extension';
import { ActivatedExtension, ActivatedExtensionJSON, ExtensionsActivator } from './activator';
import { ISumiExtensionContributions } from './sumi/extension';
import { IExtensionContributions, IExtensionLanguagePack, IMainThreadCommands } from './vscode';
import { ThemeIcon } from './vscode/ext-types';
import type { ContextKeyExpression } from '@opensumi/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
export interface IExtensionMetaData {
    id: string;
    extensionId: string;
    path: string;
    uri?: Uri;
    packageJSON: {
        [key: string]: any;
    };
    defaultPkgNlsJSON: {
        [key: string]: any;
    } | undefined;
    packageNlsJSON: {
        [key: string]: any;
    } | undefined;
    extraMetadata: JSONType;
    realPath: string;
    extendConfig: JSONType;
    isBuiltin: boolean;
    isDevelopment?: boolean;
}
/**
 * 提供插件扫描时的额外信息读取能力
 * 比如 read/changelog/package.nls.json 等等
 */
export interface IExtraMetaData {
    [key: string]: string;
}
export declare const ExtensionNodeServiceServerPath = "ExtensionNodeServiceServerPath";
export type ExtensionDependencies = (string | {
    [extensionId: string]: string;
})[];
export interface ICreateProcessOptions {
    /**
     * 启用插件进程的 Debug 模式
     */
    enableDebugExtensionHost?: boolean;
    /**
     * 调试插件进程的 Host 地址
     */
    inspectExtensionHost?: string;
    /**
     * 插件进程连接时候一些配置选项
     */
    extensionConnectOption?: ExtensionConnectOption;
    extHostSpawnOptions?: ExtHostSpawnOptions;
}
export declare const IExtensionNodeService: unique symbol;
export interface IExtensionNodeService {
    initialize(): Promise<void>;
    getAllExtensions(scan: string[], extensionCandidate: string[], localization: string, extraMetaData: IExtraMetaData): Promise<IExtensionMetaData[]>;
    createProcess(clientId: string, options?: ICreateProcessOptions): Promise<void>;
    ensureProcessReady(clientId: string): Promise<boolean>;
    getExtProcessId(clientId: string): Promise<number | null>;
    getElectronMainThreadListenPath(clientId: string): Promise<string>;
    getExtServerListenOption(clientId: string): any;
    getExtension(extensionPath: string, localization: string, extraMetaData?: IExtraMetaData): Promise<IExtensionMetaData | undefined>;
    setConnectionServiceClient(clientId: string, serviceClient: IExtensionNodeClientService): any;
    disposeClientExtProcess(clientId: string, info: boolean): Promise<void>;
    disposeAllClientExtProcess(): Promise<void>;
    tryEnableInspectPort(clientId: string, delay?: number): Promise<boolean>;
    getProcessInspectPort(clientId: string): Promise<number | undefined>;
}
export declare const IExtensionNodeClientService: unique symbol;
export interface IExtensionNodeClientService {
    getElectronMainThreadListenPath(clientId: string): Promise<string>;
    getAllExtensions(scan: string[], extensionCandidate: string[], localization: string, extraMetaData: IExtraMetaData): Promise<IExtensionMetaData[]>;
    createProcess(clientId: string, options: ICreateProcessOptions): Promise<void>;
    getExtension(extensionPath: string, localization: string, extraMetaData?: IExtraMetaData): Promise<IExtensionMetaData | undefined>;
    infoProcessNotExist(): void;
    infoProcessCrash(): void;
    restartExtProcessByClient(): void;
    disposeClientExtProcess(clientId: string, info: boolean): Promise<void>;
    updateLanguagePack(languageId: string, languagePackPath: string, storagePath: string): Promise<void>;
    setupNLSConfig(languageId: string, storagePath: string): Promise<void>;
    getOpenVSXRegistry(): Promise<string>;
    getLanguagePack(languageId: string): Promise<IExtensionLanguagePack | undefined>;
    pid(): Promise<number | null>;
}
export type ExtensionHostType = 'node' | 'worker';
export type ExtensionHostTypeUpperCase = 'Node.js' | 'Web Worker';
export interface ChangeExtensionOptions {
    upgrade: boolean;
    extensionPath: string;
    oldExtensionPath?: string;
    isBuiltin?: boolean;
}
/**
 * 管理不同进程内插件注册的 command 的运行环境及其调用
 */
export declare abstract class IExtCommandManagement {
    abstract registerProxyCommandExecutor(env: ExtensionHostType, proxyCommandExecutor: IMainThreadCommands): void;
    abstract executeExtensionCommand(env: ExtensionHostType, command: string, args: any[]): Promise<any>;
    /**
     * @param command command id
     * @param targetHost 目标插件进程的运行环境，默认 'node'
     */
    abstract registerExtensionCommandEnv(command: string, targetHost?: ExtensionHostType): IDisposable;
    abstract getExtensionCommandEnv(command: string): ExtensionHostType | undefined;
}
/**
 * 为插件市场面板提供数据/交互
 */
export declare abstract class AbstractExtensionManagementService {
    /**
     * @deprecated 建议直接用 AbstractExtInstanceManagementService#getExtensionInstances 后自行 map#toJSON 即可
     */
    abstract getAllExtensionJson(): IExtensionProps[];
    /**
     * 禁用插件
     */
    abstract postDisableExtension(extensionPath: string): Promise<void>;
    /**
     * 启用插件
     */
    abstract postEnableExtension(extensionPath: string): Promise<void>;
    /**
     * 安装插件之后开始激活
     */
    abstract postChangedExtension(options: ChangeExtensionOptions): Promise<void>;
    abstract postChangedExtension(upgrade: boolean, extensionPath: string, oldExtensionPath?: string): Promise<void>;
    abstract postChangedExtension(upgrade: boolean | ChangeExtensionOptions, extensionPath?: string, oldExtensionPath?: string): Promise<void>;
    /**
     * 卸载插件
     */
    abstract postUninstallExtension(extensionPath: string): Promise<void>;
    /**
     * 通过 extensionPath 获取插件实例
     */
    abstract getExtensionByPath(extensionPath: string): IExtension | undefined;
    /**
     * 通过 extension id 获取插件实例
     */
    abstract getExtensionByExtId(extensionId: string): IExtension | undefined;
    /**
     * 通过 extensionPath 获取插件实例序列化数据及从 node 层获取的 extraMetadata
     */
    abstract getExtensionProps(extensionPath: string, extraMetaData?: IExtraMetaData): Promise<IExtensionProps | undefined>;
}
export declare enum ERestartPolicy {
    /**
     * Always restart extension process
     */
    Always = "always",
    /**
     * Restart extension process when extension process is not running or not responding
     */
    WhenExit = "when-exit"
}
export declare abstract class ExtensionService {
    /**
     * 激活插件服务
     */
    abstract activate(): Promise<void>;
    /**
     * 重启插件进程
     */
    abstract restartExtProcess(restartPolicy?: ERestartPolicy): Promise<void>;
    /**
     * 激活插件, 给 Extension 实例使用
     */
    abstract activeExtension(extension: IExtension): Promise<void>;
    /**
     * 销毁插件
     */
    abstract disposeExtensions(): Promise<void>;
    /**
     * 执行插件命令
     */
    abstract executeExtensionCommand(command: string, args: any[]): Promise<void>;
    /**
     * @internal 提供获取所有运行中的插件的列表数据
     */
    abstract getActivatedExtensions(): Promise<{
        [key in ExtensionHostType]?: ActivatedExtension[];
    }>;
    abstract runExtensionContributes(): Promise<void>;
    eagerExtensionsActivated: Deferred<void>;
}
export declare abstract class ExtensionCapabilityRegistry {
    abstract getAllExtensions(): Promise<IExtensionMetaData[]>;
}
export declare const LANGUAGE_BUNDLE_FIELD = "languageBundle";
export interface JSONType {
    [key: string]: any;
}
export interface IExtension extends IExtensionProps {
    readonly contributes: IExtensionContributions & ISumiExtensionContributions;
    activate(visited?: Set<string>): any;
    enable(): void;
    reset(): void;
    toJSON(): IExtensionProps;
}
export declare const NO_ROOT_URI = "<none>";
export interface ContributesMap<T> {
    extensionId: string;
    contributes: T;
}
export declare abstract class VSCodeContributePoint<T extends JSONType = JSONType> extends Disposable {
    protected contributesMap: Array<ContributesMap<T>>;
    protected contributedMap: Array<ContributesMap<T>>;
    static schema: IJSONSchema;
    protected readonly iconService?: IIconService;
    abstract contribute(): void | Promise<void>;
    register(extensionId: string, contributes: T): void;
    hasUncontributedPoint(): boolean;
    afterContribute(): void;
    protected toIconClass(iconContrib: {
        [index in ThemeType]: string;
    } | string, type: IconType | undefined, basePath: string): string | undefined;
    protected getLocalizeFromNlsJSON(title: string, extensionId: string, languageId?: string): string;
    protected createLocalizedStr(title: string, extensionId: string): import("@opensumi/ide-core-common").ILocalizedStr;
}
export declare abstract class ExtensionContributesService extends WithEventBus {
    abstract ContributionPoints: (typeof VSCodeContributePoint)[];
    private logger;
    private lifecycleService;
    private readonly extensionsSchemaService;
    private injector;
    private contributedSet;
    private contributeQueue;
    private lifecycles;
    private getContributionCls;
    register(extensionId: string, contrib: JSONType): void;
    private runContributesByPhase;
    initialize(): Promise<void>;
}
export declare const CONTRIBUTE_NAME_KEY = "contribute_name";
export declare function Contributes(name: any): (target: any) => void;
export declare const LIFE_CYCLE_PHASE_KEY = "phase";
export declare function LifeCycle(name: LifeCyclePhase): (target: any) => void;
export declare const EXTENSION_EXTEND_SERVICE_PREFIX = "extension_extend_service";
export declare const MOCK_EXTENSION_EXTEND_PROXY_IDENTIFIER: import("@opensumi/ide-connection").ProxyIdentifier<unknown>;
export interface IExtensionHost {
    logger: IExtensionLogger;
    $activateExtension(id: string): Promise<void>;
    /**
     * 更新插件进程内的插件相关数据
     */
    $updateExtHostData(): Promise<void>;
    $getActivatedExtensions(): Promise<ActivatedExtensionJSON[]>;
    getExtensionExports(id: string): any;
    getExtensions(): Extension[];
    getExtension(extensionId: string): Extension<any, IExtensionHost> | undefined;
    isActivated(id: string): boolean;
    activateExtension(id: string): Promise<void>;
    extensionsChangeEmitter: Emitter<void>;
    storage: ExtHostStorage;
}
export interface IExtensionHostService extends IExtensionHost {
    $fireChangeEvent(): Promise<void>;
    init(): Promise<void>;
    close(): Promise<void>;
    getExtendExports(id: string): any;
    extensionsActivator: ExtensionsActivator;
    /**
     * 上报插件未捕获异常
     * @param error
     */
    reportUnexpectedError(error: Error): void;
}
export interface IExtensionWorkerHost extends IExtensionHost {
    staticServicePath: string;
}
export interface IExtendProxy {
    [key: string]: any;
}
export declare const WorkerHostAPIIdentifier: {
    ExtWorkerHostExtensionService: import("@opensumi/ide-connection").ProxyIdentifier<unknown>;
};
export declare enum ProcessMessageType {
    REPORTER = 0
}
export declare enum EXTENSION_ENABLE {
    ENABLE = 1,
    DISABLE = 0
}
export declare const EMIT_EXT_HOST_EVENT: {
    id: string;
};
export declare function getExtensionId(extensionId: string): string;
export declare enum ExtensionHostKind {
    NODE_HOST = 1,
    WORKER_HOST = 2
}
export declare const ExtensionHostProfilerServicePath = "ExtensionHostProfilerService";
export declare const ExtensionHostProfilerServiceToken: unique symbol;
export interface IExtensionHostProfilerService {
    $startProfile(clientId: string): Promise<void>;
    $stopProfile(clientId: string): Promise<boolean>;
    $saveLastProfile(filePath: string): Promise<void>;
}
export declare enum OutputType {
    STDOUT = 0,
    STDERR = 1
}
export interface Output {
    type: OutputType;
    data: string;
    format: string[];
}
export declare const IExtensionHostManager: unique symbol;
export interface IExtensionHostManager {
    init(): MaybePromise<void>;
    fork(modulePath: string, ...args: any[]): MaybePromise<number>;
    send(pid: number, message: string): MaybePromise<void>;
    isRunning(pid: number): MaybePromise<boolean>;
    treeKill(pid: number): MaybePromise<void>;
    kill(pid: number, signal?: string): MaybePromise<void>;
    isKilled(pid: number): MaybePromise<boolean>;
    findDebugPort(startPort: number, giveUpAfter: number, timeout: number): Promise<number>;
    onOutput(pid: number, listener: (output: Output) => void): MaybePromise<void>;
    onExit(pid: number, listener: (code: number, signal: string) => void): MaybePromise<void>;
    onMessage(pid: number, listener: (msg: any) => void): MaybePromise<void>;
    disposeProcess(pid: number): MaybePromise<void>;
    dispose(): MaybePromise<void>;
}
/**
 * 以下都是 fork 新的插件子进程的时候，传入的命令行参数的 key
 */
export declare const KT_PROCESS_SOCK_OPTION_KEY = "kt-process-sock-option";
export declare const KT_PROCESS_PRELOAD_KEY = "kt-process-preload";
export declare const KT_APP_CONFIG_KEY = "kt-app-config";
export interface SemanticTokenScopes {
    scopes?: {
        [selector: string]: string[];
    };
    language?: string;
}
export type SemanticTokenScopesSchema = Array<SemanticTokenScopes>;
export interface SemanticTokenType {
    id: string;
    description: string;
    superType?: string;
}
export type SemanticTokenTypeSchema = Array<SemanticTokenType>;
export interface SemanticTokenModifier {
    id: string;
    description: string;
}
export type SemanticTokenModifierSchema = Array<SemanticTokenModifier>;
export declare function validateTypeOrModifier(contribution: SemanticTokenType | SemanticTokenModifier, extensionPoint: string, logger: ILogger): boolean;
export declare const enum ExtensionContributePoint {
    Terminal = "terminal"
}
export interface IWalkthrough {
    id: string;
    title: string;
    description: string;
    order: number;
    source: string;
    isFeatured: boolean;
    next?: string;
    when: ContextKeyExpression;
    steps: IWalkthroughStep[];
    icon: {
        type: 'icon';
        icon: ThemeIcon;
    } | {
        type: 'image';
        path: string;
    };
}
export type IWalkthroughLoose = Omit<IWalkthrough, 'steps'> & {
    steps: (Omit<IWalkthroughStep, 'description'> & {
        description: string;
    })[];
};
export interface IWalkthroughStep {
    id: string;
    title: string;
    description: LinkedText[];
    category: string;
    when: ContextKeyExpression;
    order: number;
    completionEvents: string[];
    media: {
        type: 'image';
        path: {
            hcDark: URI;
            hcLight: URI;
            light: URI;
            dark: URI;
        };
        altText: string;
    } | {
        type: 'svg';
        path: URI;
        altText: string;
    } | {
        type: 'markdown';
        path: URI;
        base: URI;
        root: URI;
    };
}
export interface StepProgress {
    done: boolean;
}
export interface IResolvedWalkthroughStep extends IWalkthroughStep, StepProgress {
}
export declare namespace CompletionEventsType {
    const onLink = "onLink";
    const onEvent = "onEvent";
    const onView = "onView";
    const onSettingChanged = "onSettingChanged";
    const onContext = "onContext";
    const onStepSelected = "onStepSelected";
    const stepSelected = "stepSelected";
    const onCommand = "onCommand";
    const onExtensionInstalled = "onExtensionInstalled";
    const extensionInstalled = "extensionInstalled";
}
//# sourceMappingURL=extension.d.ts.map