Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/node/copilot/pendingEditContentStore.ts
13399 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 { encodeHex, VSBuffer } from '../../../../base/common/buffer.js';
7
import { IDisposable } from '../../../../base/common/lifecycle.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { IFileService } from '../../../files/common/files.js';
10
import { InMemoryFileSystemProvider } from '../../../files/common/inMemoryFilesystemProvider.js';
11
12
/**
13
* URI scheme for transient file content backing tool-call write-permission
14
* previews. Files under this scheme live in an in-memory provider registered
15
* on the agent host's file service; content can be read/written through the
16
* file service just like any other resource.
17
*/
18
export const PENDING_EDIT_CONTENT_SCHEME = 'pending-edit-content';
19
20
/**
21
* Builds a `pending-edit-content:` URI identifying the proposed "after"
22
* content for a write permission request. The authority is a hex-encoded
23
* session URI so multiple concurrent sessions don't collide.
24
*/
25
export function buildPendingEditContentUri(sessionUri: string, toolCallId: string, filePath: string): URI {
26
return URI.from({
27
scheme: PENDING_EDIT_CONTENT_SCHEME,
28
authority: encodeHex(VSBuffer.fromString(sessionUri)).toString(),
29
path: `/${encodeURIComponent(toolCallId)}/${encodeHex(VSBuffer.fromString(filePath))}`,
30
});
31
}
32
33
/**
34
* Registers a fresh {@link InMemoryFileSystemProvider} for the
35
* `pending-edit-content:` scheme on the given file service. Callers use the
36
* returned disposable to unregister the provider.
37
*/
38
export function registerPendingEditContentProvider(fileService: IFileService): IDisposable {
39
const provider = new InMemoryFileSystemProvider();
40
const registration = fileService.registerProvider(PENDING_EDIT_CONTENT_SCHEME, provider);
41
return {
42
dispose() {
43
registration.dispose();
44
provider.dispose();
45
},
46
};
47
}
48
49
50