diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index 1a89a1bb10f6c0aeb5477a6b86391076f9bfc876..a9fe1cda9252f4a7fe05cf077d574dc79e0de8a3 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -198,21 +198,21 @@ export interface IFileSystemProvider { onDidChangeFile: Event; watch(resource: URI, opts: IWatchOptions): IDisposable; - stat(resource: URI): TPromise; - mkdir(resource: URI): TPromise; - readdir(resource: URI): TPromise<[string, FileType][]>; - delete(resource: URI, opts: FileDeleteOptions): TPromise; + stat(resource: URI): Thenable; + mkdir(resource: URI): Thenable; + readdir(resource: URI): Thenable<[string, FileType][]>; + delete(resource: URI, opts: FileDeleteOptions): Thenable; - rename(from: URI, to: URI, opts: FileOverwriteOptions): TPromise; - copy?(from: URI, to: URI, opts: FileOverwriteOptions): TPromise; + rename(from: URI, to: URI, opts: FileOverwriteOptions): Thenable; + copy?(from: URI, to: URI, opts: FileOverwriteOptions): Thenable; - readFile?(resource: URI): TPromise; - writeFile?(resource: URI, content: Uint8Array, opts: FileWriteOptions): TPromise; + readFile?(resource: URI): Thenable; + writeFile?(resource: URI, content: Uint8Array, opts: FileWriteOptions): Thenable; - open?(resource: URI): TPromise; - close?(fd: number): TPromise; - read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise; - write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise; + open?(resource: URI): Thenable; + close?(fd: number): Thenable; + read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Thenable; + write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Thenable; } export interface IFileSystemProviderRegistrationEvent { diff --git a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts index 60985bd29020212144767c4213c2e61cb57d471d..911c23e45899171219ccd5d68ce1c3900122947f 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts @@ -7,7 +7,6 @@ import { Emitter, Event } from 'vs/base/common/event'; import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle'; import { URI } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import { FileWriteOptions, FileSystemProviderCapabilities, IFileChange, IFileService, IFileSystemProvider, IStat, IWatchOptions, FileType, FileOverwriteOptions, FileDeleteOptions } from 'vs/platform/files/common/files'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import { ExtHostContext, ExtHostFileSystemShape, IExtHostContext, IFileChangeDto, MainContext, MainThreadFileSystemShape } from '../node/extHost.protocol'; @@ -96,53 +95,53 @@ class RemoteFileSystemProvider implements IFileSystemProvider { return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength); } - stat(resource: URI): TPromise { + stat(resource: URI): Thenable { return this._proxy.$stat(this._handle, resource).then(undefined, err => { throw err; }); } - readFile(resource: URI): TPromise { + readFile(resource: URI): Thenable { return this._proxy.$readFile(this._handle, resource); } - writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): TPromise { + writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Thenable { return this._proxy.$writeFile(this._handle, resource, RemoteFileSystemProvider._asBuffer(content), opts); } - delete(resource: URI, opts: FileDeleteOptions): TPromise { + delete(resource: URI, opts: FileDeleteOptions): Thenable { return this._proxy.$delete(this._handle, resource, opts); } - mkdir(resource: URI): TPromise { + mkdir(resource: URI): Thenable { return this._proxy.$mkdir(this._handle, resource); } - readdir(resource: URI): TPromise<[string, FileType][]> { + readdir(resource: URI): Thenable<[string, FileType][]> { return this._proxy.$readdir(this._handle, resource); } - rename(resource: URI, target: URI, opts: FileOverwriteOptions): TPromise { + rename(resource: URI, target: URI, opts: FileOverwriteOptions): Thenable { return this._proxy.$rename(this._handle, resource, target, opts); } - copy(resource: URI, target: URI, opts: FileOverwriteOptions): TPromise { + copy(resource: URI, target: URI, opts: FileOverwriteOptions): Thenable { return this._proxy.$copy(this._handle, resource, target, opts); } - open(resource: URI): TPromise { + open(resource: URI): Thenable { return this._proxy.$open(this._handle, resource); } - close(fd: number): TPromise { + close(fd: number): Thenable { return this._proxy.$close(this._handle, fd); } - read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise { + read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Thenable { return this._proxy.$read(this._handle, fd, pos, RemoteFileSystemProvider._asBuffer(data), offset, length); } - write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): TPromise { + write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Thenable { return this._proxy.$write(this._handle, fd, pos, RemoteFileSystemProvider._asBuffer(data), offset, length); } } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 7c61838cf13d1571b1a39d91574617c5d401afb9..4cf844d61ef2324f32744b08a9b7c4bfc0baf7d4 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -681,20 +681,20 @@ export interface ExtHostWorkspaceShape { } export interface ExtHostFileSystemShape { - $stat(handle: number, resource: UriComponents): TPromise; - $readdir(handle: number, resource: UriComponents): TPromise<[string, FileType][]>; - $readFile(handle: number, resource: UriComponents): TPromise; - $writeFile(handle: number, resource: UriComponents, content: Buffer, opts: FileWriteOptions): TPromise; - $rename(handle: number, resource: UriComponents, target: UriComponents, opts: FileOverwriteOptions): TPromise; - $copy(handle: number, resource: UriComponents, target: UriComponents, opts: FileOverwriteOptions): TPromise; - $mkdir(handle: number, resource: UriComponents): TPromise; - $delete(handle: number, resource: UriComponents, opts: FileDeleteOptions): TPromise; + $stat(handle: number, resource: UriComponents): Thenable; + $readdir(handle: number, resource: UriComponents): Thenable<[string, FileType][]>; + $readFile(handle: number, resource: UriComponents): Thenable; + $writeFile(handle: number, resource: UriComponents, content: Buffer, opts: FileWriteOptions): Thenable; + $rename(handle: number, resource: UriComponents, target: UriComponents, opts: FileOverwriteOptions): Thenable; + $copy(handle: number, resource: UriComponents, target: UriComponents, opts: FileOverwriteOptions): Thenable; + $mkdir(handle: number, resource: UriComponents): Thenable; + $delete(handle: number, resource: UriComponents, opts: FileDeleteOptions): Thenable; $watch(handle: number, session: number, resource: UriComponents, opts: IWatchOptions): void; $unwatch(handle: number, session: number): void; - $open(handle: number, resource: UriComponents): TPromise; - $close(handle: number, fd: number): TPromise; - $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise; - $write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise; + $open(handle: number, resource: UriComponents): Thenable; + $close(handle: number, fd: number): Thenable; + $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): Thenable; + $write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): Thenable; } export interface ExtHostSearchShape { diff --git a/src/vs/workbench/api/node/extHostFileSystem.ts b/src/vs/workbench/api/node/extHostFileSystem.ts index 6faf26d9b3d7d717264d6dfffcce58fcded2efcb..00a379eb8083a52647b07d387577a3898149ab62 100644 --- a/src/vs/workbench/api/node/extHostFileSystem.ts +++ b/src/vs/workbench/api/node/extHostFileSystem.ts @@ -5,12 +5,10 @@ 'use strict'; import { URI, UriComponents } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import { MainContext, IMainContext, ExtHostFileSystemShape, MainThreadFileSystemShape, IFileChangeDto } from './extHost.protocol'; import * as vscode from 'vscode'; import * as files from 'vs/platform/files/common/files'; import { IDisposable, toDisposable } from 'vs/base/common/lifecycle'; -import { asWinJsPromise } from 'vs/base/common/async'; import { values } from 'vs/base/common/map'; import { Range, FileChangeType } from 'vs/workbench/api/node/extHostTypes'; import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFeatures'; @@ -156,47 +154,43 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { return { type, ctime, mtime, size }; } - $stat(handle: number, resource: UriComponents): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).stat(URI.revive(resource))).then(ExtHostFileSystem._asIStat); + $stat(handle: number, resource: UriComponents): Promise { + return Promise.resolve(this._fsProvider.get(handle).stat(URI.revive(resource))).then(ExtHostFileSystem._asIStat); } - $readdir(handle: number, resource: UriComponents): TPromise<[string, files.FileType][]> { - return asWinJsPromise(() => this._fsProvider.get(handle).readDirectory(URI.revive(resource))); + $readdir(handle: number, resource: UriComponents): Promise<[string, files.FileType][]> { + return Promise.resolve(this._fsProvider.get(handle).readDirectory(URI.revive(resource))); } - $readFile(handle: number, resource: UriComponents): TPromise { - return asWinJsPromise(() => { - return this._fsProvider.get(handle).readFile(URI.revive(resource)); - }).then(data => { + $readFile(handle: number, resource: UriComponents): Promise { + return Promise.resolve(this._fsProvider.get(handle).readFile(URI.revive(resource))).then(data => { return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength); }); } - $writeFile(handle: number, resource: UriComponents, content: Buffer, opts: files.FileWriteOptions): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).writeFile(URI.revive(resource), content, opts)); + $writeFile(handle: number, resource: UriComponents, content: Buffer, opts: files.FileWriteOptions): Promise { + return Promise.resolve(this._fsProvider.get(handle).writeFile(URI.revive(resource), content, opts)); } - $delete(handle: number, resource: UriComponents, opts: files.FileDeleteOptions): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).delete(URI.revive(resource), opts)); + $delete(handle: number, resource: UriComponents, opts: files.FileDeleteOptions): Promise { + return Promise.resolve(this._fsProvider.get(handle).delete(URI.revive(resource), opts)); } - $rename(handle: number, oldUri: UriComponents, newUri: UriComponents, opts: files.FileOverwriteOptions): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).rename(URI.revive(oldUri), URI.revive(newUri), opts)); + $rename(handle: number, oldUri: UriComponents, newUri: UriComponents, opts: files.FileOverwriteOptions): Promise { + return Promise.resolve(this._fsProvider.get(handle).rename(URI.revive(oldUri), URI.revive(newUri), opts)); } - $copy(handle: number, oldUri: UriComponents, newUri: UriComponents, opts: files.FileOverwriteOptions): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).copy(URI.revive(oldUri), URI.revive(newUri), opts)); + $copy(handle: number, oldUri: UriComponents, newUri: UriComponents, opts: files.FileOverwriteOptions): Promise { + return Promise.resolve(this._fsProvider.get(handle).copy(URI.revive(oldUri), URI.revive(newUri), opts)); } - $mkdir(handle: number, resource: UriComponents): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).createDirectory(URI.revive(resource))); + $mkdir(handle: number, resource: UriComponents): Promise { + return Promise.resolve(this._fsProvider.get(handle).createDirectory(URI.revive(resource))); } $watch(handle: number, session: number, resource: UriComponents, opts: files.IWatchOptions): void { - asWinJsPromise(() => { - let subscription = this._fsProvider.get(handle).watch(URI.revive(resource), opts); - this._watches.set(session, subscription); - }); + let subscription = this._fsProvider.get(handle).watch(URI.revive(resource), opts); + this._watches.set(session, subscription); } $unwatch(session: number): void { @@ -207,20 +201,20 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { } } - $open(handle: number, resource: UriComponents): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).open(URI.revive(resource))); + $open(handle: number, resource: UriComponents): Promise { + return Promise.resolve(this._fsProvider.get(handle).open(URI.revive(resource))); } - $close(handle: number, fd: number): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).close(fd)); + $close(handle: number, fd: number): Promise { + return Promise.resolve(this._fsProvider.get(handle).close(fd)); } - $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).read(fd, pos, data, offset, length)); + $read(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): Promise { + return Promise.resolve(this._fsProvider.get(handle).read(fd, pos, data, offset, length)); } - $write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): TPromise { - return asWinJsPromise(() => this._fsProvider.get(handle).write(fd, pos, data, offset, length)); + $write(handle: number, fd: number, pos: number, data: Buffer, offset: number, length: number): Promise { + return Promise.resolve(this._fsProvider.get(handle).write(fd, pos, data, offset, length)); } } diff --git a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts index 3ad00f570a7cc0186c496238ed9e66d75e46178d..881b1dec78abffc150a4a3dd7e838697bb8e35b8 100644 --- a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts +++ b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts @@ -38,7 +38,7 @@ class TypeOnlyStat implements IStat { size: number = 0; } -function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse?: (tuple: [URI, IStat]) => boolean): TPromise { +function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse?: (tuple: [URI, IStat]) => boolean): Thenable { const [resource, stat] = tuple; const fileStat: IFileStat = { resource, @@ -72,7 +72,7 @@ function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse return TPromise.as(fileStat); } -export function toDeepIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], to: URI[]): TPromise { +export function toDeepIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], to: URI[]): Thenable { const trie = TernarySearchTree.forPaths(); trie.set(tuple[0].toString(), true);