mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Fixes #131027 by introducing editor.bracketPairColorization.useIndependentColorPoolPerBracketType
This commit is contained in:
@@ -3550,6 +3550,11 @@ export interface IBracketPairColorizationOptions {
|
||||
* Enable or disable bracket pair colorization.
|
||||
*/
|
||||
enabled?: boolean;
|
||||
|
||||
/**
|
||||
* Use independent color pool per bracket type.
|
||||
*/
|
||||
useIndependentColorPoolPerBracketType?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3563,7 +3568,8 @@ export type InternalBracketPairColorizationOptions = Readonly<Required<IBracketP
|
||||
class BracketPairColorization extends BaseEditorOption<EditorOption.bracketPairColorization, IBracketPairColorizationOptions, InternalBracketPairColorizationOptions> {
|
||||
constructor() {
|
||||
const defaults: InternalBracketPairColorizationOptions = {
|
||||
enabled: EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions.enabled
|
||||
enabled: EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions.enabled,
|
||||
useIndependentColorPoolPerBracketType: EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions.useIndependentColorPoolPerBracketType,
|
||||
};
|
||||
|
||||
super(
|
||||
@@ -3573,7 +3579,12 @@ class BracketPairColorization extends BaseEditorOption<EditorOption.bracketPairC
|
||||
type: 'boolean',
|
||||
default: defaults.enabled,
|
||||
description: nls.localize('bracketPairColorization.enabled', "Controls whether bracket pair colorization is enabled or not. Use 'workbench.colorCustomizations' to override the bracket highlight colors.")
|
||||
}
|
||||
},
|
||||
'editor.bracketPairColorization.useIndependentColorPoolPerBracketType': {
|
||||
type: 'boolean',
|
||||
default: defaults.useIndependentColorPoolPerBracketType,
|
||||
description: nls.localize('bracketPairColorization.useIndependentColorPoolPerBracketType', "Controls whether each bracket type has its own independent color pool.")
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -3584,7 +3595,8 @@ class BracketPairColorization extends BaseEditorOption<EditorOption.bracketPairC
|
||||
}
|
||||
const input = _input as IBracketPairColorizationOptions;
|
||||
return {
|
||||
enabled: boolean(input.enabled, this.defaultValue.enabled)
|
||||
enabled: boolean(input.enabled, this.defaultValue.enabled),
|
||||
useIndependentColorPoolPerBracketType: boolean(input.useIndependentColorPoolPerBracketType, this.defaultValue.useIndependentColorPoolPerBracketType),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ export const EDITOR_MODEL_DEFAULTS = {
|
||||
detectIndentation: true,
|
||||
trimAutoWhitespace: true,
|
||||
largeFileOptimizations: true,
|
||||
bracketPairColorizationOptions: { enabled: false }
|
||||
bracketPairColorizationOptions: {
|
||||
enabled: false,
|
||||
useIndependentColorPoolPerBracketType: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -488,6 +488,7 @@ export interface ITextModelCreationOptions {
|
||||
|
||||
export interface BracketPairColorizationOptions {
|
||||
enabled: boolean;
|
||||
useIndependentColorPoolPerBracketType: boolean;
|
||||
}
|
||||
|
||||
export interface ITextModelUpdateOptions {
|
||||
|
||||
@@ -627,9 +627,10 @@ export class BracketAstNode extends ImmutableLeafAstNode {
|
||||
public static create(
|
||||
length: Length,
|
||||
languageId: string,
|
||||
text: string,
|
||||
bracketIds: SmallImmutableSet<OpeningBracketId>
|
||||
): BracketAstNode {
|
||||
const node = new BracketAstNode(length, languageId, bracketIds);
|
||||
const node = new BracketAstNode(length, languageId, text, bracketIds);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -644,6 +645,7 @@ export class BracketAstNode extends ImmutableLeafAstNode {
|
||||
private constructor(
|
||||
length: Length,
|
||||
public readonly languageId: string,
|
||||
public readonly text: string,
|
||||
/**
|
||||
* In case of a opening bracket, this is the id of the opening bracket.
|
||||
* In case of a closing bracket, this contains the ids of all opening brackets it can close.
|
||||
|
||||
+24
-10
@@ -128,7 +128,7 @@ export class BracketPairsTree extends Disposable {
|
||||
const endOffset = toLength(range.endLineNumber - 1, range.endColumn - 1);
|
||||
const result = new Array<BracketInfo>();
|
||||
const node = this.initialAstWithoutTokens || this.astWithTokens!;
|
||||
collectBrackets(node, lengthZero, node.length, startOffset, endOffset, result);
|
||||
collectBrackets(node, lengthZero, node.length, startOffset, endOffset, result, 0, new Map());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -146,25 +146,35 @@ export class BracketPairsTree extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
function collectBrackets(node: AstNode, nodeOffsetStart: Length, nodeOffsetEnd: Length, startOffset: Length, endOffset: Length, result: BracketInfo[], level: number = 0): void {
|
||||
function collectBrackets(node: AstNode, nodeOffsetStart: Length, nodeOffsetEnd: Length, startOffset: Length, endOffset: Length, result: BracketInfo[], level: number = 0, levelPerBracketType?: Map<string, number>): void {
|
||||
if (node.kind === AstNodeKind.List) {
|
||||
for (const child of node.children) {
|
||||
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
||||
if (lengthLessThanEqual(nodeOffsetStart, endOffset) && lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
||||
collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, result, level);
|
||||
collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, result, level, levelPerBracketType);
|
||||
}
|
||||
nodeOffsetStart = nodeOffsetEnd;
|
||||
}
|
||||
} else if (node.kind === AstNodeKind.Pair) {
|
||||
// Don't use node.children here to improve performance
|
||||
level++;
|
||||
|
||||
let levelPerBracket = 0;
|
||||
if (levelPerBracketType) {
|
||||
let existing = levelPerBracketType.get(node.openingBracket.text);
|
||||
if (existing === undefined) {
|
||||
existing = 0;
|
||||
}
|
||||
levelPerBracket = existing;
|
||||
existing++;
|
||||
levelPerBracketType.set(node.openingBracket.text, existing);
|
||||
}
|
||||
|
||||
// Don't use node.children here to improve performance
|
||||
{
|
||||
const child = node.openingBracket;
|
||||
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
||||
if (lengthLessThanEqual(nodeOffsetStart, endOffset) && lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
||||
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
||||
result.push(new BracketInfo(range, level - 1, !node.closingBracket));
|
||||
result.push(new BracketInfo(range, level, levelPerBracket, !node.closingBracket));
|
||||
}
|
||||
nodeOffsetStart = nodeOffsetEnd;
|
||||
}
|
||||
@@ -173,7 +183,7 @@ function collectBrackets(node: AstNode, nodeOffsetStart: Length, nodeOffsetEnd:
|
||||
const child = node.child;
|
||||
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
||||
if (lengthLessThanEqual(nodeOffsetStart, endOffset) && lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
||||
collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, result, level);
|
||||
collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, result, level + 1, levelPerBracketType);
|
||||
}
|
||||
nodeOffsetStart = nodeOffsetEnd;
|
||||
}
|
||||
@@ -182,16 +192,20 @@ function collectBrackets(node: AstNode, nodeOffsetStart: Length, nodeOffsetEnd:
|
||||
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
||||
if (lengthLessThanEqual(nodeOffsetStart, endOffset) && lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
||||
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
||||
result.push(new BracketInfo(range, level - 1, false));
|
||||
result.push(new BracketInfo(range, level, levelPerBracket, false));
|
||||
}
|
||||
nodeOffsetStart = nodeOffsetEnd;
|
||||
}
|
||||
|
||||
if (levelPerBracketType) {
|
||||
levelPerBracketType.set(node.openingBracket.text, levelPerBracket);
|
||||
}
|
||||
} else if (node.kind === AstNodeKind.UnexpectedClosingBracket) {
|
||||
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
||||
result.push(new BracketInfo(range, level - 1, true));
|
||||
result.push(new BracketInfo(range, level - 1, 0, true));
|
||||
} else if (node.kind === AstNodeKind.Bracket) {
|
||||
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
||||
result.push(new BracketInfo(range, level - 1, false));
|
||||
result.push(new BracketInfo(range, level - 1, 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export class BracketTokens {
|
||||
TokenKind.ClosingBracket,
|
||||
info.first,
|
||||
info.openingBrackets,
|
||||
BracketAstNode.create(length, configuration.languageId, info.openingBrackets)
|
||||
BracketAstNode.create(length, configuration.languageId, closingText, info.openingBrackets)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class BracketTokens {
|
||||
TokenKind.OpeningBracket,
|
||||
openingTextId,
|
||||
bracketIds,
|
||||
BracketAstNode.create(length, configuration.languageId, bracketIds)
|
||||
BracketAstNode.create(length, configuration.languageId, openingText, bracketIds)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -55,9 +55,15 @@ export class ColorizedBracketPairsDecorationProvider extends Disposable implemen
|
||||
for (const bracket of bracketsInRange) {
|
||||
result.push({
|
||||
id: `bracket${bracket.range.toString()}-${bracket.nestingLevel}`,
|
||||
options: { description: 'BracketPairColorization', inlineClassName: this.colorProvider.getInlineClassName(bracket) },
|
||||
options: {
|
||||
description: 'BracketPairColorization',
|
||||
inlineClassName: this.colorProvider.getInlineClassName(
|
||||
bracket,
|
||||
this.colorizationOptions.useIndependentColorPoolPerBracketType
|
||||
),
|
||||
},
|
||||
ownerId: 0,
|
||||
range: bracket.range
|
||||
range: bracket.range,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
@@ -81,11 +87,11 @@ export class ColorizedBracketPairsDecorationProvider extends Disposable implemen
|
||||
class ColorProvider {
|
||||
public readonly unexpectedClosingBracketClassName = 'unexpected-closing-bracket';
|
||||
|
||||
getInlineClassName(bracket: BracketInfo): string {
|
||||
getInlineClassName(bracket: BracketInfo, useIndependentColorPoolPerBracketType: boolean): string {
|
||||
if (bracket.isInvalid) {
|
||||
return this.unexpectedClosingBracketClassName;
|
||||
}
|
||||
return this.getInlineClassNameOfLevel(bracket.nestingLevel);
|
||||
return this.getInlineClassNameOfLevel(useIndependentColorPoolPerBracketType ? bracket.nestingLevelOfEqualBracketType : bracket.nestingLevel);
|
||||
}
|
||||
|
||||
getInlineClassNameOfLevel(level: number): string {
|
||||
|
||||
@@ -237,7 +237,8 @@ export class ModelService extends Disposable implements IModelService {
|
||||
let bracketPairColorizationOptions = EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions;
|
||||
if (config.editor?.bracketPairColorization && typeof config.editor.bracketPairColorization === 'object') {
|
||||
bracketPairColorizationOptions = {
|
||||
enabled: !!config.editor.bracketPairColorization.enabled
|
||||
enabled: !!config.editor.bracketPairColorization.enabled,
|
||||
useIndependentColorPoolPerBracketType: !!config.editor.bracketPairColorization.useIndependentColorPoolPerBracketType
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ export class BracketInfo {
|
||||
public readonly range: Range,
|
||||
/** 0-based level */
|
||||
public readonly nestingLevel: number,
|
||||
public readonly nestingLevelOfEqualBracketType: number,
|
||||
public readonly isInvalid: boolean,
|
||||
) { }
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -1686,6 +1686,7 @@ declare namespace monaco.editor {
|
||||
|
||||
export interface BracketPairColorizationOptions {
|
||||
enabled: boolean;
|
||||
useIndependentColorPoolPerBracketType: boolean;
|
||||
}
|
||||
|
||||
export interface ITextModelUpdateOptions {
|
||||
@@ -3974,6 +3975,10 @@ declare namespace monaco.editor {
|
||||
* Enable or disable bracket pair colorization.
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Use independent color pool per bracket type.
|
||||
*/
|
||||
useIndependentColorPoolPerBracketType?: boolean;
|
||||
}
|
||||
|
||||
export interface IGuidesOptions {
|
||||
|
||||
Reference in New Issue
Block a user