Skip to content

Commit db1f631

Browse files
authored
Fix colorization issue where only 1 of multiple get colorized (#3777)
1 parent 426c082 commit db1f631

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Extension/src/LanguageServer/colorization.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,6 @@ export class ColorizationState {
443443
}
444444

445445
private refreshInner(e: vscode.TextEditor): void {
446-
447-
// The only way to un-apply decorators is to dispose them.
448-
// If we dispose old decorators before applying new decorators, we see a flicker on Mac,
449-
// likely due to a race with UI updates. Here we set aside the existing decorators to be
450-
// disposed of after the new decorators have been applied, so there is not a gap
451-
// in which decorators are not applied.
452-
let oldInactiveDecoration: vscode.TextEditorDecorationType = this.inactiveDecoration;
453-
let oldDecorations: vscode.TextEditorDecorationType[] = this.decorations;
454-
this.inactiveDecoration = null;
455-
this.decorations = new Array<vscode.TextEditorDecorationType>(TokenKind.Count);
456-
457-
this.createColorizationDecorations(e.document.languageId === "cpp");
458-
459446
let settings: CppSettings = new CppSettings(this.uri);
460447
if (settings.enhancedColorization === "Enabled" && settings.intelliSenseEngine === "Default") {
461448
for (let i: number = 0; i < TokenKind.Count; i++) {
@@ -482,18 +469,6 @@ export class ColorizationState {
482469
if (settings.dimInactiveRegions && this.inactiveDecoration && this.inactiveRanges) {
483470
e.setDecorations(this.inactiveDecoration, this.inactiveRanges);
484471
}
485-
486-
// Dispose of the old decorators only after the new ones have been applied.
487-
if (oldInactiveDecoration) {
488-
oldInactiveDecoration.dispose();
489-
}
490-
if (oldDecorations) {
491-
for (let i: number = 0; i < TokenKind.Count; i++) {
492-
if (oldDecorations[i]) {
493-
oldDecorations[i].dispose();
494-
}
495-
}
496-
}
497472
}
498473

499474
public refresh(e: vscode.TextEditor): void {
@@ -672,11 +647,36 @@ export class ColorizationState {
672647
}
673648
}
674649
let f: () => void = async () => {
650+
// The only way to un-apply decorators is to dispose them.
651+
// If we dispose old decorators before applying new decorators, we see a flicker on Mac,
652+
// likely due to a race with UI updates. Here we set aside the existing decorators to be
653+
// disposed of after the new decorators have been applied, so there is not a gap
654+
// in which decorators are not applied.
655+
let oldInactiveDecoration: vscode.TextEditorDecorationType = this.inactiveDecoration;
656+
let oldDecorations: vscode.TextEditorDecorationType[] = this.decorations;
657+
this.inactiveDecoration = null;
658+
this.decorations = new Array<vscode.TextEditorDecorationType>(TokenKind.Count);
659+
660+
let isCpp: boolean = util.isEditorFileCpp(uri);
661+
this.createColorizationDecorations(isCpp);
662+
675663
// Apply the decorations to all *visible* text editors
676664
let editors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => e.document.uri.toString() === uri);
677665
for (let e of editors) {
678666
this.refreshInner(e);
679667
}
668+
669+
// Dispose of the old decorators only after the new ones have been applied.
670+
if (oldInactiveDecoration) {
671+
oldInactiveDecoration.dispose();
672+
}
673+
if (oldDecorations) {
674+
for (let i: number = 0; i < TokenKind.Count; i++) {
675+
if (oldDecorations[i]) {
676+
oldDecorations[i].dispose();
677+
}
678+
}
679+
}
680680
};
681681
this.colorizationSettings.syncWithLoadingSettings(f);
682682
}

0 commit comments

Comments
 (0)