add FileSystemProvider2 for rapid changes, add readFile/writeFile, simplify delete, #47475

This commit is contained in:
Johannes Rieken
2018-04-09 11:35:20 +02:00
parent 317bf2e647
commit 534d10d37d
7 changed files with 159 additions and 117 deletions

View File

@@ -11,7 +11,6 @@ import { IFileService, IFileSystemProvider, IStat, IFileChange } from 'vs/platfo
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IProgress } from 'vs/platform/progress/common/progress';
import { ISearchResultProvider, ISearchQuery, ISearchComplete, ISearchProgressItem, QueryType, IFileMatch, ISearchService, ILineMatch } from 'vs/platform/search/common/search';
import { values } from 'vs/base/common/map';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
@@ -55,11 +54,6 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
$onFileSystemChange(handle: number, changes: IFileChangeDto[]): void {
this._fileProvider.get(handle).$onFileSystemChange(changes);
}
$reportFileChunk(handle: number, session: number, base64Chunk: string): void {
this._fileProvider.get(handle).reportFileChunk(session, base64Chunk);
}
// --- search
$handleFindMatch(handle: number, session, data: UriComponents | [UriComponents, ILineMatch]): void {
@@ -67,23 +61,10 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
}
}
class FileReadOperation {
private static _idPool = 0;
constructor(
readonly progress: IProgress<Uint8Array>,
readonly id: number = ++FileReadOperation._idPool
) {
//
}
}
class RemoteFileSystemProvider implements IFileSystemProvider {
private readonly _onDidChange = new Emitter<IFileChange[]>();
private readonly _registrations: IDisposable[];
private readonly _reads = new Map<number, FileReadOperation>();
readonly onDidChange: Event<IFileChange[]> = this._onDidChange.event;
@@ -118,25 +99,19 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
stat(resource: URI): TPromise<IStat, any> {
return this._proxy.$stat(this._handle, resource);
}
read(resource: URI, offset: number, count: number, progress: IProgress<Uint8Array>): TPromise<number, any> {
const read = new FileReadOperation(progress);
this._reads.set(read.id, read);
return this._proxy.$read(this._handle, read.id, offset, count, resource).then(value => {
this._reads.delete(read.id);
return value;
readFile(resource: URI): TPromise<Uint8Array, any> {
return this._proxy.$readFile(this._handle, resource).then(encoded => {
return Buffer.from(encoded, 'base64');
});
}
reportFileChunk(session: number, encodedChunk: string): void {
this._reads.get(session).progress.report(Buffer.from(encodedChunk, 'base64'));
}
write(resource: URI, content: Uint8Array): TPromise<void, any> {
writeFile(resource: URI, content: Uint8Array): TPromise<void, any> {
let encoded = Buffer.isBuffer(content)
? content.toString('base64')
: Buffer.from(content.buffer, content.byteOffset, content.byteLength).toString('base64');
return this._proxy.$write(this._handle, resource, encoded);
return this._proxy.$writeFile(this._handle, resource, encoded);
}
unlink(resource: URI): TPromise<void, any> {
return this._proxy.$unlink(this._handle, resource);
delete(resource: URI): TPromise<void, any> {
return this._proxy.$delete(this._handle, resource);
}
move(resource: URI, target: URI): TPromise<IStat, any> {
return this._proxy.$move(this._handle, resource, target);
@@ -149,9 +124,6 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
return data.map(tuple => <[URI, IStat]>[URI.revive(tuple[0]), tuple[1]]);
});
}
rmdir(resource: URI): TPromise<void, any> {
return this._proxy.$rmdir(this._handle, resource);
}
}
class SearchOperation {