mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
catchup with latest api changes
This commit is contained in:
@ -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 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -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<string, Entry>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
88
fsprovider-sample/src/vscode.proposed.d.ts
vendored
88
fsprovider-sample/src/vscode.proposed.d.ts
vendored
@ -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<Uint8Array>;
|
||||
readFile(uri: Uri, options: FileOptions, token: CancellationToken): Uint8Array | Thenable<Uint8Array>;
|
||||
|
||||
/**
|
||||
* 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<void>;
|
||||
writeFile(uri: Uri, content: Uint8Array, options: FileOptions, token: CancellationToken): void | Thenable<void>;
|
||||
|
||||
/**
|
||||
* 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<FileStat2>;
|
||||
rename(oldUri: Uri, newUri: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
|
||||
|
||||
/**
|
||||
* 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<FileStat2>;
|
||||
copy?(uri: Uri, target: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
|
||||
}
|
||||
|
||||
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<Task[]>;
|
||||
export function fetchTasks(filter?: TaskFilter): Thenable<Task[]>;
|
||||
|
||||
/**
|
||||
* Executes a task that is managed by VS Code. The returned
|
||||
@ -584,6 +615,13 @@ declare module 'vscode' {
|
||||
*/
|
||||
export function executeTask(task: Task): Thenable<TaskExecution>;
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user