Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/html-language-features/client/src/requests.ts
3320 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 { Uri, workspace, Disposable } from 'vscode';
7
import { RequestType, BaseLanguageClient } from 'vscode-languageclient';
8
import { Runtime } from './htmlClient';
9
10
export namespace FsStatRequest {
11
export const type: RequestType<string, FileStat, any> = new RequestType('fs/stat');
12
}
13
14
export namespace FsReadDirRequest {
15
export const type: RequestType<string, [string, FileType][], any> = new RequestType('fs/readDir');
16
}
17
18
export function serveFileSystemRequests(client: BaseLanguageClient, runtime: Runtime): Disposable {
19
const disposables = [];
20
disposables.push(client.onRequest(FsReadDirRequest.type, (uriString: string) => {
21
const uri = Uri.parse(uriString);
22
if (uri.scheme === 'file' && runtime.fileFs) {
23
return runtime.fileFs.readDirectory(uriString);
24
}
25
return workspace.fs.readDirectory(uri);
26
}));
27
disposables.push(client.onRequest(FsStatRequest.type, (uriString: string) => {
28
const uri = Uri.parse(uriString);
29
if (uri.scheme === 'file' && runtime.fileFs) {
30
return runtime.fileFs.stat(uriString);
31
}
32
return workspace.fs.stat(uri);
33
}));
34
return Disposable.from(...disposables);
35
}
36
37
export enum FileType {
38
/**
39
* The file type is unknown.
40
*/
41
Unknown = 0,
42
/**
43
* A regular file.
44
*/
45
File = 1,
46
/**
47
* A directory.
48
*/
49
Directory = 2,
50
/**
51
* A symbolic link to a file.
52
*/
53
SymbolicLink = 64
54
}
55
export interface FileStat {
56
/**
57
* The type of the file, e.g. is a regular file, a directory, or symbolic link
58
* to a file.
59
*/
60
type: FileType;
61
/**
62
* The creation timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
63
*/
64
ctime: number;
65
/**
66
* The modification timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
67
*/
68
mtime: number;
69
/**
70
* The size in bytes.
71
*/
72
size: number;
73
}
74
75
export interface FileSystemProvider {
76
stat(uri: string): Promise<FileStat>;
77
readDirectory(uri: string): Promise<[string, FileType][]>;
78
}
79
80