Remove onDidChagne events. Deprecate [lan].colorDecorators.enable and

use editor.colorDecorators for all.
This commit is contained in:
rebornix
2017-08-24 15:38:39 -07:00
committed by Peng Lyu
parent ef690ded3e
commit 879373d9e1
11 changed files with 110 additions and 150 deletions

View File

@@ -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());

View File

@@ -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