Path: blob/main/src/vs/workbench/services/agentHost/common/agentHostFileSystemService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';6import { AgentHostFileSystemProvider, type IRemoteFilesystemConnection } from '../../../../platform/agentHost/common/agentHostFileSystemProvider.js';7import { AGENT_HOST_LABEL_FORMATTER, AGENT_HOST_SCHEME } from '../../../../platform/agentHost/common/agentHostUri.js';8import { IFileService } from '../../../../platform/files/common/files.js';9import { InMemoryFileSystemProvider } from '../../../../platform/files/common/inMemoryFilesystemProvider.js';10import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';11import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';12import { ILabelService } from '../../../../platform/label/common/label.js';1314/**15* Scheme used for the in-memory plugin filesystem backing synced customizations.16*17* URIs under this scheme are served by a registered {@link InMemoryFileSystemProvider}18* and are reachable by the agent host via `fetchContent`.19*/20export const SYNCED_CUSTOMIZATION_SCHEME = 'vscode-synced-customization';2122export const IAgentHostFileSystemService = createDecorator<IAgentHostFileSystemService>('agentHostFileSystemService');2324export interface IAgentHostFileSystemService {25readonly _serviceBrand: undefined;2627/**28* Register a mapping from a URI authority to a connection so that29* `vscode-agent-host://[authority]/…` URIs resolve through this connection.30*/31registerAuthority(authority: string, connection: IRemoteFilesystemConnection): IDisposable;3233/**34* Ensures the in-memory filesystem provider for synced customizations35* (`vscode-synced-customization:` scheme) is registered. Called lazily36* by {@link SyncedCustomizationBundler} — safe to call multiple times.37*/38ensureSyncedCustomizationProvider(): void;39}4041class AgentHostFileSystemService extends Disposable implements IAgentHostFileSystemService {42declare readonly _serviceBrand: undefined;4344private readonly _fsProvider: AgentHostFileSystemProvider;45private _syncedCustomizationProviderRegistered = false;4647constructor(48@IFileService private readonly _fileService: IFileService,49@ILabelService labelService: ILabelService,50) {51super();5253this._fsProvider = this._register(new AgentHostFileSystemProvider());54this._register(_fileService.registerProvider(AGENT_HOST_SCHEME, this._fsProvider));55this._register(labelService.registerFormatter(AGENT_HOST_LABEL_FORMATTER));56}5758registerAuthority(authority: string, connection: IRemoteFilesystemConnection): IDisposable {59return this._fsProvider.registerAuthority(authority, connection);60}6162ensureSyncedCustomizationProvider(): void {63if (!this._syncedCustomizationProviderRegistered) {64this._syncedCustomizationProviderRegistered = true;65const provider = this._register(new InMemoryFileSystemProvider());66this._register(this._fileService.registerProvider(SYNCED_CUSTOMIZATION_SCHEME, provider));67}68}69}7071registerSingleton(IAgentHostFileSystemService, AgentHostFileSystemService, InstantiationType.Delayed);727374