provideColorPresentations should have document in paramaters.

This commit is contained in:
rebornix 2017-09-20 13:44:57 -07:00
parent ce20acd130
commit 084849c2fa
11 changed files with 18 additions and 17 deletions

View file

@ -70,7 +70,7 @@ export function activate(context: ExtensionContext) {
});
});
},
provideColorPresentations(colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
let result: ColorPresentation[] = [];
let color = colorInfo.color;
let label;

View file

@ -87,7 +87,7 @@ export function activate(context: ExtensionContext) {
});
});
},
provideColorPresentations(colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
let result: ColorPresentation[] = [];
let color = colorInfo.color;
let label;

View file

@ -132,7 +132,7 @@ export function activate(context: ExtensionContext) {
});
});
},
provideColorPresentations(colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation): ColorPresentation[] | Thenable<ColorPresentation[]> {
let result: ColorPresentation[] = [];
let color = colorInfo.color;
let label;

View file

@ -728,7 +728,7 @@ export interface DocumentColorProvider {
/**
* Provide the string representations for a color.
*/
provideColorPresentations(colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
provideColorPresentations(model: editorCommon.IReadOnlyModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
}
export interface IResourceEdit {

View file

@ -27,6 +27,6 @@ export function getColors(model: IReadOnlyModel): TPromise<IColorData[]> {
return TPromise.join(promises).then(() => colors);
}
export function getColorPresentations(colorInfo: IColorInformation, provider: DocumentColorProvider): TPromise<IColorPresentation[]> {
return asWinJsPromise(token => provider.provideColorPresentations(colorInfo, token));
export function getColorPresentations(model: IReadOnlyModel, colorInfo: IColorInformation, provider: DocumentColorProvider): TPromise<IColorPresentation[]> {
return asWinJsPromise(token => provider.provideColorPresentations(model, colorInfo, token));
}

View file

@ -325,7 +325,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
const model = new ColorPickerModel(color, [], 0);
const widget = new ColorPickerWidget(fragment, model, this._editor.getConfiguration().pixelRatio);
getColorPresentations(colorInfo, msg.provider).then(colorPresentations => {
getColorPresentations(editorModel, colorInfo, msg.provider).then(colorPresentations => {
model.colorPresentations = colorPresentations;
const originalText = this._editor.getModel().getValueInRange(msg.range);
model.guessColorPresentation(color, originalText);
@ -360,7 +360,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
};
const updateColorPresentations = (color: Color) => {
return getColorPresentations({
return getColorPresentations(editorModel, {
range: range,
color: {
red: color.rgba.r / 255,

2
src/vs/monaco.d.ts vendored
View file

@ -4904,7 +4904,7 @@ declare module monaco.languages {
/**
* Provide the string representations for a color.
*/
provideColorPresentations(colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
provideColorPresentations(model: editor.IReadOnlyModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
}
export interface IResourceEdit {

View file

@ -222,7 +222,7 @@ declare module 'vscode' {
/**
* Provide representations for a color.
*/
provideColorPresentations(colorInfo: ColorInformation, token: CancellationToken): ProviderResult<ColorPresentation[]>;
provideColorPresentations(document: TextDocument, colorInfo: ColorInformation, token: CancellationToken): ProviderResult<ColorPresentation[]>;
}
export namespace languages {

View file

@ -306,8 +306,8 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
});
},
provideColorPresentations: (colorInfo, token) => {
return wireCancellationToken(token, proxy.$provideColorPresentations(handle, {
provideColorPresentations: (model, colorInfo, token) => {
return wireCancellationToken(token, proxy.$provideColorPresentations(handle, model.uri, {
color: [colorInfo.color.red, colorInfo.color.green, colorInfo.color.blue, colorInfo.color.alpha],
range: colorInfo.range
}));

View file

@ -559,7 +559,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[]>;
$provideColorPresentations(handle: number, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]>;
$provideColorPresentations(handle: number, resource: URI, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]>;
}
export interface ExtHostQuickOpenShape {

View file

@ -729,7 +729,7 @@ class ColorProviderAdapter {
});
}
provideColorPresentations(rawColorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
provideColorPresentations(resource: URI, rawColorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
let colorInfo: vscode.ColorInformation = {
range: TypeConverters.toRange(rawColorInfo.range),
color: {
@ -739,7 +739,8 @@ class ColorProviderAdapter {
alpha: rawColorInfo.color[3]
}
};
return asWinJsPromise(token => this._provider.provideColorPresentations(colorInfo, token)).then(value => {
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));
});
}
@ -1053,8 +1054,8 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColors(resource));
}
$provideColorPresentations(handle: number, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColorPresentations(colorInfo));
$provideColorPresentations(handle: number, resource: URI, colorInfo: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColorPresentations(resource, colorInfo));
}
// --- configuration