提交 7945915d 编写于 作者: J Johannes Rieken

remote - better reads

上级 876b47a9
...@@ -53,8 +53,8 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape { ...@@ -53,8 +53,8 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
this._provider.get(handle).$onFileSystemChange(changes); this._provider.get(handle).$onFileSystemChange(changes);
} }
$reportFileChunk(handle: number, data: UriComponents, chunk: number[]): void { $reportFileChunk(handle: number, session: number, chunk: number[]): void {
this._provider.get(handle).reportFileChunk(URI.revive(data), chunk); this._provider.get(handle).reportFileChunk(session, chunk);
} }
// --- search // --- search
...@@ -64,10 +64,22 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape { ...@@ -64,10 +64,22 @@ 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, ISearchResultProvider { class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProvider {
private readonly _onDidChange = new Emitter<IFileChange[]>(); private readonly _onDidChange = new Emitter<IFileChange[]>();
private readonly _reads = new Map<string, IProgress<Uint8Array>>(); private readonly _reads = new Map<number, FileReadOperation>();
private readonly _registrations: IDisposable[]; private readonly _registrations: IDisposable[];
readonly onDidChange: Event<IFileChange[]> = this._onDidChange.event; readonly onDidChange: Event<IFileChange[]> = this._onDidChange.event;
...@@ -104,11 +116,12 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv ...@@ -104,11 +116,12 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv
return this._proxy.$stat(this._handle, resource); return this._proxy.$stat(this._handle, resource);
} }
read(resource: URI, offset: number, count: number, progress: IProgress<Uint8Array>): TPromise<number, any> { read(resource: URI, offset: number, count: number, progress: IProgress<Uint8Array>): TPromise<number, any> {
this._reads.set(resource.toString(), progress); const read = new FileReadOperation(progress);
return this._proxy.$read(this._handle, offset, count, resource); this._reads.set(read.id, read);
return this._proxy.$read(this._handle, read.id, offset, count, resource);
} }
reportFileChunk(resource: URI, chunk: number[]): void { reportFileChunk(session: number, chunk: number[]): void {
this._reads.get(resource.toString()).report(Buffer.from(chunk)); this._reads.get(session).progress.report(Buffer.from(chunk));
} }
write(resource: URI, content: Uint8Array): TPromise<void, any> { write(resource: URI, content: Uint8Array): TPromise<void, any> {
return this._proxy.$write(this._handle, resource, [].slice.call(content)); return this._proxy.$write(this._handle, resource, [].slice.call(content));
...@@ -143,7 +156,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv ...@@ -143,7 +156,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv
const id = ++this._searchesIdPool; const id = ++this._searchesIdPool;
const matches: IFileMatch[] = []; const matches: IFileMatch[] = [];
return new PPromise((resolve, reject, report) => { return new PPromise((resolve, reject, report) => {
this._proxy.$fileFiles(this._handle, id, query.filePattern).then(() => { this._proxy.$findFiles(this._handle, id, query.filePattern).then(() => {
this._searches.delete(id); this._searches.delete(id);
resolve({ resolve({
results: matches, results: matches,
......
...@@ -371,7 +371,7 @@ export interface MainThreadFileSystemShape extends IDisposable { ...@@ -371,7 +371,7 @@ export interface MainThreadFileSystemShape extends IDisposable {
$onDidAddFileSystemRoot(root: UriComponents): void; $onDidAddFileSystemRoot(root: UriComponents): void;
$onFileSystemChange(handle: number, resource: IFileChange[]): void; $onFileSystemChange(handle: number, resource: IFileChange[]): void;
$reportFileChunk(handle: number, resource: UriComponents, chunk: number[] | null): void; $reportFileChunk(handle: number, session: number, chunk: number[] | null): void;
$handleSearchProgress(handle: number, session: number, resource: UriComponents): void; $handleSearchProgress(handle: number, session: number, resource: UriComponents): void;
} }
...@@ -535,14 +535,14 @@ export interface ExtHostWorkspaceShape { ...@@ -535,14 +535,14 @@ export interface ExtHostWorkspaceShape {
export interface ExtHostFileSystemShape { export interface ExtHostFileSystemShape {
$utimes(handle: number, resource: UriComponents, mtime: number, atime: number): TPromise<IStat>; $utimes(handle: number, resource: UriComponents, mtime: number, atime: number): TPromise<IStat>;
$stat(handle: number, resource: UriComponents): TPromise<IStat>; $stat(handle: number, resource: UriComponents): TPromise<IStat>;
$read(handle: number, offset: number, count: number, resource: UriComponents): TPromise<number>; $read(handle: number, session: number, offset: number, count: number, resource: UriComponents): TPromise<number>;
$write(handle: number, resource: UriComponents, content: number[]): TPromise<void>; $write(handle: number, resource: UriComponents, content: number[]): TPromise<void>;
$unlink(handle: number, resource: UriComponents): TPromise<void>; $unlink(handle: number, resource: UriComponents): TPromise<void>;
$move(handle: number, resource: UriComponents, target: UriComponents): TPromise<IStat>; $move(handle: number, resource: UriComponents, target: UriComponents): TPromise<IStat>;
$mkdir(handle: number, resource: UriComponents): TPromise<IStat>; $mkdir(handle: number, resource: UriComponents): TPromise<IStat>;
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>; $readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>;
$rmdir(handle: number, resource: UriComponents): TPromise<void>; $rmdir(handle: number, resource: UriComponents): TPromise<void>;
$fileFiles(handle: number, session: number, query: string): TPromise<void>; $findFiles(handle: number, session: number, query: string): TPromise<void>;
} }
export interface ExtHostExtensionServiceShape { export interface ExtHostExtensionServiceShape {
......
...@@ -48,10 +48,10 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { ...@@ -48,10 +48,10 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$stat(handle: number, resource: UriComponents): TPromise<IStat, any> { $stat(handle: number, resource: UriComponents): TPromise<IStat, any> {
return asWinJsPromise(token => this._provider.get(handle).stat(URI.revive(resource))); return asWinJsPromise(token => this._provider.get(handle).stat(URI.revive(resource)));
} }
$read(handle: number, offset: number, count: number, resource: UriComponents): TPromise<number> { $read(handle: number, session: number, offset: number, count: number, resource: UriComponents): TPromise<number> {
const progress = { const progress = {
report: chunk => { report: chunk => {
this._proxy.$reportFileChunk(handle, resource, [].slice.call(chunk)); this._proxy.$reportFileChunk(handle, session, [].slice.call(chunk));
} }
}; };
return asWinJsPromise(token => this._provider.get(handle).read(URI.revive(resource), offset, count, progress)); return asWinJsPromise(token => this._provider.get(handle).read(URI.revive(resource), offset, count, progress));
...@@ -74,7 +74,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { ...@@ -74,7 +74,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$rmdir(handle: number, resource: UriComponents): TPromise<void, any> { $rmdir(handle: number, resource: UriComponents): TPromise<void, any> {
return asWinJsPromise(token => this._provider.get(handle).rmdir(URI.revive(resource))); return asWinJsPromise(token => this._provider.get(handle).rmdir(URI.revive(resource)));
} }
$fileFiles(handle: number, session: number, query: string): TPromise<void> { $findFiles(handle: number, session: number, query: string): TPromise<void> {
const provider = this._provider.get(handle); const provider = this._provider.get(handle);
if (!provider.findFiles) { if (!provider.findFiles) {
return TPromise.as(undefined); return TPromise.as(undefined);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册