mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Updated color API and color info conversion between extHost and main. Added color picker disposal, more listeners.
This commit is contained in:
@@ -261,12 +261,13 @@ export function createApiFactory(
|
||||
registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
|
||||
return languageFeatures.registerDocumentLinkProvider(selector, provider);
|
||||
},
|
||||
registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
|
||||
return languageFeatures.registerColorProvider(selector, provider);
|
||||
},
|
||||
setLanguageConfiguration: (language: string, configuration: vscode.LanguageConfiguration): vscode.Disposable => {
|
||||
return languageFeatures.setLanguageConfiguration(language, configuration);
|
||||
}
|
||||
},
|
||||
// proposed API
|
||||
registerColorProvider: proposedApiFunction(extension, (selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider) => {
|
||||
return languageFeatures.registerColorProvider(selector, provider);
|
||||
})
|
||||
};
|
||||
|
||||
// namespace: window
|
||||
@@ -491,7 +492,6 @@ export function createApiFactory(
|
||||
CodeLens: extHostTypes.CodeLens,
|
||||
Color: extHostTypes.Color,
|
||||
ColorInfo: extHostTypes.ColorInfo,
|
||||
ColorType: extHostTypes.ColorType,
|
||||
EndOfLine: extHostTypes.EndOfLine,
|
||||
CompletionItem: extHostTypes.CompletionItem,
|
||||
CompletionItemKind: extHostTypes.CompletionItemKind,
|
||||
|
||||
@@ -454,6 +454,11 @@ export abstract class ExtHostHeapServiceShape {
|
||||
$onGarbageCollection(ids: number[]): void { throw ni(); }
|
||||
}
|
||||
|
||||
export interface IColorInfo {
|
||||
color: [number, number, number, number | undefined];
|
||||
range: IRange;
|
||||
}
|
||||
|
||||
export abstract class ExtHostLanguageFeaturesShape {
|
||||
$provideDocumentSymbols(handle: number, resource: URI): TPromise<modes.SymbolInformation[]> { throw ni(); }
|
||||
$provideCodeLenses(handle: number, resource: URI): TPromise<modes.ICodeLensSymbol[]> { throw ni(); }
|
||||
@@ -475,7 +480,7 @@ export abstract class ExtHostLanguageFeaturesShape {
|
||||
$resolveCompletionItem(handle: number, resource: URI, position: IPosition, suggestion: modes.ISuggestion): TPromise<modes.ISuggestion> { throw ni(); }
|
||||
$provideSignatureHelp(handle: number, resource: URI, position: IPosition): TPromise<modes.SignatureHelp> { throw ni(); }
|
||||
$provideDocumentLinks(handle: number, resource: URI): TPromise<modes.ILink[]> { throw ni(); }
|
||||
$provideDocumentColors(handle: number, resource: URI): TPromise<modes.IColorInfo[]> { throw ni(); }
|
||||
$provideDocumentColors(handle: number, resource: URI): TPromise<IColorInfo[]> { throw ni(); }
|
||||
$resolveDocumentLink(handle: number, link: modes.ILink): TPromise<modes.ILink> { throw ni(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHos
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { IWorkspaceSymbolProvider } from 'vs/workbench/parts/search/common/search';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier } from './extHost.protocol';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IColorInfo } from './extHost.protocol';
|
||||
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
@@ -681,7 +681,7 @@ class ColorProviderAdapter {
|
||||
this._provider = provider;
|
||||
}
|
||||
|
||||
provideColors(resource: URI): TPromise<modes.IColorInfo[]> {
|
||||
provideColors(resource: URI): TPromise<IColorInfo[]> {
|
||||
const doc = this._documents.getDocumentData(resource).document;
|
||||
|
||||
return asWinJsPromise(token => this._provider.provideDocumentColors(doc, token)).then(colors => {
|
||||
@@ -988,7 +988,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideDocumentColors(handle: number, resource: URI): TPromise<modes.IColorInfo[]> {
|
||||
$provideDocumentColors(handle: number, resource: URI): TPromise<IColorInfo[]> {
|
||||
return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColors(resource));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { ISelection } from 'vs/editor/common/core/selection';
|
||||
import { RGBA, Color } from "vs/base/common/color";
|
||||
import { IColorInfo } from "vs/workbench/api/node/extHost.protocol";
|
||||
|
||||
export interface PositionLike {
|
||||
line: number;
|
||||
@@ -371,10 +371,10 @@ export namespace DocumentLink {
|
||||
}
|
||||
|
||||
export namespace DocumentColor {
|
||||
export function from(colorInfo: vscode.ColorInfo): modes.IColorInfo {
|
||||
export function from(colorInfo: vscode.ColorInfo): IColorInfo {
|
||||
return {
|
||||
range: fromRange(colorInfo.range),
|
||||
color: Color.fromRGBA(new RGBA(colorInfo.color.r, colorInfo.color.g, colorInfo.color.b, colorInfo.color.a * 255))
|
||||
color: [colorInfo.color.red, colorInfo.color.green, colorInfo.color.blue, colorInfo.color.alpha],
|
||||
range: fromRange(colorInfo.range)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,18 +1015,18 @@ export class DocumentLink {
|
||||
}
|
||||
}
|
||||
|
||||
export enum ColorType {
|
||||
RGBA = 0,
|
||||
HSL = 1,
|
||||
Hex = 2,
|
||||
Custom = 3
|
||||
}
|
||||
|
||||
export class Color {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
a: number;
|
||||
red: number;
|
||||
green: number;
|
||||
blue: number;
|
||||
alpha: number;
|
||||
|
||||
constructor(red: number, green: number, blue: number, alpha?: number) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
export class ColorInfo {
|
||||
@@ -1034,9 +1034,7 @@ export class ColorInfo {
|
||||
|
||||
color: Color;
|
||||
|
||||
type: ColorType;
|
||||
|
||||
constructor(range: Range, color: Color) {
|
||||
constructor(color: Color, range: Range) {
|
||||
if (color && !(color instanceof Color)) {
|
||||
throw illegalArgument('target');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user