mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
Remove onDidChagne events. Deprecate [lan].colorDecorators.enable and
use editor.colorDecorators for all.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as parse from 'parse-color';
|
||||
import { workspace, Range, TextDocument, DocumentColorProvider, Color, ColorRange, Event, EventEmitter } from 'vscode';
|
||||
import { Range, TextDocument, DocumentColorProvider, Color, ColorRange } from 'vscode';
|
||||
|
||||
const CSSColorFormats = {
|
||||
Hex: '#{red:X}{green:X}{blue:X}',
|
||||
@@ -20,33 +20,7 @@ const CSSColorFormats = {
|
||||
};
|
||||
|
||||
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());
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
import { languages, window, commands, workspace, ExtensionContext } from 'vscode';
|
||||
import { languages, window, commands, ExtensionContext } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, Range, TextEdit } from 'vscode-languageclient';
|
||||
import { ConfigurationFeature } from 'vscode-languageclient/lib/proposed';
|
||||
import { ColorProvider } from './colorDecorators';
|
||||
@@ -56,11 +56,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(['css', 'scss', 'less'], new ColorProvider(colorRequestor, { css: true, scss: true, less: true }, isDecoratorEnabled)));
|
||||
context.subscriptions.push(languages.registerColorProvider(['css', 'scss', 'less'], new ColorProvider(colorRequestor)));
|
||||
});
|
||||
|
||||
let indentationRules = {
|
||||
|
||||
Reference in New Issue
Block a user