|
| 1 | +/** |
| 2 | + * @module ApiFactory |
| 3 | + * @description The main module for the `ApiFactory` service, which is |
| 4 | + * responsible for creating sandboxed `vscode` API objects for extensions. |
| 5 | + */ |
| 6 | + |
| 7 | +import { Context, Effect, Layer } from "effect"; |
| 8 | +import type { IExtensionDescription } from "vs/platform/extensions/common/extensions.js"; |
| 9 | +import type * as Vscode from "vscode"; |
| 10 | + |
| 11 | +import * as Service from "../../Service/mod.js"; |
| 12 | +import { CreateApiFactory } from "./CreateApiFactory.js"; |
| 13 | + |
| 14 | +/** |
| 15 | + * The interface for the `ApiFactory` service. |
| 16 | + */ |
| 17 | +export interface Interface { |
| 18 | + /** |
| 19 | + * Creates a new, sandboxed `vscode` API object for a specific extension. |
| 20 | + * @param Extension The full description of the extension requesting the API. |
| 21 | + * @returns A frozen `vscode` API object tailored for the extension. |
| 22 | + */ |
| 23 | + readonly Create: (Extension: IExtensionDescription) => typeof Vscode; |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * The `Context.Tag` for the `ApiFactory` service. |
| 28 | + */ |
| 29 | +export const Tag = Context.Tag<Interface>("ApiFactory"); |
| 30 | + |
| 31 | +/** |
| 32 | + * The live implementation `Layer` for the `ApiFactory` service. |
| 33 | + * |
| 34 | + * This layer has a comprehensive dependency graph, as it requires every |
| 35 | + * underlying service that contributes to the final `vscode` API object. It |
| 36 | + * injects all of these services into the `CreateApiFactory` function to |
| 37 | + * construct the final service implementation. |
| 38 | + */ |
| 39 | +export const Live = Layer.effect( |
| 40 | + Tag, |
| 41 | + Effect.gen(function* (_) { |
| 42 | + // --- Inject all necessary services --- |
| 43 | + const LogService = yield* _(Service.Log.Tag); |
| 44 | + const ProposedApiService = yield* _(Service.ProposedApi.Tag); |
| 45 | + const DeprecationService = yield* _(Service.ApiDeprecation.Tag); |
| 46 | + const CommandsService = yield* _(Service.Commands.Tag); |
| 47 | + const WorkspaceService = yield* _(Service.Workspace.Tag); |
| 48 | + const WindowService = yield* _(Service.Window.Tag); |
| 49 | + const LanguageFeaturesService = yield* _(Service.LanguageFeatures.Tag); |
| 50 | + const DebugService = yield* _(Service.Debug.Tag); |
| 51 | + const TasksService = yield* _(Service.Tasks.Tag); |
| 52 | + const ExtensionService = yield* _(Service.Extension.Tag); |
| 53 | + const WebviewPanelService = yield* _(Service.WebviewPanel.Tag); |
| 54 | + const CustomEditorService = yield* _(Service.CustomEditor.Tag); |
| 55 | + const TreeViewService = yield* _(Service.TreeView.Tag); |
| 56 | + const StatusBarService = yield* _(Service.StatusBar.Tag); |
| 57 | + // Add other services here as they are implemented. |
| 58 | + |
| 59 | + // --- Construct the factory with all its dependencies --- |
| 60 | + return CreateApiFactory( |
| 61 | + LogService, |
| 62 | + ProposedApiService, |
| 63 | + DeprecationService, |
| 64 | + CommandsService, |
| 65 | + WorkspaceService, |
| 66 | + WindowService, |
| 67 | + LanguageFeaturesService, |
| 68 | + DebugService, |
| 69 | + TasksService, |
| 70 | + ExtensionService, |
| 71 | + WebviewPanelService, |
| 72 | + CustomEditorService, |
| 73 | + TreeViewService, |
| 74 | + StatusBarService, |
| 75 | + ); |
| 76 | + }), |
| 77 | +); |
0 commit comments