vscode.proposed.d.ts 17.7 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 13
	export namespace window {
		export function sampleFunction(): Thenable<any>;
	}

14
	//#region Joh: file system provider (OLD)
J
Johannes Rieken 已提交
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	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 {
34
		id: number | string;
35
		mtime: number;
J
Johannes Rieken 已提交
36
		// atime: number;
37 38 39 40
		size: number;
		type: FileType;
	}

J
Johannes Rieken 已提交
41
	// todo@joh discover files etc
J
Johannes Rieken 已提交
42
	// todo@joh CancellationToken everywhere
J
Johannes Rieken 已提交
43
	// todo@joh add open/close calls?
J
Johannes Rieken 已提交
44
	export interface FileSystemProvider {
D
Dirk Baeumer 已提交
45

J
Johannes Rieken 已提交
46
		readonly onDidChange?: Event<FileChange[]>;
47 48

		// more...
49
		// @deprecated - will go away
J
Johannes Rieken 已提交
50
		utimes(resource: Uri, mtime: number, atime: number): Thenable<FileStat>;
51

52
		stat(resource: Uri): Thenable<FileStat>;
53

54
		read(resource: Uri, offset: number, length: number, progress: Progress<Uint8Array>): Thenable<number>;
55

J
Johannes Rieken 已提交
56
		// todo@joh - have an option to create iff not exist
57 58 59 60
		// todo@remote
		// offset - byte offset to start
		// count - number of bytes to write
		// Thenable<number> - number of bytes actually written
61
		write(resource: Uri, content: Uint8Array): Thenable<void>;
62 63 64

		// todo@remote
		// Thenable<FileStat>
65 66 67 68 69
		move(resource: Uri, target: Uri): Thenable<FileStat>;

		// todo@remote
		// helps with performance bigly
		// copy?(from: Uri, to: Uri): Thenable<void>;
70 71 72

		// todo@remote
		// Thenable<FileStat>
73
		mkdir(resource: Uri): Thenable<FileStat>;
74

75 76 77 78 79
		readdir(resource: Uri): Thenable<[Uri, FileStat][]>;

		// todo@remote
		// ? merge both
		// ? recursive del
80
		rmdir(resource: Uri): Thenable<void>;
81 82 83 84
		unlink(resource: Uri): Thenable<void>;

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

87 88 89 90 91 92 93 94
	export type DeprecatedFileChangeType = FileChangeType;
	export type DeprecatedFileType = FileType;
	export type DeprecatedFileChange = FileChange;
	export type DeprecatedFileStat = FileStat;
	export type DeprecatedFileSystemProvider = FileSystemProvider;

	export namespace workspace {
		export function registerDeprecatedFileSystemProvider(scheme: string, provider: DeprecatedFileSystemProvider): Disposable;
95
		export function registerFileSystemProvider(scheme: string, provider: FileSystemProvider, newProvider?: FileSystemProvider2): Disposable;
96 97 98 99 100 101
	}

	//#endregion

	//#region Joh: file system provider (new)

J
Johannes Rieken 已提交
102
	/**
103
	 *
J
Johannes Rieken 已提交
104
	 */
105
	export class FileSystemError extends Error {
106

107 108 109 110
		static EntryExists(message?: string): FileSystemError;
		static EntryNotFound(message?: string): FileSystemError;
		static EntryNotADirectory(message?: string): FileSystemError;
		static EntryIsADirectory(message?: string): FileSystemError;
111

J
Johannes Rieken 已提交
112 113
		constructor(message?: string);
	}
114

115 116 117 118 119 120 121 122
	export enum FileChangeType2 {
		Changed = 1,
		Created = 2,
		Deleted = 3,
	}

	export interface FileChange2 {
		type: FileChangeType2;
123
		uri: Uri;
124 125 126
	}

	export interface FileStat2 {
127 128 129
		isFile: boolean;
		isDirectory: boolean;
		isSymbolicLink: boolean;
130 131 132 133
		mtime: number;
		size: number;
	}

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

161 162 163
	/**
	 *
	 */
164 165
	export interface FileSystemProvider2 {

166
		_version: 9;
167

J
Johannes Rieken 已提交
168
		/**
169 170 171
		 * 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.
J
Johannes Rieken 已提交
172
		 */
173 174 175
		readonly onDidChangeFile: Event<FileChange2[]>;

		/**
176 177 178
		 * Subscribe to events in the file or folder denoted by `uri`.
		 * @param uri
		 * @param options
179 180
		 */
		watch(uri: Uri, options: { recursive?: boolean; excludes?: string[] }): Disposable;
181

J
Johannes Rieken 已提交
182
		/**
183 184
		 * Retrieve metadata about a file. Throw an [`EntryNotFound`](#FileError.EntryNotFound)-error
		 * in case the file does not exist.
J
Johannes Rieken 已提交
185 186 187
		 *
		 * @param uri The uri of the file to retrieve meta data about.
		 * @param token A cancellation token.
J
Johannes Rieken 已提交
188
		 * @return The file metadata about the file.
J
Johannes Rieken 已提交
189
		 */
190
		stat(uri: Uri, options: { /*future: followSymlinks*/ }, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
191

J
Johannes Rieken 已提交
192 193 194 195 196
		/**
		 * Retrieve the meta data of all entries of a [directory](#FileType2.Directory)
		 *
		 * @param uri The uri of the folder.
		 * @param token A cancellation token.
197
		 * @return A thenable that resolves to an array of tuples of file names and files stats.
J
Johannes Rieken 已提交
198
		 */
199
		readDirectory(uri: Uri, options: { /*future: onlyType?*/ }, token: CancellationToken): [string, FileStat2][] | Thenable<[string, FileStat2][]>;
200

201 202
		/**
		 * Create a new directory. *Note* that new files are created via `write`-calls.
203
		 *
204 205 206
		 * @param uri The uri of the *new* folder.
		 * @param token A cancellation token.
		 */
207
		createDirectory(uri: Uri, options: { /*future: permissions?*/ }, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
208

J
Johannes Rieken 已提交
209 210 211 212 213 214 215
		/**
		 * 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.
		 */
216
		readFile(uri: Uri, options: FileOptions, token: CancellationToken): Uint8Array | Thenable<Uint8Array>;
217

J
Johannes Rieken 已提交
218 219 220 221 222 223 224
		/**
		 * 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.
		 */
225
		writeFile(uri: Uri, content: Uint8Array, options: FileOptions, token: CancellationToken): void | Thenable<void>;
226

227
		/**
228 229
		 * Delete a file or folder from the underlying storage.
		 *
230 231 232 233 234 235
		 * @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>;

J
Johannes Rieken 已提交
236 237 238
		/**
		 * Rename a file or folder.
		 *
239 240
		 * @param oldUri The existing file or folder.
		 * @param newUri The target location.
J
Johannes Rieken 已提交
241 242
		 * @param token A cancellation token.
		 */
243
		rename(oldUri: Uri, newUri: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
244

245 246 247 248 249 250 251 252
		/**
		 * 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.
		 */
253
		copy?(uri: Uri, target: Uri, options: FileOptions, token: CancellationToken): FileStat2 | Thenable<FileStat2>;
254 255
	}

256
	export namespace workspace {
257
		export function registerFileSystemProvider2(scheme: string, provider: FileSystemProvider2, options: { isCaseSensitive?: boolean }): Disposable;
258
	}
J
Johannes Rieken 已提交
259

260 261 262 263 264 265
	//#endregion

	//#region Joh: remote, search provider

	export interface TextSearchQuery {
		pattern: string;
266
		isRegExp?: boolean;
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
		isCaseSensitive?: boolean;
		isWordMatch?: boolean;
	}

	export interface TextSearchOptions {
		includes: GlobPattern[];
		excludes: GlobPattern[];
	}

	export interface TextSearchResult {
		uri: Uri;
		range: Range;
		preview: { leading: string, matching: string, trailing: string };
	}

	export interface SearchProvider {
		provideFileSearchResults?(query: string, progress: Progress<Uri>, token: CancellationToken): Thenable<void>;
284
		provideTextSearchResults?(query: TextSearchQuery, options: TextSearchOptions, progress: Progress<TextSearchResult>, token: CancellationToken): Thenable<void>;
285 286
	}

287
	export namespace workspace {
288
		export function registerSearchProvider(scheme: string, provider: SearchProvider): Disposable;
289 290
	}

J
Johannes Rieken 已提交
291
	//#endregion
292

J
Johannes Rieken 已提交
293
	//#region Joao: diff command
P
Pine Wu 已提交
294

J
Joao Moreno 已提交
295 296 297
	/**
	 * The contiguous set of modified lines in a diff.
	 */
J
Joao Moreno 已提交
298 299 300 301 302 303 304
	export interface LineChange {
		readonly originalStartLineNumber: number;
		readonly originalEndLineNumber: number;
		readonly modifiedStartLineNumber: number;
		readonly modifiedEndLineNumber: number;
	}

305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	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;
	}
323

J
Johannes Rieken 已提交
324 325 326
	//#endregion

	//#region Joh: decorations
327 328 329 330 331

	//todo@joh -> make class
	export interface DecorationData {
		priority?: number;
		title?: string;
332
		bubble?: boolean;
333 334
		abbreviation?: string;
		color?: ThemeColor;
335
		source?: string;
336 337
	}

338 339 340 341 342 343
	export interface SourceControlResourceDecorations {
		source?: string;
		letter?: string;
		color?: ThemeColor;
	}

344
	export interface DecorationProvider {
345
		onDidChangeDecorations: Event<undefined | Uri | Uri[]>;
346 347 348 349
		provideDecoration(uri: Uri, token: CancellationToken): ProviderResult<DecorationData>;
	}

	export namespace window {
350
		export function registerDecorationProvider(provider: DecorationProvider): Disposable;
351 352 353
	}

	//#endregion
354

J
Johannes Rieken 已提交
355 356
	//#region André: debug

357 358 359 360 361 362
	/**
	 * Represents a debug adapter executable and optional arguments passed to it.
	 */
	export class DebugAdapterExecutable {
		/**
		 * The command path of the debug adapter executable.
A
Andre Weinand 已提交
363
		 * A command must be either an absolute path or the name of an executable looked up via the PATH environment variable.
364 365 366 367 368
		 * The special value 'node' will be mapped to VS Code's built-in node runtime.
		 */
		readonly command: string;

		/**
A
Andre Weinand 已提交
369
		 * Optional arguments passed to the debug adapter executable.
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
		 */
		readonly args: string[];

		/**
		 * Create a new debug adapter specification.
		 */
		constructor(command: string, args?: string[]);
	}

	export interface DebugConfigurationProvider {
		/**
		 * This optional method is called just before a debug adapter is started to determine its excutable path and arguments.
		 * Registering more than one debugAdapterExecutable for a type results in an error.
		 * @param folder The workspace folder from which the configuration originates from or undefined for a folderless setup.
		 * @param token A cancellation token.
		 * @return a [debug adapter's executable and optional arguments](#DebugAdapterExecutable) or undefined.
		 */
		debugAdapterExecutable?(folder: WorkspaceFolder | undefined, token?: CancellationToken): ProviderResult<DebugAdapterExecutable>;
	}

J
Johannes Rieken 已提交
390 391 392 393
	//#endregion

	//#region Rob, Matt: logging

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
	/**
	 * The severity level of a log message
	 */
	export enum LogLevel {
		Trace = 1,
		Debug = 2,
		Info = 3,
		Warning = 4,
		Error = 5,
		Critical = 6,
		Off = 7
	}

	/**
	 * A logger for writing to an extension's log file, and accessing its dedicated log directory.
	 */
	export interface Logger {
		trace(message: string, ...args: any[]): void;
		debug(message: string, ...args: any[]): void;
		info(message: string, ...args: any[]): void;
		warn(message: string, ...args: any[]): void;
		error(message: string | Error, ...args: any[]): void;
		critical(message: string | Error, ...args: any[]): void;
	}

	export interface ExtensionContext {
		/**
R
Rob Lourens 已提交
421
		 * This extension's logger
422 423
		 */
		logger: Logger;
424 425 426 427 428 429 430

		/**
		 * Path where an extension can write log files.
		 *
		 * Extensions must create this directory before writing to it. The parent directory will always exist.
		 */
		readonly logDirectory: string;
431
	}
432

M
Matt Bierner 已提交
433 434 435 436 437 438 439 440 441
	export namespace env {
		/**
		 * Current logging level.
		 *
		 * @readonly
		 */
		export const logLevel: LogLevel;
	}

J
Johannes Rieken 已提交
442 443 444
	//#endregion

	//#region Joao: SCM validation
445

J
Joao Moreno 已提交
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
	/**
	 * Represents the validation type of the Source Control input.
	 */
	export enum SourceControlInputBoxValidationType {

		/**
		 * Something not allowed by the rules of a language or other means.
		 */
		Error = 0,

		/**
		 * Something suspicious but allowed.
		 */
		Warning = 1,

		/**
		 * Something to inform about but not a problem.
		 */
		Information = 2
	}

	export interface SourceControlInputBoxValidation {

		/**
		 * The validation message to display.
		 */
		readonly message: string;

		/**
		 * The validation type.
		 */
		readonly type: SourceControlInputBoxValidationType;
	}

	/**
	 * Represents the input box in the Source Control viewlet.
	 */
	export interface SourceControlInputBox {

		/**
		 * A validation function for the input box. It's possible to change
		 * the validation provider simply by setting this property to a different function.
		 */
		validateInput?(value: string, cursorPosition: number): ProviderResult<SourceControlInputBoxValidation | undefined | null>;
	}
M
Matt Bierner 已提交
491

J
Johannes Rieken 已提交
492 493
	//#endregion

494
	//#region Matt: WebView Serializer
495

496
	/**
497
	 * Save and restore webview panels that have been persisted when vscode shuts down.
498
	 */
499
	interface WebviewPanelSerializer {
500
		/**
501
		 * Save a webview panel's `state`.
502
		 *
503 504
		 * Called before shutdown. Extensions have a 250ms timeframe to return a state. If serialization
		 * takes longer than 250ms, the panel will not be serialized.
505
		 *
506
		 * @param webviewPanel webview Panel to serialize. May or may not be visible.
507 508 509
		 *
		 * @returns JSON serializable state blob.
		 */
510
		serializeWebviewPanel(webviewPanel: WebviewPanel): Thenable<any>;
511 512

		/**
513
		 * Restore a webview panel from its seriailzed `state`.
514
		 *
515
		 * Called when a serialized webview first becomes visible.
516
		 *
517
		 * @param webviewPanel Webview panel to restore. The serializer should take ownership of this panel.
518
		 * @param state Persisted state.
519 520
		 *
		 * @return Thanble indicating that the webview has been fully restored.
521
		 */
522
		deserializeWebviewPanel(webviewPanel: WebviewPanel, state: any): Thenable<void>;
523 524
	}

M
Matt Bierner 已提交
525
	namespace window {
526
		/**
527
		 * Registers a webview panel serializer.
528 529
		 *
		 * Extensions that support reviving should have an `"onView:viewType"` activation method and
530
		 * make sure that [registerWebviewPanelSerializer](#registerWebviewPanelSerializer) is called during activation.
531 532 533
		 *
		 * Only a single serializer may be registered at a time for a given `viewType`.
		 *
534
		 * @param viewType Type of the webview panel that can be serialized.
535 536
		 * @param reviver Webview serializer.
		 */
537
		export function registerWebviewPanelSerializer(viewType: string, reviver: WebviewPanelSerializer): Disposable;
M
Matt Bierner 已提交
538
	}
S
Sandeep Somavarapu 已提交
539

J
Johannes Rieken 已提交
540 541
	//#endregion

542 543 544
	//#region Tasks

	/**
545 546
	 * An object representing an executed Task. It can be used
	 * to terminate a task.
D
Dirk Baeumer 已提交
547 548
	 *
	 * This interface is not intended to be implemented.
549
	 */
550
	export interface TaskExecution {
D
Dirk Baeumer 已提交
551 552 553 554 555 556 557 558 559
		/**
		 * The task that got started.
		 */
		task: Task;

		/**
		 * Terminates the task execution.
		 */
		terminate(): void;
560 561 562 563
	}

	/**
	 * An event signaling the start of a task execution.
D
Dirk Baeumer 已提交
564 565
	 *
	 * This interface is not intended to be implemented.
566 567 568 569 570 571 572 573 574 575
	 */
	interface TaskStartEvent {
		/**
		 * The task item representing the task that got started.
		 */
		execution: TaskExecution;
	}

	/**
	 * An event signaling the end of an executed task.
D
Dirk Baeumer 已提交
576 577
	 *
	 * This interface is not intended to be implemented.
578 579 580 581 582 583 584 585
	 */
	interface TaskEndEvent {
		/**
		 * The task item representing the task that finished.
		 */
		execution: TaskExecution;
	}

586 587 588 589 590 591 592 593 594 595 596 597 598
	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;
	}

599
	export namespace workspace {
600 601

		/**
602
		 * Fetches all task available in the systems. Thisweweb includes tasks
603 604
		 * from `tasks.json` files as well as tasks from task providers
		 * contributed through extensions.
605 606
		 *
		 * @param filter a filter to filter the return tasks.
607
		 */
608
		export function fetchTasks(filter?: TaskFilter): Thenable<Task[]>;
609 610

		/**
611 612 613 614
		 * Executes a task that is managed by VS Code. The returned
		 * task execution can be used to terminate the task.
		 *
		 * @param task the task to execute
615
		 */
616
		export function executeTask(task: Task): Thenable<TaskExecution>;
D
Dirk Baeumer 已提交
617

618 619 620 621 622 623 624
		/**
		 * The currently active task executions or an empty array.
		 *
		 * @readonly
		 */
		export let taskExecutions: TaskExecution[];

D
Dirk Baeumer 已提交
625
		/**
626 627 628 629
		 * Fires when a task starts.
		 */
		export const onDidStartTask: Event<TaskStartEvent>;

630
		/**
631
		 * Fires when a task ends.
632
		 */
633
		export const onDidEndTask: Event<TaskEndEvent>;
634 635 636
	}

	//#endregion
637 638 639

	//#region Terminal

D
Daniel Imms 已提交
640 641 642 643
	export interface Terminal {
		onData: Event<string>;
	}

644
	export namespace window {
D
Daniel Imms 已提交
645
		/**
D
jsdoc  
Daniel Imms 已提交
646 647
		 * The currently active terminals or an empty array.
		 *
D
Daniel Imms 已提交
648 649 650 651
		 * @readonly
		 */
		export let terminals: Terminal[];

D
jsdoc  
Daniel Imms 已提交
652 653 654 655
		/**
		 * An [event](#Event) which fires when a terminal has been created, either through the
		 * [createTerminal](#window.createTerminal) API or commands.
		 */
656 657 658 659
		export const onDidOpenTerminal: Event<Terminal>;
	}

	//#endregion
J
Joao Moreno 已提交
660 661 662

	//#region URLs

J
Joao Moreno 已提交
663 664
	export interface ExternalUriHandler {
		handleExternalUri(uri: Uri): void;
J
Joao Moreno 已提交
665 666 667 668 669
	}

	export namespace window {

		/**
J
Joao Moreno 已提交
670
		 * Registers a protocol handler capable of handling system-wide URIs.
J
Joao Moreno 已提交
671
		 */
J
Joao Moreno 已提交
672
		export function registerExternalUriHandler(handler: ExternalUriHandler): Disposable;
J
Joao Moreno 已提交
673 674 675
	}

	//#endregion
J
Johannes Rieken 已提交
676
}