@codingame/monaco-vscode-files-service-override 5.1.2 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/files.js +378 -122
- package/index.js +1 -1
- package/package.json +2 -2
package/files.js
CHANGED
|
@@ -7,10 +7,10 @@ import { InMemoryFileSystemProvider } from 'vscode/vscode/vs/platform/files/comm
|
|
|
7
7
|
export { InMemoryFileSystemProvider } from 'vscode/vscode/vs/platform/files/common/inMemoryFilesystemProvider';
|
|
8
8
|
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
9
9
|
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
10
|
-
import { FileType, FilePermission, createFileSystemProviderError, FileSystemProviderErrorCode, FileSystemProviderError } from 'vscode/vscode/vs/platform/files/common/files';
|
|
10
|
+
import { FileType, FilePermission, createFileSystemProviderError, FileSystemProviderErrorCode, FileSystemProviderError, hasFileReadStreamCapability } from 'vscode/vscode/vs/platform/files/common/files';
|
|
11
11
|
export { FileChangeType, FilePermission, FileSystemProviderCapabilities, FileSystemProviderError, FileSystemProviderErrorCode, FileType } from 'vscode/vscode/vs/platform/files/common/files';
|
|
12
12
|
import { Disposable, DisposableStore, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
13
|
-
import { extUri,
|
|
13
|
+
import { extUri, basename, dirname } from 'vscode/vscode/vs/base/common/resources';
|
|
14
14
|
import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
|
|
15
15
|
import { HTMLFileSystemProvider } from 'vscode/vscode/vs/platform/files/browser/htmlFileSystemProvider';
|
|
16
16
|
export { HTMLFileSystemProvider } from 'vscode/vscode/vs/platform/files/browser/htmlFileSystemProvider';
|
|
@@ -26,23 +26,77 @@ import { FilesConfigurationService } from 'vscode/vscode/vs/workbench/services/f
|
|
|
26
26
|
import { IFilesConfigurationService } from 'vscode/vscode/vs/workbench/services/filesConfiguration/common/filesConfigurationService.service';
|
|
27
27
|
import { BrowserElevatedFileService } from './vscode/src/vs/workbench/services/files/browser/elevatedFileService.js';
|
|
28
28
|
import { IElevatedFileService } from 'vscode/vscode/vs/workbench/services/files/common/elevatedFileService.service';
|
|
29
|
+
import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
|
|
30
|
+
import { newWriteableStream } from 'vscode/vscode/vs/base/common/stream';
|
|
29
31
|
import { registerServiceInitializePreParticipant, checkServicesNotInitialized } from 'vscode/lifecycle';
|
|
30
32
|
import { logsPath } from 'vscode/workbench';
|
|
31
33
|
import 'vscode/vscode/vs/workbench/contrib/files/browser/files.contribution._configuration';
|
|
32
34
|
|
|
35
|
+
class RegisteredDirectory {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.type = FileType.Directory;
|
|
38
|
+
this._onDidChange = new Emitter();
|
|
39
|
+
this.onDidChange = this._onDidChange.event;
|
|
40
|
+
this._onDidDelete = new Emitter();
|
|
41
|
+
this.onDidDelete = this._onDidDelete.event;
|
|
42
|
+
this.ctime = Date.now();
|
|
43
|
+
this.mtime = Date.now();
|
|
44
|
+
this.type = FileType.Directory;
|
|
45
|
+
this.entries = new Map();
|
|
46
|
+
}
|
|
47
|
+
async stats() {
|
|
48
|
+
return {
|
|
49
|
+
ctime: this.ctime,
|
|
50
|
+
mtime: this.mtime,
|
|
51
|
+
size: 0,
|
|
52
|
+
type: FileType.Directory
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
delete() {
|
|
56
|
+
this._onDidDelete.fire();
|
|
57
|
+
}
|
|
58
|
+
addChild(name, node) {
|
|
59
|
+
this.entries.set(name, node);
|
|
60
|
+
this._onDidChange.fire();
|
|
61
|
+
const disposable = {
|
|
62
|
+
dispose: () => {
|
|
63
|
+
this.deleteChild(name);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
node.onDidDelete(() => {
|
|
67
|
+
disposable.dispose();
|
|
68
|
+
});
|
|
69
|
+
return disposable;
|
|
70
|
+
}
|
|
71
|
+
deleteChild(name) {
|
|
72
|
+
if (this.entries.delete(name)) {
|
|
73
|
+
this.mtime = Date.now();
|
|
74
|
+
this._onDidChange.fire();
|
|
75
|
+
if (this.entries.size === 0) {
|
|
76
|
+
this.delete();
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
getChildren(name) {
|
|
83
|
+
return this.entries.get(name);
|
|
84
|
+
}
|
|
85
|
+
read() {
|
|
86
|
+
return ( Array.from(this.entries.entries()).map(([name, child]) => [name, child.type]));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
33
89
|
class RegisteredFile {
|
|
34
90
|
constructor(uri, readonly) {
|
|
35
91
|
this.uri = uri;
|
|
36
92
|
this.readonly = readonly;
|
|
93
|
+
this.type = FileType.File;
|
|
37
94
|
this._onDidChange = new Emitter();
|
|
38
95
|
this.onDidChange = this._onDidChange.event;
|
|
39
96
|
this._onDidDelete = new Emitter();
|
|
40
97
|
this.onDidDelete = this._onDidDelete.event;
|
|
41
|
-
this._onDidRename = new Emitter();
|
|
42
|
-
this.onDidRename = this._onDidRename.event;
|
|
43
98
|
this.ctime = Date.now();
|
|
44
99
|
this.mtime = Date.now();
|
|
45
|
-
this.type = FileType.File;
|
|
46
100
|
this.onDidChange(() => {
|
|
47
101
|
this.mtime = Date.now();
|
|
48
102
|
});
|
|
@@ -56,22 +110,21 @@ class RegisteredFile {
|
|
|
56
110
|
permissions: this.readonly ? FilePermission.Readonly : undefined
|
|
57
111
|
};
|
|
58
112
|
}
|
|
59
|
-
async getSize() {
|
|
60
|
-
return (await this.read()).length;
|
|
61
|
-
}
|
|
62
113
|
async delete() {
|
|
114
|
+
if (this.readonly) {
|
|
115
|
+
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.FileWriteLocked);
|
|
116
|
+
}
|
|
63
117
|
this._onDidDelete.fire();
|
|
64
118
|
}
|
|
65
|
-
async rename(to) {
|
|
66
|
-
const previousUri = this.uri;
|
|
67
|
-
this.uri = to;
|
|
68
|
-
this._onDidRename.fire({ from: previousUri, to });
|
|
69
|
-
}
|
|
70
119
|
}
|
|
71
120
|
class RegisteredReadOnlyFile extends RegisteredFile {
|
|
72
|
-
constructor(uri, read) {
|
|
121
|
+
constructor(uri, read, size) {
|
|
73
122
|
super(uri, true);
|
|
74
123
|
this.read = read;
|
|
124
|
+
this.size = size;
|
|
125
|
+
}
|
|
126
|
+
async getSize() {
|
|
127
|
+
return this.size;
|
|
75
128
|
}
|
|
76
129
|
write() {
|
|
77
130
|
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.FileWriteLocked);
|
|
@@ -79,14 +132,60 @@ class RegisteredReadOnlyFile extends RegisteredFile {
|
|
|
79
132
|
async delete() {
|
|
80
133
|
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.FileWriteLocked);
|
|
81
134
|
}
|
|
82
|
-
|
|
135
|
+
}
|
|
136
|
+
class RegisteredUriFile extends RegisteredFile {
|
|
137
|
+
constructor(location, url, metadata) {
|
|
138
|
+
super(location, true);
|
|
139
|
+
this.url = url;
|
|
140
|
+
this.metadata = metadata;
|
|
141
|
+
}
|
|
142
|
+
async fetch() {
|
|
143
|
+
const response = await fetch(this.url, {
|
|
144
|
+
headers: this.metadata?.mimeType != null
|
|
145
|
+
? {
|
|
146
|
+
Accept: this.metadata.mimeType
|
|
147
|
+
}
|
|
148
|
+
: {}
|
|
149
|
+
});
|
|
150
|
+
if (response.status !== 200) {
|
|
151
|
+
throw new Error(response.statusText);
|
|
152
|
+
}
|
|
153
|
+
return response;
|
|
154
|
+
}
|
|
155
|
+
async getSize() {
|
|
156
|
+
return this.metadata?.size ?? 0;
|
|
157
|
+
}
|
|
158
|
+
async read() {
|
|
159
|
+
const response = await this.fetch();
|
|
160
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
161
|
+
}
|
|
162
|
+
async readStream() {
|
|
163
|
+
const response = await this.fetch();
|
|
164
|
+
return response.body;
|
|
165
|
+
}
|
|
166
|
+
write() {
|
|
167
|
+
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.FileWriteLocked);
|
|
168
|
+
}
|
|
169
|
+
async delete() {
|
|
83
170
|
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.FileWriteLocked);
|
|
84
171
|
}
|
|
85
172
|
}
|
|
173
|
+
const encoder = new TextEncoder();
|
|
174
|
+
function encode(data) {
|
|
175
|
+
if (data instanceof Uint8Array) {
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return encoder.encode(data);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
86
182
|
class RegisteredMemoryFile extends RegisteredFile {
|
|
87
183
|
constructor(uri, content) {
|
|
88
184
|
super(uri, false);
|
|
89
|
-
this.content = content;
|
|
185
|
+
this.content = encode(content);
|
|
186
|
+
}
|
|
187
|
+
async getSize() {
|
|
188
|
+
return this.content.length;
|
|
90
189
|
}
|
|
91
190
|
async read() {
|
|
92
191
|
return this.content;
|
|
@@ -96,148 +195,266 @@ class RegisteredMemoryFile extends RegisteredFile {
|
|
|
96
195
|
this._onDidChange.fire();
|
|
97
196
|
}
|
|
98
197
|
}
|
|
99
|
-
function addTrailingSlash(uri) {
|
|
100
|
-
if (!uri.endsWith('/')) {
|
|
101
|
-
return uri + '/';
|
|
102
|
-
}
|
|
103
|
-
return uri;
|
|
104
|
-
}
|
|
105
|
-
const encoder = new TextEncoder();
|
|
106
|
-
const decoder = new TextDecoder();
|
|
107
198
|
class RegisteredFileSystemProvider extends Disposable {
|
|
108
199
|
constructor(readonly) {
|
|
109
200
|
super();
|
|
201
|
+
this.memoryFdCounter = 0;
|
|
202
|
+
this.fdMemory = new Map();
|
|
110
203
|
this.onDidChangeCapabilities = Event.None;
|
|
111
204
|
this._onDidChangeFile = new Emitter();
|
|
112
205
|
this.onDidChangeFile = this._onDidChangeFile.event;
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
206
|
+
this._bufferedChanges = [];
|
|
207
|
+
this.rootByAuthority = new Map();
|
|
208
|
+
this.capabilities = 2 | 1024 | 16 ;
|
|
115
209
|
if (readonly) {
|
|
116
210
|
this.capabilities |= 2048 ;
|
|
117
211
|
}
|
|
118
212
|
}
|
|
119
|
-
|
|
120
|
-
|
|
213
|
+
async open(resource) {
|
|
214
|
+
const data = await this.readFile(resource);
|
|
215
|
+
const fd = this.memoryFdCounter++;
|
|
216
|
+
this.fdMemory.set(fd, data);
|
|
217
|
+
return fd;
|
|
218
|
+
}
|
|
219
|
+
async close(fd) {
|
|
220
|
+
this.fdMemory.delete(fd);
|
|
221
|
+
}
|
|
222
|
+
async read(fd, pos, data, offset, length) {
|
|
223
|
+
const memory = this.fdMemory.get(fd);
|
|
224
|
+
if (memory == null) {
|
|
225
|
+
throw createFileSystemProviderError('No file with that descriptor open', FileSystemProviderErrorCode.Unavailable);
|
|
226
|
+
}
|
|
227
|
+
const toWrite = VSBuffer.wrap(memory).slice(pos, pos + length);
|
|
228
|
+
data.set(toWrite.buffer, offset);
|
|
229
|
+
return toWrite.byteLength;
|
|
230
|
+
}
|
|
231
|
+
write(fd, pos, data, offset, length) {
|
|
232
|
+
const memory = this.fdMemory.get(fd);
|
|
233
|
+
if (memory == null) {
|
|
234
|
+
throw createFileSystemProviderError('No file with that descriptor open', FileSystemProviderErrorCode.Unavailable);
|
|
235
|
+
}
|
|
236
|
+
const toWrite = VSBuffer.wrap(data).slice(offset, offset + length);
|
|
237
|
+
memory.set(toWrite.buffer, pos);
|
|
238
|
+
return Promise.resolve(toWrite.byteLength);
|
|
239
|
+
}
|
|
240
|
+
_lookupRoot(authority) {
|
|
241
|
+
let root = this.rootByAuthority.get(authority);
|
|
242
|
+
if (root == null) {
|
|
243
|
+
root = new RegisteredDirectory();
|
|
244
|
+
this.rootByAuthority.set(authority, root);
|
|
245
|
+
}
|
|
246
|
+
return root;
|
|
247
|
+
}
|
|
248
|
+
_lookup(uri, silent) {
|
|
249
|
+
const parts = uri.path.split('/');
|
|
250
|
+
const root = this._lookupRoot(uri.authority);
|
|
251
|
+
let entry = root;
|
|
252
|
+
for (const part of parts) {
|
|
253
|
+
if (part.length === 0) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
let child;
|
|
257
|
+
if (entry instanceof RegisteredDirectory) {
|
|
258
|
+
child = entry.getChildren(part);
|
|
259
|
+
}
|
|
260
|
+
if (child == null) {
|
|
261
|
+
if (!silent) {
|
|
262
|
+
throw createFileSystemProviderError('file not found', FileSystemProviderErrorCode.FileNotFound);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
entry = child;
|
|
269
|
+
}
|
|
270
|
+
return entry;
|
|
271
|
+
}
|
|
272
|
+
_lookupAsDirectory(uri, silent) {
|
|
273
|
+
const entry = this._lookup(uri, silent);
|
|
274
|
+
if (entry instanceof RegisteredDirectory) {
|
|
275
|
+
return entry;
|
|
276
|
+
}
|
|
277
|
+
throw createFileSystemProviderError('file not a directory', FileSystemProviderErrorCode.FileNotADirectory);
|
|
278
|
+
}
|
|
279
|
+
_lookupAsFile(uri, silent) {
|
|
280
|
+
const entry = this._lookup(uri, silent);
|
|
281
|
+
if (entry != null && entry.type === FileType.File) {
|
|
282
|
+
return entry;
|
|
283
|
+
}
|
|
284
|
+
throw createFileSystemProviderError('file is a directory', FileSystemProviderErrorCode.FileIsADirectory);
|
|
121
285
|
}
|
|
122
286
|
registerFile(file) {
|
|
123
|
-
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
287
|
+
const parts = file.uri.path.split('/');
|
|
288
|
+
let directory = this._lookupRoot(file.uri.authority);
|
|
289
|
+
let uri = file.uri.with({ path: '/' });
|
|
290
|
+
for (const part of parts.slice(0, -1)) {
|
|
291
|
+
if (part === '') {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
uri = extUri.joinPath(uri, part);
|
|
295
|
+
let children = directory.getChildren(part);
|
|
296
|
+
if (children == null) {
|
|
297
|
+
const newDirectory = this.mkdirSync(uri);
|
|
298
|
+
children = newDirectory;
|
|
299
|
+
}
|
|
300
|
+
if (!(children instanceof RegisteredDirectory)) {
|
|
301
|
+
throw new Error(`file '${uri.toString()}' is not a directory`);
|
|
302
|
+
}
|
|
303
|
+
directory = children;
|
|
304
|
+
}
|
|
305
|
+
const name = parts[parts.length - 1];
|
|
306
|
+
if (directory.getChildren(name) != null) {
|
|
307
|
+
throw new Error(`file '${uri.toString()}' already exists`);
|
|
308
|
+
}
|
|
128
309
|
const disposableStore = new DisposableStore();
|
|
129
310
|
disposableStore.add(toDisposable(() => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
type: 2
|
|
135
|
-
}]);
|
|
136
|
-
}
|
|
311
|
+
this._fireSoon({
|
|
312
|
+
resource: file.uri,
|
|
313
|
+
type: 2
|
|
314
|
+
});
|
|
137
315
|
}));
|
|
138
316
|
disposableStore.add(file.onDidDelete(() => {
|
|
139
317
|
disposableStore.dispose();
|
|
140
318
|
}));
|
|
141
319
|
disposableStore.add(file.onDidChange(() => {
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}));
|
|
147
|
-
disposableStore.add(file.onDidRename(({ from, to }) => {
|
|
148
|
-
if (this.files.get(this.formatUri(from)) === file) {
|
|
149
|
-
this.files.delete(this.formatUri(from));
|
|
150
|
-
this.files.set(this.formatUri(to), file);
|
|
151
|
-
this._onDidChangeFile.fire([{
|
|
152
|
-
resource: from,
|
|
153
|
-
type: 2
|
|
154
|
-
}, {
|
|
155
|
-
resource: to,
|
|
156
|
-
type: 1
|
|
157
|
-
}]);
|
|
158
|
-
}
|
|
320
|
+
this._fireSoon({
|
|
321
|
+
resource: file.uri,
|
|
322
|
+
type: 0
|
|
323
|
+
});
|
|
159
324
|
}));
|
|
325
|
+
disposableStore.add(directory.addChild(name, file));
|
|
326
|
+
this._fireSoon({
|
|
327
|
+
resource: file.uri,
|
|
328
|
+
type: 1
|
|
329
|
+
});
|
|
160
330
|
return disposableStore;
|
|
161
331
|
}
|
|
162
332
|
async stat(resource) {
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
for (const handledUri of handledUris) {
|
|
170
|
-
if (handledUri.startsWith(addTrailingSlash(resourceUri))) {
|
|
171
|
-
return {
|
|
172
|
-
ctime: Date.now(),
|
|
173
|
-
mtime: Date.now(),
|
|
174
|
-
size: 0,
|
|
175
|
-
type: FileType.Directory
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
throw createFileSystemProviderError('file not found', FileSystemProviderErrorCode.FileNotFound);
|
|
333
|
+
const node = this._lookup(resource, false);
|
|
334
|
+
return node.stats();
|
|
335
|
+
}
|
|
336
|
+
readdirSync(resource) {
|
|
337
|
+
const directory = this._lookupAsDirectory(resource, false);
|
|
338
|
+
return directory.read();
|
|
180
339
|
}
|
|
181
340
|
async readdir(resource) {
|
|
182
|
-
|
|
183
|
-
.map(uri => ( URI.parse(uri))))
|
|
184
|
-
.filter(uri => uri.authority === resource.authority && uri.path.startsWith(addTrailingSlash(resource.path)))
|
|
185
|
-
.map(uri => extUri.relativePath(resource, uri)));
|
|
186
|
-
const files = includedPaths.filter(path => !path.includes('/'));
|
|
187
|
-
const directories = ( includedPaths.filter(path => path.includes('/')).map(path => path.slice(0, path.indexOf('/'))));
|
|
188
|
-
return [
|
|
189
|
-
...( files.map(path => [
|
|
190
|
-
path,
|
|
191
|
-
FileType.File
|
|
192
|
-
])),
|
|
193
|
-
...( directories.map(path => [
|
|
194
|
-
path,
|
|
195
|
-
FileType.Directory
|
|
196
|
-
]))
|
|
197
|
-
];
|
|
341
|
+
return this.readdirSync(resource);
|
|
198
342
|
}
|
|
199
343
|
async readFile(resource) {
|
|
200
|
-
const file = this.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
344
|
+
const file = this._lookupAsFile(resource, false);
|
|
345
|
+
return await file.read();
|
|
346
|
+
}
|
|
347
|
+
readFileStream(resource, opts, token) {
|
|
348
|
+
const file = this._lookupAsFile(resource, false);
|
|
349
|
+
const stream = newWriteableStream(data => VSBuffer.concat(( data.map(data => VSBuffer.wrap(data)))).buffer, {
|
|
350
|
+
highWaterMark: 10
|
|
351
|
+
});
|
|
352
|
+
void (async () => {
|
|
353
|
+
try {
|
|
354
|
+
if (file.readStream == null || typeof opts.length === 'number' || typeof opts.position === 'number') {
|
|
355
|
+
let buffer = await file.read();
|
|
356
|
+
if (typeof opts.position === 'number') {
|
|
357
|
+
buffer = buffer.slice(opts.position);
|
|
358
|
+
}
|
|
359
|
+
if (typeof opts.length === 'number') {
|
|
360
|
+
buffer = buffer.slice(0, opts.length);
|
|
361
|
+
}
|
|
362
|
+
stream.end(buffer);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
const reader = (await file.readStream()).getReader();
|
|
366
|
+
let res = await reader.read();
|
|
367
|
+
while (!res.done) {
|
|
368
|
+
if (token.isCancellationRequested) {
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
await stream.write(res.value);
|
|
372
|
+
if (token.isCancellationRequested) {
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
res = await reader.read();
|
|
376
|
+
}
|
|
377
|
+
stream.end(undefined);
|
|
378
|
+
}
|
|
205
379
|
}
|
|
206
|
-
|
|
207
|
-
|
|
380
|
+
catch (error) {
|
|
381
|
+
stream.error(createFileSystemProviderError(error, FileSystemProviderErrorCode.Unknown));
|
|
382
|
+
stream.end();
|
|
208
383
|
}
|
|
209
|
-
}
|
|
210
|
-
|
|
384
|
+
})();
|
|
385
|
+
return stream;
|
|
211
386
|
}
|
|
212
387
|
watch() {
|
|
213
388
|
return Disposable.None;
|
|
214
389
|
}
|
|
215
|
-
async writeFile(resource, content) {
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
390
|
+
async writeFile(resource, content, opts) {
|
|
391
|
+
const node = this._lookup(resource, true);
|
|
392
|
+
if (node != null && !(node instanceof RegisteredFile)) {
|
|
393
|
+
throw createFileSystemProviderError('file is directory', FileSystemProviderErrorCode.FileIsADirectory);
|
|
394
|
+
}
|
|
395
|
+
if (node == null) {
|
|
396
|
+
throw createFileSystemProviderError('file not found', FileSystemProviderErrorCode.FileNotFound);
|
|
397
|
+
}
|
|
398
|
+
if (!opts.overwrite) {
|
|
399
|
+
throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
|
|
220
400
|
}
|
|
401
|
+
await node.write(content);
|
|
402
|
+
}
|
|
403
|
+
async rename() {
|
|
221
404
|
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.NoPermissions);
|
|
222
405
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
await file.delete();
|
|
227
|
-
return;
|
|
406
|
+
mkdirSync(resource) {
|
|
407
|
+
if (this._lookup(resource, true) != null) {
|
|
408
|
+
throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
|
|
228
409
|
}
|
|
229
|
-
|
|
410
|
+
const basename$1 = basename(resource);
|
|
411
|
+
const dirname$1 = dirname(resource);
|
|
412
|
+
const parent = this._lookupAsDirectory(dirname$1, false);
|
|
413
|
+
const directory = new RegisteredDirectory();
|
|
414
|
+
const disposable = new DisposableStore();
|
|
415
|
+
disposable.add(directory.onDidDelete(() => {
|
|
416
|
+
disposable.dispose();
|
|
417
|
+
this._fireSoon({
|
|
418
|
+
resource,
|
|
419
|
+
type: 2
|
|
420
|
+
});
|
|
421
|
+
}));
|
|
422
|
+
disposable.add(directory.onDidChange(() => {
|
|
423
|
+
this._fireSoon({
|
|
424
|
+
resource,
|
|
425
|
+
type: 0
|
|
426
|
+
});
|
|
427
|
+
}));
|
|
428
|
+
parent.addChild(basename$1, directory);
|
|
429
|
+
this._fireSoon({ type: 1 , resource });
|
|
430
|
+
return directory;
|
|
230
431
|
}
|
|
231
|
-
async
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
432
|
+
async mkdir() {
|
|
433
|
+
throw createFileSystemProviderError('Can\' create a directory', FileSystemProviderErrorCode.NoPermissions);
|
|
434
|
+
}
|
|
435
|
+
deleteSync(resource) {
|
|
436
|
+
const node = this._lookup(resource, true);
|
|
437
|
+
if (node == null) {
|
|
438
|
+
throw createFileSystemProviderError('Not found', FileSystemProviderErrorCode.FileNotFound);
|
|
236
439
|
}
|
|
237
|
-
|
|
440
|
+
else if (node.type === FileType.Directory) {
|
|
441
|
+
throw createFileSystemProviderError('Can\'t delete a directory', FileSystemProviderErrorCode.NoPermissions);
|
|
442
|
+
}
|
|
443
|
+
node.delete();
|
|
238
444
|
}
|
|
239
|
-
async
|
|
240
|
-
|
|
445
|
+
async delete(resource) {
|
|
446
|
+
this.deleteSync(resource);
|
|
447
|
+
}
|
|
448
|
+
_fireSoon(...changes) {
|
|
449
|
+
this._bufferedChanges.push(...changes);
|
|
450
|
+
if (this._fireSoonHandle != null) {
|
|
451
|
+
clearTimeout(this._fireSoonHandle);
|
|
452
|
+
this._fireSoonHandle = undefined;
|
|
453
|
+
}
|
|
454
|
+
this._fireSoonHandle = window.setTimeout(() => {
|
|
455
|
+
this._onDidChangeFile.fire(this._bufferedChanges);
|
|
456
|
+
this._bufferedChanges.length = 0;
|
|
457
|
+
}, 5);
|
|
241
458
|
}
|
|
242
459
|
}
|
|
243
460
|
function isFullfiled(result) {
|
|
@@ -251,7 +468,7 @@ class OverlayFileSystemProvider {
|
|
|
251
468
|
this.onDidChangeFile = this._onDidChangeFile.event;
|
|
252
469
|
this._onDidChangeOverlays = new Emitter();
|
|
253
470
|
this.onDidChangeOverlays = this._onDidChangeOverlays.event;
|
|
254
|
-
this.capabilities = 2 | 1024 ;
|
|
471
|
+
this.capabilities = 2 | 1024 | 16 ;
|
|
255
472
|
}
|
|
256
473
|
register(priority, provider) {
|
|
257
474
|
const item = { priority, provider };
|
|
@@ -299,6 +516,29 @@ class OverlayFileSystemProvider {
|
|
|
299
516
|
}
|
|
300
517
|
throw firstError;
|
|
301
518
|
}
|
|
519
|
+
readFromDelegatesSync(caller) {
|
|
520
|
+
if (this.delegates.length === 0) {
|
|
521
|
+
throw createFileSystemProviderError('No delegate', FileSystemProviderErrorCode.Unavailable);
|
|
522
|
+
}
|
|
523
|
+
let firstError;
|
|
524
|
+
for (const delegate of this.delegates) {
|
|
525
|
+
try {
|
|
526
|
+
return caller(delegate);
|
|
527
|
+
}
|
|
528
|
+
catch (err) {
|
|
529
|
+
firstError ?? (firstError = err);
|
|
530
|
+
if (err instanceof FileSystemProviderError && [
|
|
531
|
+
FileSystemProviderErrorCode.NoPermissions,
|
|
532
|
+
FileSystemProviderErrorCode.FileNotFound,
|
|
533
|
+
FileSystemProviderErrorCode.Unavailable
|
|
534
|
+
].includes(err.code)) {
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
throw err;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
throw firstError;
|
|
541
|
+
}
|
|
302
542
|
async writeToDelegates(caller) {
|
|
303
543
|
if (this.delegates.length === 0) {
|
|
304
544
|
throw createFileSystemProviderError('No delegate', FileSystemProviderErrorCode.Unavailable);
|
|
@@ -336,6 +576,22 @@ class OverlayFileSystemProvider {
|
|
|
336
576
|
async readFile(resource) {
|
|
337
577
|
return this.readFromDelegates(delegate => delegate.readFile(resource));
|
|
338
578
|
}
|
|
579
|
+
readFileStream(resource, opts, token) {
|
|
580
|
+
return this.readFromDelegatesSync(delegate => {
|
|
581
|
+
if (hasFileReadStreamCapability(delegate)) {
|
|
582
|
+
return delegate.readFileStream(resource, opts, token);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
const stream = newWriteableStream(data => VSBuffer.concat(( data.map(data => VSBuffer.wrap(data)))).buffer);
|
|
586
|
+
delegate.readFile(resource).then(data => {
|
|
587
|
+
stream.end(data);
|
|
588
|
+
}, err => {
|
|
589
|
+
stream.error(err);
|
|
590
|
+
});
|
|
591
|
+
return stream;
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
339
595
|
async readdir(resource) {
|
|
340
596
|
const results = await Promise.allSettled(( this.delegates.map(async (delegate) => delegate.readdir(resource))));
|
|
341
597
|
if (!( results.some(isFullfiled))) {
|
|
@@ -502,8 +758,8 @@ function registerCustomProvider(scheme, provider) {
|
|
|
502
758
|
checkServicesNotInitialized();
|
|
503
759
|
providers[scheme] = provider;
|
|
504
760
|
}
|
|
505
|
-
function registerExtensionFile(
|
|
506
|
-
return extensionFileSystemProvider.registerFile(
|
|
761
|
+
function registerExtensionFile(file) {
|
|
762
|
+
return extensionFileSystemProvider.registerFile(file);
|
|
507
763
|
}
|
|
508
764
|
async function initFile(file, content, options) {
|
|
509
765
|
checkServicesNotInitialized();
|
|
@@ -581,4 +837,4 @@ function registerFileSystemOverlay(priority, provider) {
|
|
|
581
837
|
return overlayProvider.register(priority, provider);
|
|
582
838
|
}
|
|
583
839
|
|
|
584
|
-
export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, IndexedDBFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, createIndexedDBProviders, getServiceOverride as default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider };
|
|
840
|
+
export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, IndexedDBFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, RegisteredUriFile, createIndexedDBProviders, getServiceOverride as default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider };
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, createIndexedDBProviders, default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider } from './files.js';
|
|
1
|
+
export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, RegisteredUriFile, createIndexedDBProviders, default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider } from './files.js';
|
|
2
2
|
export { FileChangeType, FilePermission, FileSystemProviderCapabilities, FileSystemProviderError, FileSystemProviderErrorCode, FileType } from 'vscode/vscode/vs/platform/files/common/files';
|
|
3
3
|
export { HTMLFileSystemProvider } from 'vscode/vscode/vs/platform/files/browser/htmlFileSystemProvider';
|
|
4
4
|
export { InMemoryFileSystemProvider } from 'vscode/vscode/vs/platform/files/common/inMemoryFilesystemProvider';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-files-service-override",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"vscode": "npm:@codingame/monaco-vscode-api@5.
|
|
29
|
+
"vscode": "npm:@codingame/monaco-vscode-api@5.3.0"
|
|
30
30
|
}
|
|
31
31
|
}
|