Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/agentHost/common/agentHostFileSystemService.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';
7
import { AgentHostFileSystemProvider, type IRemoteFilesystemConnection } from '../../../../platform/agentHost/common/agentHostFileSystemProvider.js';
8
import { AGENT_HOST_LABEL_FORMATTER, AGENT_HOST_SCHEME } from '../../../../platform/agentHost/common/agentHostUri.js';
9
import { IFileService } from '../../../../platform/files/common/files.js';
10
import { InMemoryFileSystemProvider } from '../../../../platform/files/common/inMemoryFilesystemProvider.js';
11
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
12
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
13
import { ILabelService } from '../../../../platform/label/common/label.js';
14
15
/**
16
* Scheme used for the in-memory plugin filesystem backing synced customizations.
17
*
18
* URIs under this scheme are served by a registered {@link InMemoryFileSystemProvider}
19
* and are reachable by the agent host via `fetchContent`.
20
*/
21
export const SYNCED_CUSTOMIZATION_SCHEME = 'vscode-synced-customization';
22
23
export const IAgentHostFileSystemService = createDecorator<IAgentHostFileSystemService>('agentHostFileSystemService');
24
25
export interface IAgentHostFileSystemService {
26
readonly _serviceBrand: undefined;
27
28
/**
29
* Register a mapping from a URI authority to a connection so that
30
* `vscode-agent-host://[authority]/…` URIs resolve through this connection.
31
*/
32
registerAuthority(authority: string, connection: IRemoteFilesystemConnection): IDisposable;
33
34
/**
35
* Ensures the in-memory filesystem provider for synced customizations
36
* (`vscode-synced-customization:` scheme) is registered. Called lazily
37
* by {@link SyncedCustomizationBundler} — safe to call multiple times.
38
*/
39
ensureSyncedCustomizationProvider(): void;
40
}
41
42
class AgentHostFileSystemService extends Disposable implements IAgentHostFileSystemService {
43
declare readonly _serviceBrand: undefined;
44
45
private readonly _fsProvider: AgentHostFileSystemProvider;
46
private _syncedCustomizationProviderRegistered = false;
47
48
constructor(
49
@IFileService private readonly _fileService: IFileService,
50
@ILabelService labelService: ILabelService,
51
) {
52
super();
53
54
this._fsProvider = this._register(new AgentHostFileSystemProvider());
55
this._register(_fileService.registerProvider(AGENT_HOST_SCHEME, this._fsProvider));
56
this._register(labelService.registerFormatter(AGENT_HOST_LABEL_FORMATTER));
57
}
58
59
registerAuthority(authority: string, connection: IRemoteFilesystemConnection): IDisposable {
60
return this._fsProvider.registerAuthority(authority, connection);
61
}
62
63
ensureSyncedCustomizationProvider(): void {
64
if (!this._syncedCustomizationProviderRegistered) {
65
this._syncedCustomizationProviderRegistered = true;
66
const provider = this._register(new InMemoryFileSystemProvider());
67
this._register(this._fileService.registerProvider(SYNCED_CUSTOMIZATION_SCHEME, provider));
68
}
69
}
70
}
71
72
registerSingleton(IAgentHostFileSystemService, AgentHostFileSystemService, InstantiationType.Delayed);
73
74