Skip to content

Commit 7945915

Browse files
committed
remote - better reads
1 parent 876b47a commit 7945915

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
5353
this._provider.get(handle).$onFileSystemChange(changes);
5454
}
5555

56-
$reportFileChunk(handle: number, data: UriComponents, chunk: number[]): void {
57-
this._provider.get(handle).reportFileChunk(URI.revive(data), chunk);
56+
$reportFileChunk(handle: number, session: number, chunk: number[]): void {
57+
this._provider.get(handle).reportFileChunk(session, chunk);
5858
}
5959

6060
// --- search
@@ -64,10 +64,22 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
6464
}
6565
}
6666

67+
class FileReadOperation {
68+
69+
private static _idPool = 0;
70+
71+
constructor(
72+
readonly progress: IProgress<Uint8Array>,
73+
readonly id: number = ++FileReadOperation._idPool
74+
) {
75+
//
76+
}
77+
}
78+
6779
class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProvider {
6880

6981
private readonly _onDidChange = new Emitter<IFileChange[]>();
70-
private readonly _reads = new Map<string, IProgress<Uint8Array>>();
82+
private readonly _reads = new Map<number, FileReadOperation>();
7183
private readonly _registrations: IDisposable[];
7284

7385
readonly onDidChange: Event<IFileChange[]> = this._onDidChange.event;
@@ -104,11 +116,12 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv
104116
return this._proxy.$stat(this._handle, resource);
105117
}
106118
read(resource: URI, offset: number, count: number, progress: IProgress<Uint8Array>): TPromise<number, any> {
107-
this._reads.set(resource.toString(), progress);
108-
return this._proxy.$read(this._handle, offset, count, resource);
119+
const read = new FileReadOperation(progress);
120+
this._reads.set(read.id, read);
121+
return this._proxy.$read(this._handle, read.id, offset, count, resource);
109122
}
110-
reportFileChunk(resource: URI, chunk: number[]): void {
111-
this._reads.get(resource.toString()).report(Buffer.from(chunk));
123+
reportFileChunk(session: number, chunk: number[]): void {
124+
this._reads.get(session).progress.report(Buffer.from(chunk));
112125
}
113126
write(resource: URI, content: Uint8Array): TPromise<void, any> {
114127
return this._proxy.$write(this._handle, resource, [].slice.call(content));
@@ -143,7 +156,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv
143156
const id = ++this._searchesIdPool;
144157
const matches: IFileMatch[] = [];
145158
return new PPromise((resolve, reject, report) => {
146-
this._proxy.$fileFiles(this._handle, id, query.filePattern).then(() => {
159+
this._proxy.$findFiles(this._handle, id, query.filePattern).then(() => {
147160
this._searches.delete(id);
148161
resolve({
149162
results: matches,

src/vs/workbench/api/node/extHost.protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export interface MainThreadFileSystemShape extends IDisposable {
371371

372372
$onDidAddFileSystemRoot(root: UriComponents): void;
373373
$onFileSystemChange(handle: number, resource: IFileChange[]): void;
374-
$reportFileChunk(handle: number, resource: UriComponents, chunk: number[] | null): void;
374+
$reportFileChunk(handle: number, session: number, chunk: number[] | null): void;
375375

376376
$handleSearchProgress(handle: number, session: number, resource: UriComponents): void;
377377
}
@@ -535,14 +535,14 @@ export interface ExtHostWorkspaceShape {
535535
export interface ExtHostFileSystemShape {
536536
$utimes(handle: number, resource: UriComponents, mtime: number, atime: number): TPromise<IStat>;
537537
$stat(handle: number, resource: UriComponents): TPromise<IStat>;
538-
$read(handle: number, offset: number, count: number, resource: UriComponents): TPromise<number>;
538+
$read(handle: number, session: number, offset: number, count: number, resource: UriComponents): TPromise<number>;
539539
$write(handle: number, resource: UriComponents, content: number[]): TPromise<void>;
540540
$unlink(handle: number, resource: UriComponents): TPromise<void>;
541541
$move(handle: number, resource: UriComponents, target: UriComponents): TPromise<IStat>;
542542
$mkdir(handle: number, resource: UriComponents): TPromise<IStat>;
543543
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>;
544544
$rmdir(handle: number, resource: UriComponents): TPromise<void>;
545-
$fileFiles(handle: number, session: number, query: string): TPromise<void>;
545+
$findFiles(handle: number, session: number, query: string): TPromise<void>;
546546
}
547547

548548
export interface ExtHostExtensionServiceShape {

src/vs/workbench/api/node/extHostFileSystem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
4848
$stat(handle: number, resource: UriComponents): TPromise<IStat, any> {
4949
return asWinJsPromise(token => this._provider.get(handle).stat(URI.revive(resource)));
5050
}
51-
$read(handle: number, offset: number, count: number, resource: UriComponents): TPromise<number> {
51+
$read(handle: number, session: number, offset: number, count: number, resource: UriComponents): TPromise<number> {
5252
const progress = {
5353
report: chunk => {
54-
this._proxy.$reportFileChunk(handle, resource, [].slice.call(chunk));
54+
this._proxy.$reportFileChunk(handle, session, [].slice.call(chunk));
5555
}
5656
};
5757
return asWinJsPromise(token => this._provider.get(handle).read(URI.revive(resource), offset, count, progress));
@@ -74,7 +74,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
7474
$rmdir(handle: number, resource: UriComponents): TPromise<void, any> {
7575
return asWinJsPromise(token => this._provider.get(handle).rmdir(URI.revive(resource)));
7676
}
77-
$fileFiles(handle: number, session: number, query: string): TPromise<void> {
77+
$findFiles(handle: number, session: number, query: string): TPromise<void> {
7878
const provider = this._provider.get(handle);
7979
if (!provider.findFiles) {
8080
return TPromise.as(undefined);

0 commit comments

Comments
 (0)