Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions Extension/src/LanguageServer/colorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,6 @@ export class ColorizationState {
}

private refreshInner(e: vscode.TextEditor): void {

// The only way to un-apply decorators is to dispose them.
// If we dispose old decorators before applying new decorators, we see a flicker on Mac,
// likely due to a race with UI updates. Here we set aside the existing decorators to be
// disposed of after the new decorators have been applied, so there is not a gap
// in which decorators are not applied.
let oldInactiveDecoration: vscode.TextEditorDecorationType = this.inactiveDecoration;
let oldDecorations: vscode.TextEditorDecorationType[] = this.decorations;
this.inactiveDecoration = null;
this.decorations = new Array<vscode.TextEditorDecorationType>(TokenKind.Count);

this.createColorizationDecorations(e.document.languageId === "cpp");

let settings: CppSettings = new CppSettings(this.uri);
if (settings.enhancedColorization === "Enabled" && settings.intelliSenseEngine === "Default") {
for (let i: number = 0; i < TokenKind.Count; i++) {
Expand All @@ -482,18 +469,6 @@ export class ColorizationState {
if (settings.dimInactiveRegions && this.inactiveDecoration && this.inactiveRanges) {
e.setDecorations(this.inactiveDecoration, this.inactiveRanges);
}

// Dispose of the old decorators only after the new ones have been applied.
if (oldInactiveDecoration) {
oldInactiveDecoration.dispose();
}
if (oldDecorations) {
for (let i: number = 0; i < TokenKind.Count; i++) {
if (oldDecorations[i]) {
oldDecorations[i].dispose();
}
}
}
}

public refresh(e: vscode.TextEditor): void {
Expand Down Expand Up @@ -672,11 +647,36 @@ export class ColorizationState {
}
}
let f: () => void = async () => {
// The only way to un-apply decorators is to dispose them.
// If we dispose old decorators before applying new decorators, we see a flicker on Mac,
// likely due to a race with UI updates. Here we set aside the existing decorators to be
// disposed of after the new decorators have been applied, so there is not a gap
// in which decorators are not applied.
let oldInactiveDecoration: vscode.TextEditorDecorationType = this.inactiveDecoration;
let oldDecorations: vscode.TextEditorDecorationType[] = this.decorations;
this.inactiveDecoration = null;
this.decorations = new Array<vscode.TextEditorDecorationType>(TokenKind.Count);

let isCpp: boolean = util.isEditorFileCpp(uri);
this.createColorizationDecorations(isCpp);

// Apply the decorations to all *visible* text editors
let editors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => e.document.uri.toString() === uri);
for (let e of editors) {
this.refreshInner(e);
}

// Dispose of the old decorators only after the new ones have been applied.
if (oldInactiveDecoration) {
oldInactiveDecoration.dispose();
}
if (oldDecorations) {
for (let i: number = 0; i < TokenKind.Count; i++) {
if (oldDecorations[i]) {
oldDecorations[i].dispose();
}
}
}
};
this.colorizationSettings.syncWithLoadingSettings(f);
}
Expand Down