mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
stale color box when switching languages. Fixes #21108
This commit is contained in:
parent
d9806bcd9d
commit
3c0ac99311
|
@ -23,7 +23,7 @@ let decorationType: DecorationRenderOptions = {
|
|||
}
|
||||
};
|
||||
|
||||
export function activateColorDecorations(decoratorProvider: (uri: string) => Thenable<Range[]>, supportedLanguages: { [id: string]: boolean }): Disposable {
|
||||
export function activateColorDecorations(decoratorProvider: (uri: string) => Thenable<Range[]>, supportedLanguages: { [id: string]: boolean }, isDecoratorEnabled: (languageId: string) => boolean): Disposable {
|
||||
|
||||
let disposables: Disposable[] = [];
|
||||
|
||||
|
@ -45,6 +45,10 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
workspace.onDidChangeTextDocument(event => triggerUpdateDecorations(event.document), null, disposables);
|
||||
|
||||
// track open and close for document languageId changes
|
||||
workspace.onDidCloseTextDocument(event => triggerUpdateDecorations(event, true));
|
||||
workspace.onDidOpenTextDocument(event => triggerUpdateDecorations(event));
|
||||
|
||||
workspace.onDidChangeConfiguration(_ => {
|
||||
let hasChanges = false;
|
||||
for (let languageId in supportedLanguages) {
|
||||
|
@ -62,10 +66,6 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
updateAllVisibleEditors(false);
|
||||
|
||||
function isDecoratorEnabled(languageId: string) {
|
||||
return workspace.getConfiguration().get<boolean>(languageId + '.colorDecorators.enable');
|
||||
}
|
||||
|
||||
function updateAllVisibleEditors(settingsChanges: boolean) {
|
||||
window.visibleTextEditors.forEach(editor => {
|
||||
if (editor.document) {
|
||||
|
@ -76,23 +76,22 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
function triggerUpdateDecorations(document: TextDocument, settingsChanges = false) {
|
||||
let triggerUpdate = supportedLanguages[document.languageId] && (decoratorEnablement[document.languageId] || settingsChanges);
|
||||
let documentUri = document.uri;
|
||||
let documentUriStr = documentUri.toString();
|
||||
let timeout = pendingUpdateRequests[documentUriStr];
|
||||
if (typeof timeout !== 'undefined') {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
if (triggerUpdate) {
|
||||
let documentUriStr = document.uri.toString();
|
||||
let timeout = pendingUpdateRequests[documentUriStr];
|
||||
if (typeof timeout !== 'undefined') {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
pendingUpdateRequests[documentUriStr] = setTimeout(() => {
|
||||
// check if the document is in use by an active editor
|
||||
for (let editor of window.visibleTextEditors) {
|
||||
if (editor.document && documentUriStr === editor.document.uri.toString()) {
|
||||
if (decoratorEnablement[document.languageId]) {
|
||||
if (decoratorEnablement[editor.document.languageId]) {
|
||||
updateDecorationForEditor(documentUriStr, editor.document.version);
|
||||
break;
|
||||
} else {
|
||||
editor.setDecorations(colorsDecorationType, []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete pendingUpdateRequests[documentUriStr];
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import * as path from 'path';
|
||||
|
||||
import { languages, window, commands, ExtensionContext } from 'vscode';
|
||||
import { languages, window, commands, workspace, ExtensionContext } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, Range, TextEdit } from 'vscode-languageclient';
|
||||
import { activateColorDecorations } from './colorDecorators';
|
||||
|
||||
|
@ -54,7 +54,10 @@ export function activate(context: ExtensionContext) {
|
|||
let colorRequestor = (uri: string) => {
|
||||
return client.sendRequest(ColorSymbolRequest.type, uri).then(ranges => ranges.map(client.protocol2CodeConverter.asRange));
|
||||
};
|
||||
disposable = activateColorDecorations(colorRequestor, { css: true, scss: true, less: true });
|
||||
let isDecoratorEnabled = (languageId: string) => {
|
||||
return workspace.getConfiguration().get<boolean>(languageId + '.colorDecorators.enable');
|
||||
};
|
||||
disposable = activateColorDecorations(colorRequestor, { css: true, scss: true, less: true }, isDecoratorEnabled);
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ let decorationType: DecorationRenderOptions = {
|
|||
}
|
||||
};
|
||||
|
||||
export function activateColorDecorations(decoratorProvider: (uri: string) => Thenable<Range[]>, supportedLanguages: { [id: string]: boolean }): Disposable {
|
||||
export function activateColorDecorations(decoratorProvider: (uri: string) => Thenable<Range[]>, supportedLanguages: { [id: string]: boolean }, isDecoratorEnabled: (languageId: string) => boolean): Disposable {
|
||||
|
||||
let disposables: Disposable[] = [];
|
||||
|
||||
|
@ -45,6 +45,10 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
workspace.onDidChangeTextDocument(event => triggerUpdateDecorations(event.document), null, disposables);
|
||||
|
||||
// track open and close for document languageId changes
|
||||
workspace.onDidCloseTextDocument(event => triggerUpdateDecorations(event, true));
|
||||
workspace.onDidOpenTextDocument(event => triggerUpdateDecorations(event));
|
||||
|
||||
workspace.onDidChangeConfiguration(_ => {
|
||||
let hasChanges = false;
|
||||
for (let languageId in supportedLanguages) {
|
||||
|
@ -62,10 +66,6 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
updateAllVisibleEditors(false);
|
||||
|
||||
function isDecoratorEnabled(languageId: string) {
|
||||
return workspace.getConfiguration().get<boolean>(languageId + '.colorDecorators.enable');
|
||||
}
|
||||
|
||||
function updateAllVisibleEditors(settingsChanges: boolean) {
|
||||
window.visibleTextEditors.forEach(editor => {
|
||||
if (editor.document) {
|
||||
|
@ -76,23 +76,22 @@ export function activateColorDecorations(decoratorProvider: (uri: string) => The
|
|||
|
||||
function triggerUpdateDecorations(document: TextDocument, settingsChanges = false) {
|
||||
let triggerUpdate = supportedLanguages[document.languageId] && (decoratorEnablement[document.languageId] || settingsChanges);
|
||||
let documentUri = document.uri;
|
||||
let documentUriStr = documentUri.toString();
|
||||
let timeout = pendingUpdateRequests[documentUriStr];
|
||||
if (typeof timeout !== 'undefined') {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
if (triggerUpdate) {
|
||||
let documentUriStr = document.uri.toString();
|
||||
let timeout = pendingUpdateRequests[documentUriStr];
|
||||
if (typeof timeout !== 'undefined') {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
pendingUpdateRequests[documentUriStr] = setTimeout(() => {
|
||||
// check if the document is in use by an active editor
|
||||
for (let editor of window.visibleTextEditors) {
|
||||
if (editor.document && documentUriStr === editor.document.uri.toString()) {
|
||||
if (decoratorEnablement[document.languageId]) {
|
||||
if (decoratorEnablement[editor.document.languageId]) {
|
||||
updateDecorationForEditor(documentUriStr, editor.document.version);
|
||||
break;
|
||||
} else {
|
||||
editor.setDecorations(colorsDecorationType, []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete pendingUpdateRequests[documentUriStr];
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import * as path from 'path';
|
||||
|
||||
import { languages, ExtensionContext, IndentAction } from 'vscode';
|
||||
import { languages, workspace, ExtensionContext, IndentAction } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Range, RequestType } from 'vscode-languageclient';
|
||||
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
|
||||
import { activateColorDecorations } from './colorDecorators';
|
||||
|
@ -65,7 +65,10 @@ export function activate(context: ExtensionContext) {
|
|||
let colorRequestor = (uri: string) => {
|
||||
return client.sendRequest(ColorSymbolRequest.type, uri).then(ranges => ranges.map(client.protocol2CodeConverter.asRange));
|
||||
};
|
||||
let disposable = activateColorDecorations(colorRequestor, { html: true, handlebars: true, razor: true });
|
||||
let isDecoratorEnabled = (languageId: string) => {
|
||||
return workspace.getConfiguration().get<boolean>('css.colorDecorators.enable');
|
||||
};
|
||||
let disposable = activateColorDecorations(colorRequestor, { html: true, handlebars: true, razor: true }, isDecoratorEnabled);
|
||||
context.subscriptions.push(disposable);
|
||||
client.onTelemetry(e => {
|
||||
if (telemetryReporter) {
|
||||
|
|
Loading…
Reference in a new issue