Skip to content

Commit

Permalink
make readDirectory return string/stat-tuples, #47475
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Apr 11, 2018
1 parent 1d14398 commit 1b33eb3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/vs/platform/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export interface IFileSystemProvider {
writeFile(resource: URI, content: Uint8Array): TPromise<void>;
move(from: URI, to: URI): TPromise<IStat>;
mkdir(resource: URI): TPromise<IStat>;
readdir(resource: URI): TPromise<[URI, IStat][]>;
readdir(resource: URI): TPromise<[string, IStat][]>;
delete(resource: URI): TPromise<void>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ declare module 'vscode' {
// todo@joh add open/close calls?
export interface FileSystemProvider2 {

_version: 3;
_version: 4;

/**
* An event to signal that a resource has been created, changed, or deleted.
Expand All @@ -273,9 +273,9 @@ declare module 'vscode' {
*
* @param uri The uri of the folder.
* @param token A cancellation token.
* @return A thenable that resolves to an array of tuples of resources and files stats.
* @return A thenable that resolves to an array of tuples of file names and files stats.
*/
readDirectory(uri: Uri, token: CancellationToken): Thenable<[Uri, FileStat2][]>;
readDirectory(uri: Uri, token: CancellationToken): Thenable<[string, FileStat2][]>;

/**
* Read the entire contents of a file.
Expand Down Expand Up @@ -313,7 +313,7 @@ declare module 'vscode' {
delete(uri: Uri, token: CancellationToken): Thenable<void>;

// todo@remote
create(uri: Uri, options: { type: FileType }, token: CancellationToken): Thenable<FileStat2>;
create(uri: Uri, options: { type: FileType2 }, token: CancellationToken): Thenable<FileStat2>;
}

export namespace workspace {
Expand Down
6 changes: 2 additions & 4 deletions src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
mkdir(resource: URI): TPromise<IStat, any> {
return this._proxy.$mkdir(this._handle, resource);
}
readdir(resource: URI): TPromise<[URI, IStat][], any> {
return this._proxy.$readdir(this._handle, resource).then(data => {
return data.map(tuple => <[URI, IStat]>[URI.revive(tuple[0]), tuple[1]]);
});
readdir(resource: URI): TPromise<[string, IStat][], any> {
return this._proxy.$readdir(this._handle, resource);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export interface ExtHostFileSystemShape {

$move(handle: number, resource: UriComponents, target: UriComponents): TPromise<IStat>;
$mkdir(handle: number, resource: UriComponents): TPromise<IStat>;
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>;
$readdir(handle: number, resource: UriComponents): TPromise<[string, IStat][]>;

$delete(handle: number, resource: UriComponents): TPromise<void>;

Expand Down
21 changes: 12 additions & 9 deletions src/vs/workbench/api/node/extHostFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Event, mapEvent } from 'vs/base/common/event';
import { MainContext, IMainContext, ExtHostFileSystemShape, MainThreadFileSystemShape } from './extHost.protocol';
import * as vscode from 'vscode';
import * as files from 'vs/platform/files/common/files';
import * as path from 'path';
import { IDisposable } from 'vs/base/common/lifecycle';
import { asWinJsPromise } from 'vs/base/common/async';
import { IPatternInfo } from 'vs/platform/search/common/search';
Expand Down Expand Up @@ -59,7 +60,7 @@ class FsLinkProvider implements vscode.DocumentLinkProvider {

class FileSystemProviderShim implements vscode.FileSystemProvider2 {

_version: 3;
_version: 4;

onDidChange: vscode.Event<vscode.FileChange2[]>;

Expand All @@ -77,9 +78,9 @@ class FileSystemProviderShim implements vscode.FileSystemProvider2 {
rename(oldUri: vscode.Uri, newUri: vscode.Uri): Thenable<vscode.FileStat2> {
return this._delegate.move(oldUri, newUri).then(stat => FileSystemProviderShim._modernizeFileStat(stat));
}
readDirectory(resource: vscode.Uri): Thenable<[vscode.Uri, vscode.FileStat2][]> {
readDirectory(resource: vscode.Uri): Thenable<[string, vscode.FileStat2][]> {
return this._delegate.readdir(resource).then(tuples => {
return tuples.map(tuple => <[vscode.Uri, vscode.FileStat2]>[tuple[0], FileSystemProviderShim._modernizeFileStat(tuple[1])]);
return tuples.map(tuple => <[string, vscode.FileStat2]>[path.posix.basename(tuple[0].path), FileSystemProviderShim._modernizeFileStat(tuple[1])]);
});
}

Expand Down Expand Up @@ -131,8 +132,8 @@ class FileSystemProviderShim implements vscode.FileSystemProvider2 {
}
});
}
create(resource: vscode.Uri, options: { type: vscode.FileType; }): Thenable<vscode.FileStat2> {
if (options.type === FileType.Dir) {
create(resource: vscode.Uri, options: { type: vscode.FileType2; }): Thenable<vscode.FileStat2> {
if (options.type === FileType2.Directory) {
return this._delegate.mkdir(resource).then(stat => FileSystemProviderShim._modernizeFileStat(stat));
} else {
return this._delegate.write(resource, Buffer.from([]))
Expand Down Expand Up @@ -173,10 +174,12 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
}

registerFileSystemProvider(scheme: string, provider: vscode.FileSystemProvider, newProvider: vscode.FileSystemProvider2) {
if (newProvider && newProvider._version === 3) {
if (newProvider && newProvider._version === 4) {
return this._doRegisterFileSystemProvider(scheme, newProvider);
} else {
} else if (provider) {
return this._doRegisterFileSystemProvider(scheme, new FileSystemProviderShim(provider));
} else {
throw new Error('IGNORED both provider');
}
}

Expand Down Expand Up @@ -234,7 +237,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$stat(handle: number, resource: UriComponents): TPromise<files.IStat, any> {
return asWinJsPromise(token => this._fsProvider.get(handle).stat(URI.revive(resource), token));
}
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, files.IStat][], any> {
$readdir(handle: number, resource: UriComponents): TPromise<[string, files.IStat][], any> {
return asWinJsPromise(token => this._fsProvider.get(handle).readDirectory(URI.revive(resource), token));
}
$readFile(handle: number, resource: UriComponents): TPromise<string> {
Expand All @@ -254,7 +257,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
return asWinJsPromise(token => this._fsProvider.get(handle).rename(URI.revive(oldUri), URI.revive(newUri), token));
}
$mkdir(handle: number, resource: UriComponents): TPromise<files.IStat, any> {
return asWinJsPromise(token => this._fsProvider.get(handle).create(URI.revive(resource), { type: FileType.Dir }, token));
return asWinJsPromise(token => this._fsProvider.get(handle).create(URI.revive(resource), { type: FileType2.Directory }, token));
}

$provideFileSearchResults(handle: number, session: number, query: string): TPromise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse
// dir -> resolve
return provider.readdir(resource).then(entries => {
// resolve children if requested
return TPromise.join(entries.map(stat => toIFileStat(provider, stat, recurse))).then(children => {
return TPromise.join(entries.map(tuple => {
const [name, stat] = tuple;
const childResource = resource.with({ path: posix.join(resource.path, name) });
return toIFileStat(provider, [childResource, stat], recurse);
})).then(children => {
fileStat.children = children;
return fileStat;
});
Expand Down

0 comments on commit 1b33eb3

Please sign in to comment.