@codingame/monaco-vscode-files-service-override 5.1.2-segmenter.1 → 5.2.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 -116
- 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,142 +195,266 @@ class RegisteredMemoryFile extends RegisteredFile {
|
|
|
96
195
|
this._onDidChange.fire();
|
|
97
196
|
}
|
|
98
197
|
}
|
|
99
|
-
const encoder = new TextEncoder();
|
|
100
|
-
const decoder = new TextDecoder();
|
|
101
198
|
class RegisteredFileSystemProvider extends Disposable {
|
|
102
199
|
constructor(readonly) {
|
|
103
200
|
super();
|
|
201
|
+
this.memoryFdCounter = 0;
|
|
202
|
+
this.fdMemory = new Map();
|
|
104
203
|
this.onDidChangeCapabilities = Event.None;
|
|
105
204
|
this._onDidChangeFile = new Emitter();
|
|
106
205
|
this.onDidChangeFile = this._onDidChangeFile.event;
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
206
|
+
this._bufferedChanges = [];
|
|
207
|
+
this.rootByAuthority = new Map();
|
|
208
|
+
this.capabilities = 2 | 1024 | 16 ;
|
|
109
209
|
if (readonly) {
|
|
110
210
|
this.capabilities |= 2048 ;
|
|
111
211
|
}
|
|
112
212
|
}
|
|
113
|
-
|
|
114
|
-
|
|
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);
|
|
115
285
|
}
|
|
116
286
|
registerFile(file) {
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
}
|
|
122
309
|
const disposableStore = new DisposableStore();
|
|
123
310
|
disposableStore.add(toDisposable(() => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
type: 2
|
|
129
|
-
}]);
|
|
130
|
-
}
|
|
311
|
+
this._fireSoon({
|
|
312
|
+
resource: file.uri,
|
|
313
|
+
type: 2
|
|
314
|
+
});
|
|
131
315
|
}));
|
|
132
316
|
disposableStore.add(file.onDidDelete(() => {
|
|
133
317
|
disposableStore.dispose();
|
|
134
318
|
}));
|
|
135
319
|
disposableStore.add(file.onDidChange(() => {
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}));
|
|
141
|
-
disposableStore.add(file.onDidRename(({ from, to }) => {
|
|
142
|
-
if (this.files.get(this.formatUri(from)) === file) {
|
|
143
|
-
this.files.delete(this.formatUri(from));
|
|
144
|
-
this.files.set(this.formatUri(to), file);
|
|
145
|
-
this._onDidChangeFile.fire([{
|
|
146
|
-
resource: from,
|
|
147
|
-
type: 2
|
|
148
|
-
}, {
|
|
149
|
-
resource: to,
|
|
150
|
-
type: 1
|
|
151
|
-
}]);
|
|
152
|
-
}
|
|
320
|
+
this._fireSoon({
|
|
321
|
+
resource: file.uri,
|
|
322
|
+
type: 0
|
|
323
|
+
});
|
|
153
324
|
}));
|
|
325
|
+
disposableStore.add(directory.addChild(name, file));
|
|
326
|
+
this._fireSoon({
|
|
327
|
+
resource: file.uri,
|
|
328
|
+
type: 1
|
|
329
|
+
});
|
|
154
330
|
return disposableStore;
|
|
155
331
|
}
|
|
156
332
|
async stat(resource) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for (const handledUri of handledUris) {
|
|
164
|
-
if (handledUri.startsWith(resourceUri + '/')) {
|
|
165
|
-
return {
|
|
166
|
-
ctime: Date.now(),
|
|
167
|
-
mtime: Date.now(),
|
|
168
|
-
size: 0,
|
|
169
|
-
type: FileType.Directory
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
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();
|
|
174
339
|
}
|
|
175
340
|
async readdir(resource) {
|
|
176
|
-
|
|
177
|
-
.map(uri => ( URI.parse(uri))))
|
|
178
|
-
.filter(uri => uri.authority === resource.authority && uri.path.startsWith(resource.path + '/'))
|
|
179
|
-
.map(uri => extUri.relativePath(resource, uri)));
|
|
180
|
-
const files = includedPaths.filter(path => !path.includes('/'));
|
|
181
|
-
const directories = ( includedPaths.filter(path => path.includes('/')).map(path => path.slice(0, path.indexOf('/'))));
|
|
182
|
-
return [
|
|
183
|
-
...( files.map(path => [
|
|
184
|
-
path,
|
|
185
|
-
FileType.File
|
|
186
|
-
])),
|
|
187
|
-
...( directories.map(path => [
|
|
188
|
-
path,
|
|
189
|
-
FileType.Directory
|
|
190
|
-
]))
|
|
191
|
-
];
|
|
341
|
+
return this.readdirSync(resource);
|
|
192
342
|
}
|
|
193
343
|
async readFile(resource) {
|
|
194
|
-
const file = this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
}
|
|
199
379
|
}
|
|
200
|
-
|
|
201
|
-
|
|
380
|
+
catch (error) {
|
|
381
|
+
stream.error(createFileSystemProviderError(error, FileSystemProviderErrorCode.Unknown));
|
|
382
|
+
stream.end();
|
|
202
383
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
384
|
+
})();
|
|
385
|
+
return stream;
|
|
205
386
|
}
|
|
206
387
|
watch() {
|
|
207
388
|
return Disposable.None;
|
|
208
389
|
}
|
|
209
|
-
async writeFile(resource, content) {
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
return;
|
|
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);
|
|
214
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);
|
|
400
|
+
}
|
|
401
|
+
await node.write(content);
|
|
402
|
+
}
|
|
403
|
+
async rename() {
|
|
215
404
|
throw createFileSystemProviderError('Not allowed', FileSystemProviderErrorCode.NoPermissions);
|
|
216
405
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
await file.delete();
|
|
221
|
-
return;
|
|
406
|
+
mkdirSync(resource) {
|
|
407
|
+
if (this._lookup(resource, true) != null) {
|
|
408
|
+
throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
|
|
222
409
|
}
|
|
223
|
-
|
|
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;
|
|
224
431
|
}
|
|
225
|
-
async
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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);
|
|
439
|
+
}
|
|
440
|
+
else if (node.type === FileType.Directory) {
|
|
441
|
+
throw createFileSystemProviderError('Can\'t delete a directory', FileSystemProviderErrorCode.NoPermissions);
|
|
230
442
|
}
|
|
231
|
-
|
|
443
|
+
node.delete();
|
|
232
444
|
}
|
|
233
|
-
async
|
|
234
|
-
|
|
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);
|
|
235
458
|
}
|
|
236
459
|
}
|
|
237
460
|
function isFullfiled(result) {
|
|
@@ -245,7 +468,7 @@ class OverlayFileSystemProvider {
|
|
|
245
468
|
this.onDidChangeFile = this._onDidChangeFile.event;
|
|
246
469
|
this._onDidChangeOverlays = new Emitter();
|
|
247
470
|
this.onDidChangeOverlays = this._onDidChangeOverlays.event;
|
|
248
|
-
this.capabilities = 2 | 1024 ;
|
|
471
|
+
this.capabilities = 2 | 1024 | 16 ;
|
|
249
472
|
}
|
|
250
473
|
register(priority, provider) {
|
|
251
474
|
const item = { priority, provider };
|
|
@@ -293,6 +516,29 @@ class OverlayFileSystemProvider {
|
|
|
293
516
|
}
|
|
294
517
|
throw firstError;
|
|
295
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
|
+
}
|
|
296
542
|
async writeToDelegates(caller) {
|
|
297
543
|
if (this.delegates.length === 0) {
|
|
298
544
|
throw createFileSystemProviderError('No delegate', FileSystemProviderErrorCode.Unavailable);
|
|
@@ -330,6 +576,22 @@ class OverlayFileSystemProvider {
|
|
|
330
576
|
async readFile(resource) {
|
|
331
577
|
return this.readFromDelegates(delegate => delegate.readFile(resource));
|
|
332
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
|
+
}
|
|
333
595
|
async readdir(resource) {
|
|
334
596
|
const results = await Promise.allSettled(( this.delegates.map(async (delegate) => delegate.readdir(resource))));
|
|
335
597
|
if (!( results.some(isFullfiled))) {
|
|
@@ -496,8 +758,8 @@ function registerCustomProvider(scheme, provider) {
|
|
|
496
758
|
checkServicesNotInitialized();
|
|
497
759
|
providers[scheme] = provider;
|
|
498
760
|
}
|
|
499
|
-
function registerExtensionFile(
|
|
500
|
-
return extensionFileSystemProvider.registerFile(
|
|
761
|
+
function registerExtensionFile(file) {
|
|
762
|
+
return extensionFileSystemProvider.registerFile(file);
|
|
501
763
|
}
|
|
502
764
|
async function initFile(file, content, options) {
|
|
503
765
|
checkServicesNotInitialized();
|
|
@@ -575,4 +837,4 @@ function registerFileSystemOverlay(priority, provider) {
|
|
|
575
837
|
return overlayProvider.register(priority, provider);
|
|
576
838
|
}
|
|
577
839
|
|
|
578
|
-
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.2.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.2.0"
|
|
30
30
|
}
|
|
31
31
|
}
|