vscode.proposed.d.ts 7.5 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
	// todo@joh discover files etc
	export interface FileSystemProvider {
		// todo@joh -> added, deleted, renamed, changed
		onDidChange: Event<Uri>;
D
Dirk Baeumer 已提交
14

J
Johannes Rieken 已提交
15 16
		resolveContents(resource: Uri): string | Thenable<string>;
		writeContents(resource: Uri, contents: string): void | Thenable<void>;
17 18 19
	}

	export namespace workspace {
J
Johannes Rieken 已提交
20 21

		export function registerFileSystemProvider(authority: string, provider: FileSystemProvider): Disposable;
22 23
	}

24 25 26 27
	export namespace window {

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

J
Joao Moreno 已提交
29 30 31
	/**
	 * The contiguous set of modified lines in a diff.
	 */
J
Joao Moreno 已提交
32 33 34 35 36 37 38
	export interface LineChange {
		readonly originalStartLineNumber: number;
		readonly originalEndLineNumber: number;
		readonly modifiedStartLineNumber: number;
		readonly modifiedEndLineNumber: number;
	}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
	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 已提交
57

58
	/**
C
Christof Marti 已提交
59
	 * Namespace for handling credentials.
60
	 */
C
Christof Marti 已提交
61
	export namespace credentials {
62 63

		/**
C
Christof Marti 已提交
64
		 * Read a previously stored secret from the credential store.
D
Daniel Imms 已提交
65
		 *
C
Christof Marti 已提交
66 67 68
		 * @param service The service of the credential.
		 * @param account The account of the credential.
		 * @return A promise for the secret of the credential.
69
		 */
C
Christof Marti 已提交
70
		export function readSecret(service: string, account: string): Thenable<string | undefined>;
71 72

		/**
C
Christof Marti 已提交
73
		 * Write a secret to the credential store.
D
Daniel Imms 已提交
74
		 *
C
Christof Marti 已提交
75 76 77 78
		 * @param service The service of the credential.
		 * @param account The account of the credential.
		 * @param secret The secret of the credential to write to the credential store.
		 * @return A promise indicating completion of the operation.
79
		 */
C
Christof Marti 已提交
80
		export function writeSecret(service: string, account: string, secret: string): Thenable<void>;
81 82

		/**
C
Christof Marti 已提交
83
		 * Delete a previously stored secret from the credential store.
D
Daniel Imms 已提交
84
		 *
C
Christof Marti 已提交
85 86 87
		 * @param service The service of the credential.
		 * @param account The account of the credential.
		 * @return A promise resolving to true if there was a secret for that service and account.
88
		 */
C
Christof Marti 已提交
89
		export function deleteSecret(service: string, account: string): Thenable<boolean>;
90
	}
91

J
Joao Moreno 已提交
92 93 94
	/**
	 * Represents a color in RGBA space.
	 */
95
	export class Color {
J
Joao Moreno 已提交
96 97 98 99

		/**
		 * The red component of this color in the range [0-1].
		 */
100
		readonly red: number;
J
Joao Moreno 已提交
101 102 103 104

		/**
		 * The green component of this color in the range [0-1].
		 */
105
		readonly green: number;
J
Joao Moreno 已提交
106 107 108 109

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

J
Joao Moreno 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
		/**
		 * The alpha component of this color in the range [0-1].
		 */
		readonly alpha: number;

		constructor(red: number, green: number, blue: number, alpha: number);

		/**
		 * Creates a color from the HSLA space.
		 *
		 * @param hue The hue component in the range [0-1].
		 * @param saturation The saturation component in the range [0-1].
		 * @param luminance The luminance component in the range [0-1].
		 * @param alpha The alpha component in the range [0-1].
		 */
		static fromHSLA(hue: number, saturation: number, luminance: number, alpha: number): Color;
128

J
Joao Moreno 已提交
129
		// TODO: this isn't needed. this is a parsing util. remove
130
		static fromHex(hex: string): Color;
131 132
	}

J
Joao Moreno 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	/**
	 * A color format is either a single format or a combination of two
	 * formats: an opaque one and a transparent one. The format itself
	 * is a string representation of how the color can be formatted. It
	 * supports the use of placeholders, similar to how snippets work.
	 * Each placeholder, surrounded by curly braces `{}`, requires a
	 * variable name and can optionally specify a number format and range
	 * for that variable's value.
	 *
	 * Supported variables:
	 *  - `red`
	 *  - `green`
	 *  - `blue`
	 *  - `hue`
	 *  - `saturation`
J
Joao Moreno 已提交
148
	 *  - `luminance`
J
Joao Moreno 已提交
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
	 *  - `alpha`
	 *
	 * Supported number formats:
	 *  - `f`, float with 2 decimal points. This is the default format. Default range is `[0-1]`.
	 *  - `Xf`, float with `X` decimal points. Default range is `[0-1]`.
	 *  - `d`, decimal. Default range is `[0-255]`.
	 *  - `h`, `H`, hexadecimal. Default range is `[00-FF]`.
	 *
	 * The default number format is float. The default number range is `[0-1]`.
	 *
	 * As an example, take the color `Color(1, 0.5, 0, 1)`. Here's how
	 * different formats would format it:
	 *
	 *  - CSS RGB
	 *   - Format: `rgb({red:d[0-255]}, {green:d[0-255]}, {blue:d[0-255]})`
	 *   - Output: `rgb(255, 127, 0)`
	 *
	 *  - CSS RGBA
	 *   - Format: `rgba({red:d[0-255]}, {green:d[0-255]}, {blue:d[0-255]}, {alpha})`
	 *   - Output: `rgba(255, 127, 0, 1)`
	 *
	 *  - CSS Hexadecimal
	 *   - Format: `#{red:X}{green:X}{blue:X}`
	 *   - Output: `#FF7F00`
	 *
	 *  - CSS HSLA
J
Joao Moreno 已提交
175
	 *   - Format: `hsla({hue:d[0-360]}, {saturation:d[0-100]}%, {luminance:d[0-100]}%, {alpha})`
J
Joao Moreno 已提交
176 177
	 *   - Output: `hsla(30, 100%, 50%, 1)`
	 */
J
Joao Moreno 已提交
178 179
	export type ColorFormat = string | { opaque: string, transparent: string };

J
Joao Moreno 已提交
180 181 182 183 184 185 186 187
	/**
	 * Represents a color range from a document.
	 */
	export class ColorRange {

		/**
		 * The range in the document where this color appers.
		 */
188 189
		range: Range;

J
Joao Moreno 已提交
190 191 192
		/**
		 * The actual color value for this color range.
		 */
193 194
		color: Color;

J
Joao Moreno 已提交
195 196 197
		/**
		 * The other formats this color range supports the color to be formatted in.
		 */
J
Joao Moreno 已提交
198
		availableFormats: ColorFormat[];
199

J
Joao Moreno 已提交
200 201 202 203 204 205 206 207
		/**
		 * 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.
		 * @param availableFormats The other formats this color range supports the color to be formatted in.
		 */
208
		constructor(range: Range, color: Color, availableFormats: ColorFormat[]);
M
Michel Kaporin 已提交
209
	}
210

J
Joao Moreno 已提交
211 212 213 214
	/**
	 * The document color provider defines the contract between extensions and feature of
	 * picking and modifying colors in the editor.
	 */
215
	export interface DocumentColorProvider {
J
Joao Moreno 已提交
216 217 218 219 220 221 222 223 224 225

		/**
		 * Provide colors for the given document.
		 *
		 * @param document The document in which the command was invoked.
		 * @param token A cancellation token.
		 * @return An array of [color ranges](#ColorRange) or a thenable that resolves to such. The lack of a result
		 * can be signaled by returning `undefined`, `null`, or an empty array.
		 */
		provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult<ColorRange[]>;
226 227 228 229 230
	}

	export namespace languages {
		export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable;
	}
231
}