mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
color - jsdoc and tiny tweaks for color provider api
This commit is contained in:
parent
a71c987a4d
commit
65a2d30efe
|
@ -66,10 +66,10 @@ export function activate(context: ExtensionContext) {
|
|||
});
|
||||
});
|
||||
},
|
||||
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
|
||||
provideColorPresentations(color: Color, context): ColorPresentation[] | Thenable<ColorPresentation[]> {
|
||||
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 => {
|
||||
|
|
|
@ -83,10 +83,10 @@ export function activate(context: ExtensionContext) {
|
|||
});
|
||||
});
|
||||
},
|
||||
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): Thenable<ColorPresentation[]> {
|
||||
provideColorPresentations(color, context): Thenable<ColorPresentation[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,10 +145,10 @@ export function activate(context: ExtensionContext) {
|
|||
});
|
||||
});
|
||||
},
|
||||
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): Thenable<ColorPresentation[]> {
|
||||
provideColorPresentations(color: Color, context): Thenable<ColorPresentation[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
2
src/vs/vscode.d.ts
vendored
2
src/vs/vscode.d.ts
vendored
|
@ -2996,6 +2996,8 @@ declare module 'vscode' {
|
|||
resolveDocumentLink?(link: DocumentLink, token: CancellationToken): ProviderResult<DocumentLink>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A tuple of two characters, like a pair of
|
||||
* opening and closing brackets.
|
||||
|
|
43
src/vs/vscode.proposed.d.ts
vendored
43
src/vs/vscode.proposed.d.ts
vendored
|
@ -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<ColorInformation[]>;
|
||||
|
||||
/**
|
||||
* 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<ColorPresentation[]>;
|
||||
provideColorPresentations(color: Color, context: { document: TextDocument, range: Range }, token: CancellationToken): ProviderResult<ColorPresentation[]>;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<modes.IColorPresentation[]> {
|
||||
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<modes.IColorPresentation[]> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue