diff --git a/extensions/css/client/src/cssMain.ts b/extensions/css/client/src/cssMain.ts index 6b43c68252f..e86425b2d81 100644 --- a/extensions/css/client/src/cssMain.ts +++ b/extensions/css/client/src/cssMain.ts @@ -66,10 +66,10 @@ export function activate(context: ExtensionContext) { }); }); }, - provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): ColorPresentation[] | Thenable { + provideColorPresentations(color: Color, context): ColorPresentation[] | Thenable { let params: ColorPresentationParams = { - textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document), - colorInfo: { range: client.code2ProtocolConverter.asRange(colorInfo.range), color: colorInfo.color } + textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(context.document), + colorInfo: { range: client.code2ProtocolConverter.asRange(context.range), color } }; return client.sendRequest(ColorPresentationRequest.type, params).then(presentations => { return presentations.map(p => { diff --git a/extensions/html/client/src/htmlMain.ts b/extensions/html/client/src/htmlMain.ts index 2dc9899c125..4f355644a04 100644 --- a/extensions/html/client/src/htmlMain.ts +++ b/extensions/html/client/src/htmlMain.ts @@ -83,10 +83,10 @@ export function activate(context: ExtensionContext) { }); }); }, - provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): Thenable { + provideColorPresentations(color, context): Thenable { let params: ColorPresentationParams = { - textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document), - colorInfo: { range: client.code2ProtocolConverter.asRange(colorInfo.range), color: colorInfo.color } + textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(context.document), + colorInfo: { range: client.code2ProtocolConverter.asRange(context.range), color } }; return client.sendRequest(ColorPresentationRequest.type, params).then(presentations => { return presentations.map(p => { @@ -175,4 +175,4 @@ function getPackageInfo(context: ExtensionContext): IPackageInfo { }; } return null; -} \ No newline at end of file +} diff --git a/extensions/json/client/src/jsonMain.ts b/extensions/json/client/src/jsonMain.ts index 1498820c33d..2509a46e385 100644 --- a/extensions/json/client/src/jsonMain.ts +++ b/extensions/json/client/src/jsonMain.ts @@ -145,10 +145,10 @@ export function activate(context: ExtensionContext) { }); }); }, - provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): Thenable { + provideColorPresentations(color: Color, context): Thenable { let params: ColorPresentationParams = { - textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document), - colorInfo: { range: client.code2ProtocolConverter.asRange(colorInfo.range), color: colorInfo.color } + textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(context.document), + colorInfo: { range: client.code2ProtocolConverter.asRange(context.range), color } }; return client.sendRequest(ColorPresentationRequest.type, params).then(presentations => { return presentations.map(p => { @@ -288,4 +288,4 @@ function getPackageInfo(context: ExtensionContext): IPackageInfo { }; } return null; -} \ No newline at end of file +} diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 4c7756fbfcb..68b3d1b5d45 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -2996,6 +2996,8 @@ declare module 'vscode' { resolveDocumentLink?(link: DocumentLink, token: CancellationToken): ProviderResult; } + + /** * A tuple of two characters, like a pair of * opening and closing brackets. diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index fd6f8cf68e3..ee6b4bbc923 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -194,6 +194,14 @@ declare module 'vscode' { */ readonly alpha: number; + /** + * Creates a new color instance. + * + * @param red The red component. + * @param green The green component. + * @param blue The bluew component. + * @param alpha The alpha component. + */ constructor(red: number, green: number, blue: number, alpha: number); } @@ -222,19 +230,30 @@ declare module 'vscode' { constructor(range: Range, color: Color); } + /** + * A color presentation object describes how a [`color`](#Color) should be represented as text and what + * edits are required to refer to it from source code. + * + * For some languages one color can have multiple presentations, e.g. css can represent the color red with + * the constant `Red`, the hex-value `#ff0000`, or in rgba and hsla forms. In csharp other representations + * apply, e.g `System.Drawing.Color.Red`. + */ 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. @@ -254,6 +273,7 @@ declare module 'vscode' { * picking and modifying colors in the editor. */ export interface DocumentColorProvider { + /** * Provide colors for the given document. * @@ -263,13 +283,32 @@ declare module 'vscode' { * can be signaled by returning `undefined`, `null`, or an empty array. */ provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult; + /** - * Provide representations for a color. + * Provide [representations](#ColorPresentation) for a color. + * + * @param color The color to show and insert. + * @param context A context object with additional information + * @param token A cancellation token. + * @return An array of color presentations or a thenable that resolves to such. The lack of a result + * can be signaled by returning `undefined`, `null`, or an empty array. */ - provideColorPresentations(document: TextDocument, colorInfo: ColorInformation, token: CancellationToken): ProviderResult; + provideColorPresentations(color: Color, context: { document: TextDocument, range: Range }, token: CancellationToken): ProviderResult; } export namespace languages { + + /** + * Register a color provider. + * + * Multiple providers can be registered for a language. In that case providers are asked in + * parallel and the results are merged. A failing provider (rejected promise or exception) will + * not cause a failure of the whole operation. + * + * @param selector A selector that defines the documents this provider is applicable to. + * @param provider A color provider. + * @return A [disposable](#Disposable) that unregisters this provider when being disposed. + */ export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable; } } diff --git a/src/vs/workbench/api/node/extHostLanguageFeatures.ts b/src/vs/workbench/api/node/extHostLanguageFeatures.ts index 4a6a22e86f0..7718b667dd4 100644 --- a/src/vs/workbench/api/node/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/node/extHostLanguageFeatures.ts @@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { mixin } from 'vs/base/common/objects'; import * as vscode from 'vscode'; import * as TypeConverters from 'vs/workbench/api/node/extHostTypeConverters'; -import { Range, Disposable, CompletionList, SnippetString } from 'vs/workbench/api/node/extHostTypes'; +import { Range, Disposable, CompletionList, SnippetString, Color } from 'vs/workbench/api/node/extHostTypes'; import { ISingleEditOperation } from 'vs/editor/common/editorCommon'; import * as modes from 'vs/editor/common/modes'; import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService'; @@ -721,19 +721,12 @@ class ColorProviderAdapter { }); } - provideColorPresentations(resource: URI, rawColorInfo: IRawColorInfo): TPromise { - let colorInfo: vscode.ColorInformation = { - range: TypeConverters.toRange(rawColorInfo.range), - color: { - red: rawColorInfo.color[0], - green: rawColorInfo.color[1], - blue: rawColorInfo.color[2], - alpha: rawColorInfo.color[3] - } - }; - const doc = this._documents.getDocumentData(resource).document; - return asWinJsPromise(token => this._provider.provideColorPresentations(doc, colorInfo, token)).then(value => { - return value.map(v => TypeConverters.ColorPresentation.from(v)); + provideColorPresentations(resource: URI, raw: IRawColorInfo): TPromise { + const document = this._documents.getDocumentData(resource).document; + const range = TypeConverters.toRange(raw.range); + const color = new Color(raw.color[0], raw.color[1], raw.color[2], raw.color[3]); + return asWinJsPromise(token => this._provider.provideColorPresentations(color, { document, range }, token)).then(value => { + return value.map(TypeConverters.ColorPresentation.from); }); } }