Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/vscode-node/newWorkspacePreviewFileSystemProvider.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 { Disposable, Event, EventEmitter, FileChangeEvent, FileStat, FileSystemError, FileSystemProvider, FileType, Uri } from 'vscode';
7
import { INewWorkspacePreviewContentManager } from '../node/newIntent';
8
9
10
export class NewWorkspacePreviewFileSystemProvider implements FileSystemProvider {
11
constructor(private readonly contentManager: INewWorkspacePreviewContentManager) { }
12
async stat(uri: Uri): Promise<FileStat> {
13
const node = this.contentManager.get(uri);
14
if (!node) {
15
throw FileSystemError.FileNotFound(uri);
16
}
17
18
const size = await node.content?.then((content) => content?.length) ?? 0;
19
return {
20
ctime: node.ctime ?? 0,
21
mtime: node.ctime ?? 0,
22
size: size,
23
type: node.children ? FileType.Directory : FileType.File
24
};
25
}
26
27
readDirectory(uri: Uri): [string, FileType][] | Thenable<[string, FileType][]> {
28
const node = this.contentManager.get(uri);
29
if (!node) {
30
throw FileSystemError.FileNotFound(uri);
31
}
32
33
return node.children?.map((child) => [child.name, child.children ? FileType.Directory : FileType.File]) ?? [];
34
}
35
36
async readFile(uri: Uri): Promise<Uint8Array> {
37
const node = this.contentManager.get(uri);
38
if (!node) {
39
throw FileSystemError.FileNotFound(uri);
40
}
41
42
let content: Uint8Array | undefined;
43
try {
44
content = await node.content;
45
} catch { }
46
return content ?? new Uint8Array();
47
}
48
49
// #region not implemented since this filesystem impl is readonly
50
private readonly _onDidChangeFile = new EventEmitter<FileChangeEvent[]>();
51
onDidChangeFile: Event<FileChangeEvent[]> = this._onDidChangeFile.event;
52
watch(uri: Uri, options: { readonly recursive: boolean; readonly excludes: readonly string[] }): Disposable {
53
return { dispose() { } };
54
}
55
createDirectory(uri: Uri): void | Thenable<void> {
56
throw FileSystemError.NoPermissions(uri);
57
}
58
writeFile(uri: Uri, content: Uint8Array, options: { readonly create: boolean; readonly overwrite: boolean }): void | Thenable<void> {
59
throw FileSystemError.NoPermissions(uri);
60
}
61
delete(uri: Uri, options: { readonly recursive: boolean }): void | Thenable<void> {
62
throw FileSystemError.NoPermissions(uri);
63
}
64
rename(oldUri: Uri, newUri: Uri, options: { readonly overwrite: boolean }): void | Thenable<void> {
65
throw FileSystemError.NoPermissions(newUri);
66
}
67
copy?(source: Uri, destination: Uri, options: { readonly overwrite: boolean }): void | Thenable<void> {
68
throw FileSystemError.NoPermissions(destination);
69
}
70
// #endregion
71
72
dispose(): void {
73
this._onDidChangeFile.dispose();
74
}
75
}
76
77