"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAPIFactory = createAPIFactory;
const tslib_1 = require("tslib");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const const_1 = require("@opensumi/ide-core-common/lib/const");
const common_1 = require("../../../common");
const vscode_1 = require("../../../common/vscode");
const models_1 = require("../../../common/vscode/models");
const ext_host_api_impl_1 = require("../sumi/ext.host.api.impl");
const doc_1 = require("../vscode/doc");
const editor_host_1 = require("../vscode/editor/editor.host");
const ext_host_env_1 = require("../vscode/env/ext.host.env");
const workerEnvApiFactory_1 = require("../vscode/env/workerEnvApiFactory");
const ext_host_api_webview_1 = require("../vscode/ext.host.api.webview");
const ext_host_authentication_1 = require("../vscode/ext.host.authentication");
const ext_host_command_1 = require("../vscode/ext.host.command");
const ext_host_comments_1 = require("../vscode/ext.host.comments");
const ext_host_custom_editor_1 = require("../vscode/ext.host.custom-editor");
const ext_host_decoration_1 = require("../vscode/ext.host.decoration");
const ext_host_editor_tabs_1 = require("../vscode/ext.host.editor-tabs");
const ext_host_extensions_1 = require("../vscode/ext.host.extensions");
const ext_host_file_system_1 = require("../vscode/ext.host.file-system");
const ext_host_file_system_event_1 = require("../vscode/ext.host.file-system-event");
const ext_host_file_system_info_1 = require("../vscode/ext.host.file-system-info");
const ext_host_language_1 = require("../vscode/ext.host.language");
const ext_host_localization_1 = require("../vscode/ext.host.localization");
const ext_host_message_1 = require("../vscode/ext.host.message");
const ext_host_notebook_1 = require("../vscode/ext.host.notebook");
const ext_host_output_1 = require("../vscode/ext.host.output");
const ext_host_preference_1 = require("../vscode/ext.host.preference");
const ext_host_progress_1 = require("../vscode/ext.host.progress");
const ext_host_quickopen_1 = require("../vscode/ext.host.quickopen");
const ext_host_scm_1 = require("../vscode/ext.host.scm");
const ext_host_statusbar_1 = require("../vscode/ext.host.statusbar");
const ext_host_terminal_1 = require("../vscode/ext.host.terminal");
const ext_host_theming_1 = require("../vscode/ext.host.theming");
const ext_host_treeview_1 = require("../vscode/ext.host.treeview");
const ext_host_urls_1 = require("../vscode/ext.host.urls");
const ext_host_window_state_1 = require("../vscode/ext.host.window-state");
const ext_host_window_api_impl_1 = require("../vscode/ext.host.window.api.impl");
const ext_host_workspace_1 = require("../vscode/ext.host.workspace");
const ext_host_tasks_1 = require("../vscode/tasks/ext.host.tasks");
const workerExtTypes = tslib_1.__importStar(require("./worker.ext-types"));
function createAPIFactory(rpcProtocol, extensionService) {
    rpcProtocol.set(common_1.WorkerHostAPIIdentifier.ExtWorkerHostExtensionService, extensionService);
    const extHostDocs = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostDocuments, new doc_1.ExtensionDocumentDataManagerImpl(rpcProtocol));
    const extHostNotebook = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostNotebook, new ext_host_notebook_1.ExtensionNotebookDocumentManagerImpl(rpcProtocol, extHostDocs));
    const extHostCommands = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostCommands, new ext_host_command_1.ExtHostCommands(rpcProtocol));
    const extHostLanguages = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostLanguages, new ext_host_language_1.ExtHostLanguages(rpcProtocol, extHostDocs, extHostCommands, extensionService.logger));
    const extHostEditors = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostEditors, new editor_host_1.ExtensionHostEditorService(rpcProtocol, extHostDocs));
    const extHostMessage = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostMessage, new ext_host_message_1.ExtHostMessage(rpcProtocol));
    const extHostWorkspace = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostWorkspace, new ext_host_workspace_1.ExtHostWorkspace(rpcProtocol, extHostMessage, extHostDocs));
    const extHostFileSystemInfo = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostFileSystemInfo, new ext_host_file_system_info_1.ExtHostFileSystemInfo());
    const extHostFileSystem = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostFileSystem, new ext_host_file_system_1.ExtHostFileSystem(rpcProtocol, extHostFileSystemInfo));
    const extHostTerminal = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostTerminal, new ext_host_terminal_1.ExtHostTerminal(rpcProtocol));
    const extHostTasks = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostTasks, new ext_host_tasks_1.ExtHostTasks(rpcProtocol, extHostTerminal, extHostWorkspace));
    const extHostFileSystemEvent = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostFileSystemEvent, new ext_host_file_system_event_1.ExtHostFileSystemEvent(rpcProtocol, extHostDocs));
    const extHostPreference = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostPreference, new ext_host_preference_1.ExtHostPreference(rpcProtocol, extHostWorkspace));
    const extHostOutput = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostOutput, new ext_host_output_1.ExtHostOutput(rpcProtocol));
    const extHostWebview = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostWebview, new ext_host_api_webview_1.ExtHostWebviewService(rpcProtocol));
    const extHostWebviewView = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostWebviewView, new ext_host_api_webview_1.ExtHostWebviewViews(rpcProtocol, extHostWebview));
    const extHostTreeView = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostTreeView, new ext_host_treeview_1.ExtHostTreeViews(rpcProtocol, extHostCommands));
    const extHostWindowState = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostWindowState, new ext_host_window_state_1.ExtHostWindowState(rpcProtocol));
    const extHostDecorations = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostDecorations, new ext_host_decoration_1.ExtHostDecorations(rpcProtocol));
    const extHostStatusBar = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostStatusBar, new ext_host_statusbar_1.ExtHostStatusBar(rpcProtocol));
    const extHostQuickOpen = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostQuickOpen, new ext_host_quickopen_1.ExtHostQuickOpen(rpcProtocol, extHostWorkspace));
    const extHostWindow = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostWindow, new ext_host_window_api_impl_1.ExtHostWindow(rpcProtocol));
    const extHostProgress = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostProgress, new ext_host_progress_1.ExtHostProgress(rpcProtocol));
    const extHostUrls = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostUrls, new ext_host_urls_1.ExtHostUrls(rpcProtocol));
    const extHostComments = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostComments, new ext_host_comments_1.ExtHostComments(rpcProtocol, extHostCommands, extHostDocs));
    const extHostTheming = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostTheming, new ext_host_theming_1.ExtHostTheming(rpcProtocol));
    const extHostCustomEditor = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostCustomEditor, new ext_host_custom_editor_1.ExtHostCustomEditorImpl(rpcProtocol, extHostWebview, extHostDocs));
    const extHostEditorTabs = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostEditorTabs, new ext_host_editor_tabs_1.ExtHostEditorTabs(rpcProtocol));
    const extHostSCM = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostSCM, new ext_host_scm_1.ExtHostSCM(rpcProtocol, extHostCommands));
    const extHostAuthentication = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostAuthentication, new ext_host_authentication_1.ExtHostAuthentication(rpcProtocol));
    const extHostLocalization = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostLocalization, new ext_host_localization_1.ExtHostLocalization(rpcProtocol, extensionService.logger));
    const extHostEnv = rpcProtocol.set(vscode_1.ExtHostAPIIdentifier.ExtHostEnv, new ext_host_env_1.ExtHostEnv(rpcProtocol));
    // TODO: 目前 worker reporter 缺少一条通信链路，先默认实现
    const reporter = new ide_core_common_1.DefaultReporter();
    const sumiAPI = (0, ext_host_api_impl_1.createAPIFactory)(rpcProtocol, extensionService, 'worker', reporter);
    return (extension) => {
        var _a;
        return ({
            ...workerExtTypes,
            EventEmitter: ide_core_common_1.Emitter,
            CancellationTokenSource: ide_core_common_1.CancellationTokenSource,
            Event: ide_core_common_1.Event,
            ViewColumn: vscode_1.ViewColumn,
            OverviewRulerLane: models_1.OverviewRulerLane,
            TextEditorCursorStyle: vscode_1.TextEditorCursorStyle,
            TextEditorSelectionChangeKind: vscode_1.TextEditorSelectionChangeKind,
            version: ((_a = extHostEnv.getEnvValues()) === null || _a === void 0 ? void 0 : _a.customVSCodeEngineVersion) || const_1.DEFAULT_VSCODE_ENGINE_VERSION,
            // VS Code 纯前端插件 API
            // ENV 用处貌似比较少, 现有的实现依赖 node  模块，后面需要再重新实现
            env: (0, workerEnvApiFactory_1.createWorkerHostEnvAPIFactory)(rpcProtocol, extHostEnv),
            languages: (0, ext_host_language_1.createLanguagesApiFactory)(extHostLanguages, extHostNotebook, extension),
            extensions: (0, ext_host_extensions_1.createExtensionsApiFactory)(extensionService),
            workspace: (0, ext_host_workspace_1.createWorkspaceApiFactory)(extHostWorkspace, extHostPreference, extHostDocs, extHostNotebook, extHostFileSystem, extHostFileSystemEvent, extHostTasks, extension),
            scm: {
                get inputBox() {
                    return extHostSCM.getLastInputBox(extension); // Strict null override - Deprecated api
                },
                createSourceControl(id, label, rootUri) {
                    return extHostSCM.createSourceControl(extension, id, label, rootUri);
                },
                getSourceControl(extensionId, id) {
                    return extHostSCM.getSourceControl(extensionId, id);
                },
            },
            l10n: (0, ext_host_localization_1.createLocalizationApiFactory)(extHostLocalization, extension),
            window: (0, ext_host_window_api_impl_1.createWindowApiFactory)(extension, extHostEditors, extHostMessage, extHostWebview, extHostWebviewView, extHostTreeView, extHostWindowState, extHostDecorations, extHostStatusBar, extHostQuickOpen, extHostOutput, extHostTerminal, extHostWindow, extHostProgress, extHostUrls, extHostTheming, extHostCustomEditor, extHostEditorTabs),
            InlineCompletionItem: workerExtTypes.InlineSuggestion,
            InlineCompletionList: workerExtTypes.InlineSuggestionList,
            authentication: (0, ext_host_authentication_1.createAuthenticationApiFactory)(extension, extHostAuthentication),
            comments: (0, ext_host_comments_1.createCommentsApiFactory)(extension, extHostComments),
            InlineEdit: workerExtTypes.InlineEdit,
            InlineEditTriggerKind: workerExtTypes.InlineEditTriggerKind,
            // Sumi 扩展 API
            ...sumiAPI(extension),
        });
    };
}
//# sourceMappingURL=worker.host.api.impl.js.map