mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
Remove onDidChagne events. Deprecate [lan].colorDecorators.enable and
use editor.colorDecorators for all.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { workspace, Range, TextDocument, DocumentColorProvider, Color, ColorRange, Event, EventEmitter } from 'vscode';
|
||||
import { Range, TextDocument, DocumentColorProvider, Color, ColorRange } from 'vscode';
|
||||
|
||||
const ColorFormat_HEX = {
|
||||
opaque: '"#{red:X}{green:X}{blue:X}"',
|
||||
@@ -12,34 +12,7 @@ const ColorFormat_HEX = {
|
||||
};
|
||||
|
||||
export class ColorProvider implements DocumentColorProvider {
|
||||
private onDidChangeColorsEmitter = new EventEmitter<void>();
|
||||
private decoratorEnablement = {};
|
||||
|
||||
constructor(private decoratorProvider: (uri: string) => Thenable<Range[]>, private supportedLanguages: { [id: string]: boolean }, isDecoratorEnabled: (languageId: string) => boolean) {
|
||||
for (let languageId in supportedLanguages) {
|
||||
this.decoratorEnablement[languageId] = isDecoratorEnabled(languageId);
|
||||
}
|
||||
|
||||
workspace.onDidChangeConfiguration(_ => {
|
||||
let hasChanges = false;
|
||||
for (let languageId in supportedLanguages) {
|
||||
let prev = this.decoratorEnablement[languageId];
|
||||
let curr = isDecoratorEnabled(languageId);
|
||||
if (prev !== curr) {
|
||||
this.decoratorEnablement[languageId] = curr;
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
if (hasChanges) {
|
||||
this.onDidChangeColorsEmitter.fire();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public get onDidChangeColors(): Event<void> {
|
||||
return this.onDidChangeColorsEmitter.event;
|
||||
}
|
||||
constructor(private decoratorProvider: (uri: string) => Thenable<Range[]>) { }
|
||||
|
||||
async provideDocumentColors(document: TextDocument): Promise<ColorRange[]> {
|
||||
const ranges = await this.decoratorProvider(document.uri.toString());
|
||||
|
||||
@@ -119,11 +119,8 @@ export function activate(context: ExtensionContext) {
|
||||
let colorRequestor = (uri: string) => {
|
||||
return client.sendRequest(ColorSymbolRequest.type, uri).then(ranges => ranges.map(client.protocol2CodeConverter.asRange));
|
||||
};
|
||||
let isDecoratorEnabled = (languageId: string) => {
|
||||
return workspace.getConfiguration().get<boolean>(languageId + '.colorDecorators.enable');
|
||||
};
|
||||
|
||||
context.subscriptions.push(languages.registerColorProvider('json', new ColorProvider(colorRequestor, { json: true }, isDecoratorEnabled)));
|
||||
context.subscriptions.push(languages.registerColorProvider('json', new ColorProvider(colorRequestor)));
|
||||
});
|
||||
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
|
||||
Reference in New Issue
Block a user