Skip to content

Commit

Permalink
move filesystem provider api to stable, #47475
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Apr 23, 2018
1 parent bf61555 commit dc0be20
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 257 deletions.
248 changes: 248 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,241 @@ declare module 'vscode' {
resolveTask(task: Task, token?: CancellationToken): ProviderResult<Task>;
}

/**
* 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:<scheme>` 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<FileChangeEvent[]>;

/**
* 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<FileStat>;

/**
* 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<FileStat>;

/**
* 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<Uint8Array>;

/**
* 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<void>;

/**
* 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<void>;

/**
* 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<FileStat>;

/**
* 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<FileStat>;
}

/**
* Content settings for a webview.
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Loading

0 comments on commit dc0be20

Please sign in to comment.