Repository: microsoft/vscode (TypeScript)
Date: 2022-10-21 09:05:06+00:00
Task type: Bug Fix

Issue:
Error bracket highlighting no longer works
```json
{
	{ "test": "blah"
}
```

Vscode `1.70.1`:
![image](https://user-images.githubusercontent.com/33529441/194241945-d5809fc7-c94c-41fb-ac4e-0a07d2eb812d.png)

Vscode `1.71.2`:
![image](https://user-images.githubusercontent.com/33529441/194246607-7e5ba434-7e6c-4ecb-8b76-cce3f8d1dd2e.png)

Notice the red opening error bracket is now shown as a normal non-error bracket (yellow)
closing brackets still work fine
affects all languages (not just json)


Issue discussion:

Solution patch:
diff --git a/src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts b/src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts
--- a/src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts
+++ b/src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts
@@ -221,7 +221,8 @@ function collectBrackets(
 	push: (item: BracketInfo) => boolean,
 	level: number,
 	nestingLevelOfEqualBracketType: number,
-	levelPerBracketType: Map<string, number>
+	levelPerBracketType: Map<string, number>,
+	parentPairIsIncomplete: boolean = false
 ): boolean {
 	if (level > 200) {
 		return true;
@@ -289,7 +290,9 @@ function collectBrackets(
 							continue whileLoop;
 						}
 
-						const shouldContinue = collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, push, level + 1, levelPerBracket + 1, levelPerBracketType);
+						const shouldContinue = collectBrackets(
+							child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, push, level + 1, levelPerBracket + 1, levelPerBracketType, !node.closingBracket
+						);
 						if (!shouldContinue) {
 							return false;
 						}
@@ -307,7 +310,7 @@ function collectBrackets(
 			}
 			case AstNodeKind.Bracket: {
 				const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
-				return push(new BracketInfo(range, level - 1, nestingLevelOfEqualBracketType - 1, false));
+				return push(new BracketInfo(range, level - 1, nestingLevelOfEqualBracketType - 1, parentPairIsIncomplete));
 			}
 			case AstNodeKind.Text:
 				return true;


Test patch:
diff --git a/src/vs/editor/test/common/model/bracketPairColorizer/getBracketPairsInRange.test.ts b/src/vs/editor/test/common/model/bracketPairColorizer/getBracketPairsInRange.test.ts
--- a/src/vs/editor/test/common/model/bracketPairColorizer/getBracketPairsInRange.test.ts
+++ b/src/vs/editor/test/common/model/bracketPairColorizer/getBracketPairsInRange.test.ts
@@ -244,6 +244,41 @@ suite('Bracket Pair Colorizer - getBracketPairsInRange', () => {
 			);
 		});
 	});
+
+	test('Test Error Brackets', () => {
+		disposeOnReturn(store => {
+			const doc = new AnnotatedDocument(`¹ { () ] ² `);
+			const model = createTextModelWithColorizedBracketPairs(store, doc.text);
+			assert.deepStrictEqual(
+				model.bracketPairs
+					.getBracketsInRange(doc.range(1, 2))
+					.map(b => ({ level: b.nestingLevel, range: b.range.toString(), isInvalid: b.isInvalid }))
+					.toArray(),
+				[
+					{
+						level: 0,
+						isInvalid: true,
+						range: "[1,2 -> 1,3]",
+					},
+					{
+						level: 1,
+						isInvalid: false,
+						range: "[1,4 -> 1,5]",
+					},
+					{
+						level: 1,
+						isInvalid: false,
+						range: "[1,5 -> 1,6]",
+					},
+					{
+						level: 0,
+						isInvalid: true,
+						range: "[1,7 -> 1,8]"
+					}
+				]
+			);
+		});
+	});
 });
 
 function bracketPairToJSON(pair: BracketPairInfo): unknown {