mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
Re #34366. Extensions define color formats.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user