Skip to content

Commit 0af3069

Browse files
committed
Guard against decorations being set on update but without changes
1 parent 31a53bd commit 0af3069

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,15 @@ class DefaultClient implements Client {
654654
// Recycle the active text decorations when we receive a new set of inactive regions
655655
let valuePair: DecorationRangesPair = this.inactiveRegionsDecorations.get(params.uri);
656656
if (valuePair) {
657-
// Disposing of and resetting the decoration will undo previously applied text decorations
658-
valuePair.decoration.dispose();
659-
valuePair.decoration = decoration;
660-
661-
// As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range for when another editor becomes visible
662-
valuePair.ranges = params.ranges;
657+
// The language server will send notifications regardless of whether the ranges have changed. Unfortunately we must check for changes ourselves
658+
if (this.isRangesEqual(valuePair.ranges, params.ranges)) {
659+
// Disposing of and resetting the decoration will undo previously applied text decorations
660+
valuePair.decoration.dispose();
661+
valuePair.decoration = decoration;
662+
663+
// As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range for when another editor becomes visible
664+
valuePair.ranges = params.ranges;
665+
}
663666
} else { // The entry does not exist. Make a new one
664667
let toInsert: DecorationRangesPair = {
665668
decoration: decoration,
@@ -675,6 +678,21 @@ class DefaultClient implements Client {
675678
}
676679
}
677680

681+
// Helper method to compare two ranges for equality
682+
private isRangesEqual(r1: vscode.Range[], r2: vscode.Range[]): boolean {
683+
if (r1.length !== r2.length) {
684+
return false;
685+
}
686+
687+
for (let e1 of r1) {
688+
for (let e2 of r2) {
689+
if (e1 !== e2) {
690+
return false;
691+
}
692+
}
693+
}
694+
}
695+
678696
/*********************************************
679697
* requests to the language server
680698
*********************************************/

0 commit comments

Comments
 (0)