forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
230 lines (196 loc) · 8.41 KB
/
types.ts
File metadata and controls
230 lines (196 loc) · 8.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as fs from 'fs';
import * as fsextra from 'fs-extra';
import { SemVer } from 'semver';
import * as vscode from 'vscode';
import { Architecture, OSType } from '../utils/platform';
// We could use FileType from utils/filesystem.ts, but it's simpler this way.
export import FileType = vscode.FileType;
export import FileStat = vscode.FileStat;
export type ReadStream = fs.ReadStream;
export type WriteStream = fs.WriteStream;
//= ==========================
// registry
export enum RegistryHive {
HKCU,
HKLM,
}
export const IRegistry = Symbol('IRegistry');
export interface IRegistry {
getKeys(key: string, hive: RegistryHive, arch?: Architecture): Promise<string[]>;
getValue(key: string, hive: RegistryHive, arch?: Architecture, name?: string): Promise<string | undefined | null>;
}
//= ==========================
// platform
export const IPlatformService = Symbol('IPlatformService');
export interface IPlatformService {
readonly osType: OSType;
osRelease: string;
readonly pathVariableName: 'Path' | 'PATH';
readonly virtualEnvBinName: 'bin' | 'Scripts';
// convenience methods
readonly isWindows: boolean;
readonly isMac: boolean;
readonly isLinux: boolean;
readonly is64bit: boolean;
getVersion(): Promise<SemVer>;
}
//= ==========================
// temp FS
export type TemporaryFile = { filePath: string } & vscode.Disposable;
export interface ITempFileSystem {
createFile(suffix: string, mode?: number): Promise<TemporaryFile>;
}
//= ==========================
// FS paths
// The low-level file path operations used by the extension.
export interface IFileSystemPaths {
readonly sep: string;
join(...filenames: string[]): string;
dirname(filename: string): string;
basename(filename: string, suffix?: string): string;
normalize(filename: string): string;
normCase(filename: string): string;
}
// Where to fine executables.
//
// In particular this class provides all the tools needed to find
// executables, including through an environment variable.
export interface IExecutables {
delimiter: string;
envVar: string;
}
export const IFileSystemPathUtils = Symbol('IFileSystemPathUtils');
// A collection of high-level utilities related to filesystem paths.
export interface IFileSystemPathUtils {
readonly paths: IFileSystemPaths;
readonly executables: IExecutables;
readonly home: string;
// Return true if the two paths are equivalent on the current
// filesystem and false otherwise. On Windows this is significant.
// On non-Windows the filenames must always be exactly the same.
arePathsSame(path1: string, path2: string): boolean;
// Return the clean (displayable) form of the given filename.
getDisplayName(pathValue: string, cwd?: string): string;
}
//= ==========================
// filesystem operations
// The low-level filesystem operations on which the extension depends.
export interface IRawFileSystem {
pathExists(filename: string): Promise<boolean>;
// Get information about a file (resolve symlinks).
stat(filename: string): Promise<FileStat>;
// Get information about a file (do not resolve synlinks).
lstat(filename: string): Promise<FileStat>;
// Change a file's permissions.
chmod(filename: string, mode: string | number): Promise<void>;
// Move the file to a different location (and/or rename it).
move(src: string, tgt: string): Promise<void>;
//* **********************
// files
// Return the raw bytes of the given file.
readData(filename: string): Promise<Buffer>;
// Return the text of the given file (decoded from UTF-8).
readText(filename: string): Promise<string>;
// Write the given text to the file (UTF-8 encoded).
writeText(filename: string, data: string | Buffer): Promise<void>;
// Write the given text to the end of the file (UTF-8 encoded).
appendText(filename: string, text: string): Promise<void>;
// Copy a file.
copyFile(src: string, dest: string): Promise<void>;
// Delete a file.
rmfile(filename: string): Promise<void>;
//* **********************
// directories
// Create the directory and any missing parent directories.
mkdirp(dirname: string): Promise<void>;
// Delete the directory if empty.
rmdir(dirname: string): Promise<void>;
// Delete the directory and everything in it.
rmtree(dirname: string): Promise<void>;
// Return the contents of the directory.
listdir(dirname: string): Promise<[string, FileType][]>;
//* **********************
// not async
// Get information about a file (resolve symlinks).
statSync(filename: string): FileStat;
// Return the text of the given file (decoded from UTF-8).
readTextSync(filename: string): string;
// Create a streaming wrappr around an open file (for reading).
createReadStream(filename: string): ReadStream;
// Create a streaming wrappr around an open file (for writing).
createWriteStream(filename: string): WriteStream;
}
// High-level filesystem operations used by the extension.
export interface IFileSystemUtils {
readonly raw: IRawFileSystem;
readonly paths: IFileSystemPaths;
readonly pathUtils: IFileSystemPathUtils;
readonly tmp: ITempFileSystem;
//* **********************
// aliases
createDirectory(dirname: string): Promise<void>;
deleteDirectory(dirname: string): Promise<void>;
deleteFile(filename: string): Promise<void>;
//* **********************
// helpers
// Determine if the file exists, optionally requiring the type.
pathExists(filename: string, fileType?: FileType): Promise<boolean>;
// Determine if the regular file exists.
fileExists(filename: string): Promise<boolean>;
// Determine if the directory exists.
directoryExists(dirname: string): Promise<boolean>;
// Get all the directory's entries.
listdir(dirname: string): Promise<[string, FileType][]>;
// Get the paths of all immediate subdirectories.
getSubDirectories(dirname: string): Promise<string[]>;
// Get the paths of all immediately contained files.
getFiles(dirname: string): Promise<string[]>;
// Determine if the directory is read-only.
isDirReadonly(dirname: string): Promise<boolean>;
// Generate the sha512 hash for the file (based on timestamps).
getFileHash(filename: string): Promise<string>;
// Get the paths of all files matching the pattern.
search(globPattern: string): Promise<string[]>;
//* **********************
// helpers (non-async)
fileExistsSync(path: string): boolean;
}
// TODO: Later we will drop IFileSystem, switching usage to IFileSystemUtils.
// See https://github.com/microsoft/vscode-python/issues/8542.
export const IFileSystem = Symbol('IFileSystem');
export interface IFileSystem {
// path-related
directorySeparatorChar: string;
arePathsSame(path1: string, path2: string): boolean;
getDisplayName(path: string): string;
// "raw" operations
stat(filePath: string): Promise<FileStat>;
createDirectory(path: string): Promise<void>;
deleteDirectory(path: string): Promise<void>;
listdir(dirname: string): Promise<[string, FileType][]>;
readFile(filePath: string): Promise<string>;
readData(filePath: string): Promise<Buffer>;
writeFile(filePath: string, text: string | Buffer, options?: string | fsextra.WriteFileOptions): Promise<void>;
appendFile(filename: string, text: string | Buffer): Promise<void>;
copyFile(src: string, dest: string): Promise<void>;
deleteFile(filename: string): Promise<void>;
chmod(path: string, mode: string | number): Promise<void>;
move(src: string, tgt: string): Promise<void>;
// sync
readFileSync(filename: string): string;
createReadStream(path: string): fs.ReadStream;
createWriteStream(path: string): fs.WriteStream;
// utils
pathExists(path: string): Promise<boolean>;
fileExists(path: string): Promise<boolean>;
fileExistsSync(path: string): boolean;
directoryExists(path: string): Promise<boolean>;
getSubDirectories(rootDir: string): Promise<string[]>;
getFiles(rootDir: string): Promise<string[]>;
getFileHash(filePath: string): Promise<string>;
search(globPattern: string, cwd?: string, dot?: boolean): Promise<string[]>;
createTemporaryFile(extension: string, mode?: number): Promise<TemporaryFile>;
isDirReadonly(dirname: string): Promise<boolean>;
}