diff --git a/fsprovider-sample/src/extension.ts b/fsprovider-sample/src/extension.ts index bed3884b..0cdbb740 100644 --- a/fsprovider-sample/src/extension.ts +++ b/fsprovider-sample/src/extension.ts @@ -18,17 +18,17 @@ export function activate(context: vscode.ExtensionContext) { memFs.createDirectory(vscode.Uri.parse(`memfs:/xyz/abc`)); memFs.createDirectory(vscode.Uri.parse(`memfs:/xyz/def`)); - memFs.writeFile(vscode.Uri.parse(`memfs:/empty.txt`), new Uint8Array(0)); - memFs.writeFile(vscode.Uri.parse(`memfs:/file.txt`), Buffer.from('foo')); - memFs.writeFile(vscode.Uri.parse(`memfs:/file.css`), Buffer.from('* { color: green; }')); - memFs.writeFile(vscode.Uri.parse(`memfs:/large-rnd.foo`), randomData(50000)); - memFs.writeFile(vscode.Uri.parse(`memfs:/folder/empty.foo`), new Uint8Array(0)); - memFs.writeFile(vscode.Uri.parse(`memfs:/folder/file.ts`), Buffer.from('let a:number = true; console.log(a);')); - memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.md`), Buffer.from('*MemFS*')); - memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.bin`), Buffer.from([0, 0, 0, 1, 7, 0, 0, 1, 1])); + memFs.writeFile(vscode.Uri.parse(`memfs:/empty.txt`), new Uint8Array(0), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/file.txt`), Buffer.from('foo'), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/file.css`), Buffer.from('* { color: green; }'), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/large-rnd.foo`), randomData(50000), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/folder/empty.foo`), new Uint8Array(0), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/folder/file.ts`), Buffer.from('let a:number = true; console.log(a);'), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.md`), Buffer.from('*MemFS*'), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/xyz/def/foo.bin`), Buffer.from([0, 0, 0, 1, 7, 0, 0, 1, 1]), { create: true }); - memFs.writeFile(vscode.Uri.parse(`memfs:/UPPER.txt`), Buffer.from('UPPER')); - memFs.writeFile(vscode.Uri.parse(`memfs:/upper.txt`), Buffer.from('upper')); + memFs.writeFile(vscode.Uri.parse(`memfs:/UPPER.txt`), Buffer.from('UPPER'), { create: true }); + memFs.writeFile(vscode.Uri.parse(`memfs:/upper.txt`), Buffer.from('upper'), { create: true }); } }); diff --git a/fsprovider-sample/src/fileSystemProvider.ts b/fsprovider-sample/src/fileSystemProvider.ts index f51386f1..806e334b 100644 --- a/fsprovider-sample/src/fileSystemProvider.ts +++ b/fsprovider-sample/src/fileSystemProvider.ts @@ -12,13 +12,15 @@ import { workspace } from 'vscode'; class File { - type: vscode.FileType2; + isFile: boolean; + isDirectory: boolean; + isSymbolicLink: boolean; mtime: number; size: number; name: string; constructor(name: string) { - this.type = vscode.FileType2.File; + this.isFile = true; this.mtime = Date.now(); this.size = 0; this.name = name; @@ -27,14 +29,16 @@ class File { class Directory { - type: vscode.FileType2; + isFile: boolean; + isDirectory: boolean; + isSymbolicLink: boolean; mtime: number; size: number; name: string; entries: Map; constructor(name: string) { - this.type = vscode.FileType2.Directory; + this.isDirectory = true; this.mtime = Date.now(); this.size = 0; this.name = name; @@ -77,10 +81,16 @@ export class MemFS implements vscode.FileSystemProvider2 { return this._data.get(entry) || new Uint8Array(0); } - writeFile(uri: vscode.Uri, content: Uint8Array): void { + writeFile(uri: vscode.Uri, content: Uint8Array, options: vscode.FileOptions): void { let basename = path.posix.basename(uri.path); let parent = this._lookupContainer(uri); let entry = parent.entries.get(basename); + if (!entry && !options.create) { + throw vscode.FileSystemError.EntryNotFound(uri.toString(true)); + } + if (entry && options.create && options.exclusive) { + throw vscode.FileSystemError.EntryExists(uri.toString(true)); + } if (!entry) { entry = new File(basename); parent.entries.set(basename, entry); @@ -115,7 +125,7 @@ export class MemFS implements vscode.FileSystemProvider2 { let basename = path.posix.basename(uri.path); let parent = this._lookupDir(dirname); if (!parent.entries.has(basename)) { - throw vscode.FileSystemError.EntryNotFound(); + throw vscode.FileSystemError.EntryNotFound(uri.toString(true)); } parent.entries.delete(basename); parent.mtime = Date.now(); @@ -150,7 +160,7 @@ export class MemFS implements vscode.FileSystemProvider2 { child = entry.entries.get(part); } if (!child) { - throw vscode.FileSystemError.EntryNotFound(); + throw vscode.FileSystemError.EntryNotFound(uri.toString(true)); } entry = child; } @@ -160,7 +170,7 @@ export class MemFS implements vscode.FileSystemProvider2 { private _lookupDir(uri: vscode.Uri): Directory { let entry = this._lookup(uri); if (!(entry instanceof Directory)) { - throw vscode.FileSystemError.EntryNotADirectory(); + throw vscode.FileSystemError.EntryNotADirectory(uri.toString(true)); } return entry; } diff --git a/fsprovider-sample/src/vscode.proposed.d.ts b/fsprovider-sample/src/vscode.proposed.d.ts index e38fba7f..8158008c 100644 --- a/fsprovider-sample/src/vscode.proposed.d.ts +++ b/fsprovider-sample/src/vscode.proposed.d.ts @@ -123,23 +123,39 @@ declare module 'vscode' { uri: Uri; } - export enum FileType2 { - File = 0b001, - Directory = 0b010, - SymbolicLink = 0b100, - } - export interface FileStat2 { - type: FileType2; + isFile: boolean; + isDirectory: boolean; + isSymbolicLink: boolean; mtime: number; size: number; } - export enum FileOpenFlags { - Read = 0b0001, - Write = 0b0010, - Create = 0b0100, - Exclusive = 0b1000 + /** + * + */ + 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; } /** @@ -197,7 +213,7 @@ declare module 'vscode' { * @param token A cancellation token. * @return A thenable that resolves to an array of bytes. */ - readFile(uri: Uri, options: { flags: FileOpenFlags }, token: CancellationToken): Uint8Array | Thenable; + readFile(uri: Uri, options: FileOptions, token: CancellationToken): Uint8Array | Thenable; /** * Write data to a file, replacing its entire contents. @@ -206,7 +222,7 @@ declare module 'vscode' { * @param content The new content of the file. * @param token A cancellation token. */ - writeFile(uri: Uri, content: Uint8Array, options: { flags: FileOpenFlags }, token: CancellationToken): void | Thenable; + writeFile(uri: Uri, content: Uint8Array, options: FileOptions, token: CancellationToken): void | Thenable; /** * Delete a file or folder from the underlying storage. @@ -224,7 +240,7 @@ declare module 'vscode' { * @param newUri The target location. * @param token A cancellation token. */ - rename(oldUri: Uri, newUri: Uri, options: { flags: FileOpenFlags }, token: CancellationToken): FileStat2 | Thenable; + rename(oldUri: Uri, newUri: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable; /** * Copy files or folders. Implementing this function is optional but it will speedup @@ -234,7 +250,7 @@ declare module 'vscode' { * @param target The target location. * @param token A cancellation token. */ - copy?(uri: Uri, target: Uri, options: { flags: FileOpenFlags }, token: CancellationToken): FileStat2 | Thenable; + copy?(uri: Uri, target: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable; } export namespace workspace { @@ -567,14 +583,29 @@ declare module 'vscode' { execution: TaskExecution; } + export interface TaskFilter { + /** + * The task version as used in the tasks.json file. + * The string support the package.json semver notation. + */ + version?: string; + + /** + * The task type to return; + */ + type?: string; + } + export namespace workspace { /** * Fetches all task available in the systems. Thisweweb includes tasks * from `tasks.json` files as well as tasks from task providers * contributed through extensions. + * + * @param filter a filter to filter the return tasks. */ - export function fetchTasks(): Thenable; + export function fetchTasks(filter?: TaskFilter): Thenable; /** * Executes a task that is managed by VS Code. The returned @@ -584,6 +615,13 @@ declare module 'vscode' { */ export function executeTask(task: Task): Thenable; + /** + * The currently active task executions or an empty array. + * + * @readonly + */ + export let taskExecutions: TaskExecution[]; + /** * Fires when a task starts. */ @@ -615,4 +653,20 @@ declare module 'vscode' { } //#endregion + + //#region URLs + + export interface UrlHandler { + handleUrl(uri: Uri): void; + } + + export namespace window { + + /** + * Registers a URL handler. + */ + export function registerUrlHandler(handler: UrlHandler): Disposable; + } + + //#endregion }