Re #34366. Extensions define color formats.

This commit is contained in:
rebornix
2017-09-19 00:03:26 -07:00
parent ff8c917a87
commit d069e922ef
20 changed files with 316 additions and 268 deletions

View File

@@ -551,8 +551,8 @@ export function createApiFactory(
CancellationTokenSource: CancellationTokenSource,
CodeLens: extHostTypes.CodeLens,
Color: extHostTypes.Color,
ColorFormat: extHostTypes.ColorFormat,
ColorRange: extHostTypes.ColorRange,
ColorPresentation: extHostTypes.ColorPresentation,
ColorInformation: extHostTypes.ColorInformation,
EndOfLine: extHostTypes.EndOfLine,
CompletionItem: extHostTypes.CompletionItem,
CompletionItemKind: extHostTypes.CompletionItemKind,

View File

@@ -548,7 +548,7 @@ export interface ExtHostLanguageFeaturesShape {
$provideDocumentLinks(handle: number, resource: URI): TPromise<modes.ILink[]>;
$resolveDocumentLink(handle: number, link: modes.ILink): TPromise<modes.ILink>;
$provideDocumentColors(handle: number, resource: URI): TPromise<IRawColorInfo[]>;
$resolveDocumentColor(handle: number, color: modes.IColor, colorFormat: modes.ColorFormat): TPromise<string>;
$provideColorPresentations(handle: number, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]>;
}
export interface ExtHostQuickOpenShape {

View File

@@ -729,8 +729,19 @@ class ColorProviderAdapter {
});
}
resolveColor(color: modes.IColor, colorFormat: modes.ColorFormat): TPromise<string> {
return asWinJsPromise(token => this._provider.resolveDocumentColor(color, colorFormat));
provideColorPresentations(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]
}
};
return asWinJsPromise(token => this._provider.provideColorPresentations(colorInfo, token)).then(value => {
return value.map(v => TypeConverters.ColorPresentation.from(v));
});
}
}
@@ -1042,8 +1053,8 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColors(resource));
}
$resolveDocumentColor(handle: number, color: modes.IColor, colorFormat: modes.ColorFormat): TPromise<string> {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.resolveColor(color, colorFormat));
$provideColorPresentations(handle: number, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColorPresentations(colorInfo));
}
// --- configuration

View File

@@ -448,6 +448,24 @@ export namespace DocumentLink {
}
}
export namespace ColorPresentation {
export function to(colorPresentation: modes.IColorPresentation): vscode.ColorPresentation {
return {
label: colorPresentation.label,
textEdit: colorPresentation.textEdit ? TextEdit.to(colorPresentation.textEdit) : undefined,
additionalTextEdits: colorPresentation.additionalTextEdits ? colorPresentation.additionalTextEdits.map(value => TextEdit.to(value)) : undefined
};
}
export function from(colorPresentation: vscode.ColorPresentation): modes.IColorPresentation {
return {
label: colorPresentation.label,
textEdit: colorPresentation.textEdit ? TextEdit.from(colorPresentation.textEdit) : undefined,
additionalTextEdits: colorPresentation.additionalTextEdits ? colorPresentation.additionalTextEdits.map(value => TextEdit.from(value)) : undefined
};
}
}
export namespace TextDocumentSaveReason {
export function to(reason: SaveReason): vscode.TextDocumentSaveReason {

View File

@@ -1055,7 +1055,7 @@ export class Color {
export type IColorFormat = string | { opaque: string, transparent: string };
export class ColorRange {
export class ColorInformation {
range: Range;
color: Color;
@@ -1072,6 +1072,12 @@ export class ColorRange {
}
}
export class ColorPresentation {
label: string;
textEdit?: TextEdit;
additionalTextEdits?: TextEdit[];
}
export enum ColorFormat {
RGB = 0,
HEX = 1,