diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 93650ca4d4c..01ad4607951 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -4820,6 +4820,241 @@ declare module 'vscode' { resolveTask(task: Task, token?: CancellationToken): ProviderResult; } + /** + * The `FileStat`-type represents metadata about a file. + */ + export interface FileStat { + /** + * The file is a regular file. + */ + isFile?: boolean; + + /** + * The file is a directory. + */ + isDirectory?: boolean; + + /** + * The file is symbolic link to another file. + */ + isSymbolicLink?: boolean; + + /** + * The modification timestamp in milliseconds. + */ + mtime: number; + + /** + * The size in bytes. + */ + size: number; + } + + /** + * A type that filesystem providers should use to signal errors. + * + * This class has factory methods for common error-cases, like `EntryNotFound` when + * a file or folder doesn't exist, use them like so: `throw vscode.FileSystemError.EntryNotFound(someUri);` + */ + export class FileSystemError extends Error { + + /** + * Create an error to signal that a file or folder wasn't found. + * @param messageOrUri Message or uri. + */ + static FileNotFound(messageOrUri?: string | Uri): FileSystemError; + + /** + * Create an error to signal that a file or folder already exists, e.g. when + * creating but not overwriting a file. + * @param messageOrUri Message or uri. + */ + static FileExists(messageOrUri?: string | Uri): FileSystemError; + + /** + * Create an error to signal that a file is not a folder. + * @param messageOrUri Message or uri. + */ + static FileNotADirectory(messageOrUri?: string | Uri): FileSystemError; + + /** + * Create an error to signal that a file is a folder. + * @param messageOrUri Message or uri. + */ + static FileIsADirectory(messageOrUri?: string | Uri): FileSystemError; + + /** + * Creates a new filesystem error. + * + * @param messageOrUri Message or uri. + */ + constructor(messageOrUri?: string | Uri); + } + + /** + * Enumeration of file change types. + */ + export enum FileChangeType { + + /** + * The contents or metadata of a file have changed. + */ + Changed = 1, + + /** + * A file has been created. + */ + Created = 2, + + /** + * A file has been deleted. + */ + Deleted = 3, + } + + /** + * The event filesystem providers must use to signal a file change. + */ + export interface FileChangeEvent { + + /** + * The type of change. + */ + type: FileChangeType; + + /** + * The uri of the file that has changed. + */ + uri: Uri; + } + /** + * Commonly used options when reading, writing, or stat'ing files or folders. + */ + export interface FileOptions { + + /** + * Create a file when it doesn't exists + */ + create?: boolean; + + /** + * In combination with [`create`](FileOptions.create) but + * the operation should fail when a file already exists. + */ + exclusive?: boolean; + + /** + * Open a file for reading. + */ + read?: boolean; + + /** + * Open a file for writing. + */ + write?: boolean; + } + + /** + * The filesystem provider defines what the editor needs to read, write, discover, + * and to manage files and folders. It allows extensions to serve files from remote places, + * like ftp-servers, and to seamlessly integrate those into the editor. + * + * * *Note 1:* The filesystem provider API works with [uris](#Uri) and assumes hierarchical + * paths, e.g. `foo:/my/path` is a child of `foo:/my/` and a parent of `foo:/my/path/deeper`. + * * *Note 2:* There is an activation event `onFileSystem:` that fires when a file + * or folder is being accessed. + * + */ + export interface FileSystemProvider { + + /** + * An event to signal that a resource has been created, changed, or deleted. This + * event should fire for resources that are being [watched](#FileSystemProvider2.watch) + * by clients of this provider. + */ + readonly onDidChangeFile: Event; + + /** + * Subscribe to events in the file or folder denoted by `uri`. + * @param uri + * @param options + */ + watch(uri: Uri, options: { recursive?: boolean; excludes?: string[] }): Disposable; + + /** + * Retrieve metadata about a file. Throw an [`EntryNotFound`](#FileError.EntryNotFound)-error + * in case the file does not exist. + * + * @param uri The uri of the file to retrieve meta data about. + * @param token A cancellation token. + * @return The file metadata about the file. + */ + stat(uri: Uri, options: { /*future: followSymlinks*/ }, token: CancellationToken): FileStat | Thenable; + + /** + * Retrieve the meta data of all entries of a [directory](#FileType2.Directory) + * + * @param uri The uri of the folder. + * @param token A cancellation token. + * @return A thenable that resolves to an array of tuples of file names and files stats. + */ + readDirectory(uri: Uri, options: { /*future: onlyType?*/ }, token: CancellationToken): [string, FileStat][] | Thenable<[string, FileStat][]>; + + /** + * Create a new directory. *Note* that new files are created via `write`-calls. + * + * @param uri The uri of the *new* folder. + * @param token A cancellation token. + */ + createDirectory(uri: Uri, options: { /*future: permissions?*/ }, token: CancellationToken): FileStat | Thenable; + + /** + * Read the entire contents of a file. + * + * @param uri The uri of the file. + * @param token A cancellation token. + * @return A thenable that resolves to an array of bytes. + */ + readFile(uri: Uri, options: FileOptions, token: CancellationToken): Uint8Array | Thenable; + + /** + * Write data to a file, replacing its entire contents. + * + * @param uri The uri of the file. + * @param content The new content of the file. + * @param token A cancellation token. + */ + writeFile(uri: Uri, content: Uint8Array, options: FileOptions, token: CancellationToken): void | Thenable; + + /** + * Delete a file or folder from the underlying storage. + * + * @param uri The resource that is to be deleted + * @param options Options bag for future use + * @param token A cancellation token. + */ + delete(uri: Uri, options: { /*future: useTrash?, followSymlinks?*/ }, token: CancellationToken): void | Thenable; + + /** + * Rename a file or folder. + * + * @param oldUri The existing file or folder. + * @param newUri The target location. + * @param token A cancellation token. + */ + rename(oldUri: Uri, newUri: Uri, options: FileOptions, token: CancellationToken): FileStat | Thenable; + + /** + * Copy files or folders. Implementing this function is optional but it will speedup + * the copy operation. + * + * @param uri The existing file or folder. + * @param target The target location. + * @param token A cancellation token. + */ + copy?(uri: Uri, target: Uri, options: FileOptions, token: CancellationToken): FileStat | Thenable; + } + /** * Content settings for a webview. */ @@ -6273,6 +6508,19 @@ declare module 'vscode' { * @return A [disposable](#Disposable) that unregisters this provider when being disposed. */ export function registerTaskProvider(type: string, provider: TaskProvider): Disposable; + + /** + * Register a filesystem provider for a given scheme, e.g. `ftp`. + * + * There can only be one provider per scheme and an error is being thrown when a scheme + * has been claimed by another provider or when it is reserved. + * + * @param scheme The uri-[scheme](#Uri.scheme) the provider registers for. + * @param provider The filesystem provider. + * @param options Immutable metadata about the provider. + * @return A [disposable](#Disposable) that unregisters this provider when being disposed. + */ + export function registerFileSystemProvider(scheme: string, provider: FileSystemProvider, options: { isCaseSensitive?: boolean }): Disposable; } /** diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 40c99e7bcd2..fee4fe35746 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -51,261 +51,6 @@ declare module 'vscode' { //#endregion - //#region Joh: file system provider (new) - - /** - * A type that filesystem providers should use to signal errors. - * - * This class has factory methods for common error-cases, like `EntryNotFound` when - * a file or folder doesn't exist, use them like so: `throw vscode.FileSystemError.EntryNotFound(someUri);` - */ - export class FileSystemError extends Error { - - /** - * Create an error to signal that a file or folder wasn't found. - * @param messageOrUri Message or uri. - */ - static FileNotFound(messageOrUri?: string | Uri): FileSystemError; - - /** - * Create an error to signal that a file or folder already exists, e.g. when - * creating but not overwriting a file. - * @param messageOrUri Message or uri. - */ - static FileExists(messageOrUri?: string | Uri): FileSystemError; - - /** - * Create an error to signal that a file is not a folder. - * @param messageOrUri Message or uri. - */ - static FileNotADirectory(messageOrUri?: string | Uri): FileSystemError; - - /** - * Create an error to signal that a file is a folder. - * @param messageOrUri Message or uri. - */ - static FileIsADirectory(messageOrUri?: string | Uri): FileSystemError; - - /** - * Creates a new filesystem error. - * - * @param messageOrUri Message or uri. - */ - constructor(messageOrUri?: string | Uri); - } - - /** - * Enumeration of file change types. - */ - export enum FileChangeType { - - /** - * The contents or metadata of a file have changed. - */ - Changed = 1, - - /** - * A file has been created. - */ - Created = 2, - - /** - * A file has been deleted. - */ - Deleted = 3, - } - - /** - * The event filesystem providers must use to signal a file change. - */ - export interface FileChangeEvent { - - /** - * The type of change. - */ - type: FileChangeType; - - /** - * The uri of the file that has changed. - */ - uri: Uri; - } - - /** - * The `FileStat`-type represents metadata about a file. - */ - export interface FileStat { - /** - * The file is a regular file. - */ - isFile?: boolean; - - /** - * The file is a directory. - */ - isDirectory?: boolean; - - /** - * The file is symbolic link to another file. - */ - isSymbolicLink?: boolean; - - /** - * The modification timestamp in milliseconds. - */ - mtime: number; - - /** - * The size in bytes. - */ - size: number; - } - - /** - * Commonly used options when reading, writing, or stat'ing files or folders. - */ - export interface FileOptions { - - /** - * Create a file when it doesn't exists - */ - create?: boolean; - - /** - * In combination with [`create`](FileOptions.create) but - * the operation should fail when a file already exists. - */ - exclusive?: boolean; - - /** - * Open a file for reading. - */ - read?: boolean; - - /** - * Open a file for writing. - */ - write?: boolean; - } - - /** - * The filesystem provider defines what the editor needs to read, write, discover, - * and to manage files and folders. It allows extensions to serve files from remote places, - * like ftp-servers, and to seamlessly integrate those into the editor. - * - * * *Note 1:* The filesystem provider API works with [uris](#Uri) and assumes hierarchical - * paths, e.g. `foo:/my/path` is a child of `foo:/my/` and a parent of `foo:/my/path/deeper`. - * * *Note 2:* There is an activation event `onFileSystem:` that fires when a file - * or folder is being accessed. - * - */ - export interface FileSystemProvider { - - /** - * An event to signal that a resource has been created, changed, or deleted. This - * event should fire for resources that are being [watched](#FileSystemProvider2.watch) - * by clients of this provider. - */ - readonly onDidChangeFile: Event; - - /** - * Subscribe to events in the file or folder denoted by `uri`. - * @param uri - * @param options - */ - watch(uri: Uri, options: { recursive?: boolean; excludes?: string[] }): Disposable; - - /** - * Retrieve metadata about a file. Throw an [`EntryNotFound`](#FileError.EntryNotFound)-error - * in case the file does not exist. - * - * @param uri The uri of the file to retrieve meta data about. - * @param token A cancellation token. - * @return The file metadata about the file. - */ - stat(uri: Uri, options: { /*future: followSymlinks*/ }, token: CancellationToken): FileStat | Thenable; - - /** - * Retrieve the meta data of all entries of a [directory](#FileType2.Directory) - * - * @param uri The uri of the folder. - * @param token A cancellation token. - * @return A thenable that resolves to an array of tuples of file names and files stats. - */ - readDirectory(uri: Uri, options: { /*future: onlyType?*/ }, token: CancellationToken): [string, FileStat][] | Thenable<[string, FileStat][]>; - - /** - * Create a new directory. *Note* that new files are created via `write`-calls. - * - * @param uri The uri of the *new* folder. - * @param token A cancellation token. - */ - createDirectory(uri: Uri, options: { /*future: permissions?*/ }, token: CancellationToken): FileStat | Thenable; - - /** - * Read the entire contents of a file. - * - * @param uri The uri of the file. - * @param token A cancellation token. - * @return A thenable that resolves to an array of bytes. - */ - readFile(uri: Uri, options: FileOptions, token: CancellationToken): Uint8Array | Thenable; - - /** - * Write data to a file, replacing its entire contents. - * - * @param uri The uri of the file. - * @param content The new content of the file. - * @param token A cancellation token. - */ - writeFile(uri: Uri, content: Uint8Array, options: FileOptions, token: CancellationToken): void | Thenable; - - /** - * Delete a file or folder from the underlying storage. - * - * @param uri The resource that is to be deleted - * @param options Options bag for future use - * @param token A cancellation token. - */ - delete(uri: Uri, options: { /*future: useTrash?, followSymlinks?*/ }, token: CancellationToken): void | Thenable; - - /** - * Rename a file or folder. - * - * @param oldUri The existing file or folder. - * @param newUri The target location. - * @param token A cancellation token. - */ - rename(oldUri: Uri, newUri: Uri, options: FileOptions, token: CancellationToken): FileStat | Thenable; - - /** - * Copy files or folders. Implementing this function is optional but it will speedup - * the copy operation. - * - * @param uri The existing file or folder. - * @param target The target location. - * @param token A cancellation token. - */ - copy?(uri: Uri, target: Uri, options: FileOptions, token: CancellationToken): FileStat | Thenable; - } - - export namespace workspace { - /** - * Register a filesystem provider for a given scheme, e.g. `ftp`. - * - * There can only be one provider per scheme and an error is being thrown when a scheme - * has been claimed by another provider or when it is reserved. - * - * @param scheme The uri-[scheme](#Uri.scheme) the provider registers for. - * @param provider The filesystem provider. - * @param options Immutable metadata about the provider. - * @return A [disposable](#Disposable) that unregisters this provider when being disposed. - */ - export function registerFileSystemProvider(scheme: string, provider: FileSystemProvider, options: { isCaseSensitive?: boolean }): Disposable; - } - - //#endregion - //#region Joh: remote, search provider export interface TextSearchQuery { diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 62407e69d9d..728a0255f68 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -550,9 +550,9 @@ export function createApiFactory( onDidEndTask: (listeners, thisArgs?, disposables?) => { return extHostTask.onDidEndTask(listeners, thisArgs, disposables); }, - registerFileSystemProvider: proposedApiFunction(extension, (scheme, provider, options) => { + registerFileSystemProvider(scheme, provider, options) { return extHostFileSystem.registerFileSystemProvider(scheme, provider, options); - }), + }, registerDeprecatedFileSystemProvider: proposedApiFunction(extension, (scheme, provider) => { return extHostFileSystem.registerDeprecatedFileSystemProvider(scheme, provider); }),