vscode.proposed.d.ts 9.9 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

// This is the place for API experiments and proposal.

declare module 'vscode' {

J
Johannes Rieken 已提交
10 11 12
	/**
	 * Options to configure the behaviour of a file open dialog.
	 */
13
	export interface OpenDialogOptions {
J
Johannes Rieken 已提交
14 15 16
		/**
		 * The resource the dialog shows when opened.
		 */
J
Johannes Rieken 已提交
17
		defaultUri?: Uri;
J
Johannes Rieken 已提交
18 19 20 21

		/**
		 * A human-readable string for the open button.
		 */
22
		openLabel?: string;
J
Johannes Rieken 已提交
23 24 25 26 27

		/**
		 * Only allow to select files. *Note* that not all operating systems support
		 * to select files and folders in one dialog instance.
		 */
28
		openFiles?: boolean;
J
Johannes Rieken 已提交
29 30 31 32 33

		/**
		 * Only allow to select folders. *Note* that not all operating systems support
		 * to select files and folders in one dialog instance.
		 */
34
		openFolders?: boolean;
J
Johannes Rieken 已提交
35 36 37 38

		/**
		 * Allow to select many files or folders.
		 */
39
		openMany?: boolean;
J
Johannes Rieken 已提交
40 41 42 43 44 45 46 47 48 49

		/**
		 * A set of file filters that are shown in the dialog, e.g.
		 * ```ts
		 * {
		 * 	['Images']: ['*.png', '*.jpg']
		 * 	['TypeScript']: ['*.ts', '*.tsx']
		 * }
		 * ```
		 */
J
Johannes Rieken 已提交
50
		filters: { [name: string]: string[] };
51
	}
52

J
Johannes Rieken 已提交
53
	/**
J
Johannes Rieken 已提交
54
	 * Options to configure the behaviour of a file save dialog.
J
Johannes Rieken 已提交
55
	 */
56
	export interface SaveDialogOptions {
J
Johannes Rieken 已提交
57 58 59
		/**
		 * The resource the dialog shows when opened.
		 */
J
Johannes Rieken 已提交
60
		defaultUri?: Uri;
J
Johannes Rieken 已提交
61 62 63 64

		/**
		 * A human-readable string for the save button.
		 */
65
		saveLabel?: string;
J
Johannes Rieken 已提交
66 67 68 69 70 71 72 73 74 75

		/**
		 * A set of file filters that are shown in the dialog, e.g.
		 * ```ts
		 * {
		 * 	['Images']: ['*.png', '*.jpg']
		 * 	['TypeScript']: ['*.ts', '*.tsx']
		 * }
		 * ```
		 */
J
Johannes Rieken 已提交
76
		filters: { [name: string]: string[] };
77
	}
D
Dirk Baeumer 已提交
78

79
	export namespace window {
J
Johannes Rieken 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

		/**
		 * Shows a file open dialog to the user.
		 *
		 * @param options Options that control the dialog.
		 * @returns A promise that resolves to the selected resources or `undefined`.
		 */
		export function showOpenDialog(options: OpenDialogOptions): Thenable<Uri[] | undefined>;

		/**
		 * Shows a file save dialog to the user.
		 *
		 * @param options Options that control the dialog.
		 * @returns A promise that resolves to the selected resource or `undefined`.
		 */
		export function showSaveDialog(options: SaveDialogOptions): Thenable<Uri | undefined>;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

		/**
		 * Shows a selection list of [workspace folders](#workspace.workspaceFolders) to pick from.
		 * Returns `undefined` if no folder is open.
		 *
		 * @param options Configures the behavior of the workspace folder list.
		 * @return A promise that resolves to the workspace folder or `undefined`.
		 */
		export function showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined>;
	}

	/**
	 * Options to configure the behaviour of the [workspace folder](#WorkspaceFolder) pick UI.
	 */
	export interface WorkspaceFolderPickOptions {

		/**
		 * An optional string to show as place holder in the input box to guide the user what to pick on.
		 */
		placeHolder?: string;

		/**
		 * Set to `true` to keep the picker open when focus moves to another part of the editor or to another window.
		 */
		ignoreFocusOut?: boolean;
121 122
	}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

	// export enum FileErrorCodes {
	// 	/**
	// 	 * Not owner.
	// 	 */
	// 	EPERM = 1,
	// 	/**
	// 	 * No such file or directory.
	// 	 */
	// 	ENOENT = 2,
	// 	/**
	// 	 * I/O error.
	// 	 */
	// 	EIO = 5,
	// 	/**
	// 	 * Permission denied.
	// 	 */
	// 	EACCES = 13,
	// 	/**
	// 	 * File exists.
	// 	 */
	// 	EEXIST = 17,
	// 	/**
	// 	 * Not a directory.
	// 	 */
	// 	ENOTDIR = 20,
	// 	/**
	// 	 * Is a directory.
	// 	 */
	// 	EISDIR = 21,
	// 	/**
	// 	 *  File too large.
	// 	 */
	// 	EFBIG = 27,
	// 	/**
	// 	 * No space left on device.
	// 	 */
	// 	ENOSPC = 28,
	// 	/**
	// 	 * Directory is not empty.
	// 	 */
	// 	ENOTEMPTY = 66,
	// 	/**
	// 	 * Invalid file handle.
	// 	 */
	// 	ESTALE = 70,
	// 	/**
	// 	 * Illegal NFS file handle.
	// 	 */
	// 	EBADHANDLE = 10001,
	// }

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
	export enum FileChangeType {
		Updated = 0,
		Added = 1,
		Deleted = 2
	}

	export interface FileChange {
		type: FileChangeType;
		resource: Uri;
	}

	export enum FileType {
		File = 0,
		Dir = 1,
		Symlink = 2
	}

	export interface FileStat {
193
		id: number | string;
194 195 196 197 198
		mtime: number;
		size: number;
		type: FileType;
	}

J
Johannes Rieken 已提交
199 200
	// todo@joh discover files etc
	export interface FileSystemProvider {
D
Dirk Baeumer 已提交
201

202 203 204
		onDidChange?: Event<FileChange[]>;

		root: Uri;
205

206 207 208 209
		// more...
		//
		utimes(resource: Uri, mtime: number): Thenable<FileStat>;
		stat(resource: Uri): Thenable<FileStat>;
210 211 212 213 214

		// todo@remote
		// offset - byte offset to start
		// count - number of bytes to read
		// Thenable<number> - number of bytes actually red
215
		read(resource: Uri, progress: Progress<Uint8Array>): Thenable<void>;
216 217 218 219 220

		// todo@remote
		// offset - byte offset to start
		// count - number of bytes to write
		// Thenable<number> - number of bytes actually written
221
		write(resource: Uri, content: Uint8Array): Thenable<void>;
222 223 224

		// todo@remote
		// Thenable<FileStat>
225
		rename(resource: Uri, target: Uri): Thenable<void>;
226 227 228

		// todo@remote
		// Thenable<FileStat>
229
		mkdir(resource: Uri): Thenable<void>;
230 231 232 233 234
		readdir(resource: Uri): Thenable<[Uri, FileStat][]>;

		// todo@remote
		// ? merge both
		// ? recursive del
235
		rmdir(resource: Uri): Thenable<void>;
236 237 238 239 240 241 242 243
		unlink(resource: Uri): Thenable<void>;

		// todo@remote
		// create(resource: Uri): Thenable<FileStat>;

		// todo@remote
		// helps with performance bigly
		// copy(from: Uri, to: Uri): Thenable<void>;
244 245
	}

246
	export namespace workspace {
J
Johannes Rieken 已提交
247
		export function registerFileSystemProvider(authority: string, provider: FileSystemProvider): Disposable;
248 249
	}

250 251 252 253
	export namespace window {

		export function sampleFunction(): Thenable<any>;
	}
P
Pine Wu 已提交
254

J
Joao Moreno 已提交
255 256 257
	/**
	 * The contiguous set of modified lines in a diff.
	 */
J
Joao Moreno 已提交
258 259 260 261 262 263 264
	export interface LineChange {
		readonly originalStartLineNumber: number;
		readonly originalEndLineNumber: number;
		readonly modifiedStartLineNumber: number;
		readonly modifiedEndLineNumber: number;
	}

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	export namespace commands {

		/**
		 * Registers a diff information command that can be invoked via a keyboard shortcut,
		 * a menu item, an action, or directly.
		 *
		 * Diff information commands are different from ordinary [commands](#commands.registerCommand) as
		 * they only execute when there is an active diff editor when the command is called, and the diff
		 * information has been computed. Also, the command handler of an editor command has access to
		 * the diff information.
		 *
		 * @param command A unique identifier for the command.
		 * @param callback A command handler function with access to the [diff information](#LineChange).
		 * @param thisArg The `this` context used when invoking the handler function.
		 * @return Disposable which unregisters this command on disposal.
		 */
		export function registerDiffInformationCommand(command: string, callback: (diff: LineChange[], ...args: any[]) => any, thisArg?: any): Disposable;
	}
D
Daniel Imms 已提交
283

J
Joao Moreno 已提交
284 285 286
	/**
	 * Represents a color in RGBA space.
	 */
287
	export class Color {
J
Joao Moreno 已提交
288 289 290 291

		/**
		 * The red component of this color in the range [0-1].
		 */
292
		readonly red: number;
J
Joao Moreno 已提交
293 294 295 296

		/**
		 * The green component of this color in the range [0-1].
		 */
297
		readonly green: number;
J
Joao Moreno 已提交
298 299 300 301

		/**
		 * The blue component of this color in the range [0-1].
		 */
302 303
		readonly blue: number;

J
Joao Moreno 已提交
304 305 306 307 308 309
		/**
		 * The alpha component of this color in the range [0-1].
		 */
		readonly alpha: number;

		constructor(red: number, green: number, blue: number, alpha: number);
310 311
	}

J
Joao Moreno 已提交
312 313 314
	/**
	 * Represents a color range from a document.
	 */
315
	export class ColorInformation {
J
Joao Moreno 已提交
316 317 318 319

		/**
		 * The range in the document where this color appers.
		 */
320 321
		range: Range;

J
Joao Moreno 已提交
322 323 324
		/**
		 * The actual color value for this color range.
		 */
325 326
		color: Color;

J
Joao Moreno 已提交
327 328 329 330 331 332 333
		/**
		 * Creates a new color range.
		 *
		 * @param range The range the color appears in. Must not be empty.
		 * @param color The value of the color.
		 * @param format The format in which this color is currently formatted.
		 */
334
		constructor(range: Range, color: Color);
M
Michel Kaporin 已提交
335
	}
336

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
	export class ColorPresentation {
		/**
		 * The label of this color presentation. It will be shown on the color
		 * picker header. By default this is also the text that is inserted when selecting
		 * this color presentation.
		 */
		label: string;
		/**
		 * An [edit](#TextEdit) which is applied to a document when selecting
		 * this presentation for the color.  When `falsy` the [label](#ColorPresentation.label)
		 * is used.
		 */
		textEdit?: TextEdit;
		/**
		 * An optional array of additional [text edits](#TextEdit) that are applied when
		 * selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
		 */
		additionalTextEdits?: TextEdit[];
355 356 357 358 359 360 361

		/**
		 * Creates a new color presentation.
		 *
		 * @param label The label of this color presentation.
		 */
		constructor(label: string);
362 363
	}

J
Joao Moreno 已提交
364 365 366 367
	/**
	 * The document color provider defines the contract between extensions and feature of
	 * picking and modifying colors in the editor.
	 */
368
	export interface DocumentColorProvider {
J
Joao Moreno 已提交
369 370 371 372 373
		/**
		 * Provide colors for the given document.
		 *
		 * @param document The document in which the command was invoked.
		 * @param token A cancellation token.
374
		 * @return An array of [color informations](#ColorInformation) or a thenable that resolves to such. The lack of a result
J
Joao Moreno 已提交
375 376
		 * can be signaled by returning `undefined`, `null`, or an empty array.
		 */
377
		provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult<ColorInformation[]>;
378
		/**
379
		 * Provide representations for a color.
380
		 */
381
		provideColorPresentations(document: TextDocument, colorInfo: ColorInformation, token: CancellationToken): ProviderResult<ColorPresentation[]>;
382 383 384 385 386
	}

	export namespace languages {
		export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable;
	}
J
Johannes Rieken 已提交
387
}