Path: blob/main/src/vs/editor/common/textModelBracketPairs.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CallbackIterable } from '../../base/common/arrays.js';6import { Event } from '../../base/common/event.js';7import { IPosition } from './core/position.js';8import { IRange, Range } from './core/range.js';9import { ClosingBracketKind, OpeningBracketKind } from './languages/supports/languageBracketsConfiguration.js';10import { PairAstNode } from './model/bracketPairsTextModelPart/bracketPairsTree/ast.js';1112export interface IBracketPairsTextModelPart {13/**14* Is fired when bracket pairs change, either due to a text or a settings change.15*/16onDidChange: Event<void>;1718/**19* Gets all bracket pairs that intersect the given position.20* The result is sorted by the start position.21*/22getBracketPairsInRange(range: IRange): CallbackIterable<BracketPairInfo>;2324/**25* Gets all bracket pairs that intersect the given position.26* The result is sorted by the start position.27*/28getBracketPairsInRangeWithMinIndentation(range: IRange): CallbackIterable<BracketPairWithMinIndentationInfo>;2930getBracketsInRange(range: IRange, onlyColorizedBrackets?: boolean): CallbackIterable<BracketInfo>;3132/**33* Find the matching bracket of `request` up, counting brackets.34* @param request The bracket we're searching for35* @param position The position at which to start the search.36* @return The range of the matching bracket, or null if the bracket match was not found.37*/38findMatchingBracketUp(bracket: string, position: IPosition, maxDuration?: number): Range | null;3940/**41* Find the first bracket in the model before `position`.42* @param position The position at which to start the search.43* @return The info for the first bracket before `position`, or null if there are no more brackets before `positions`.44*/45findPrevBracket(position: IPosition): IFoundBracket | null;4647/**48* Find the first bracket in the model after `position`.49* @param position The position at which to start the search.50* @return The info for the first bracket after `position`, or null if there are no more brackets after `positions`.51*/52findNextBracket(position: IPosition): IFoundBracket | null;5354/**55* Find the enclosing brackets that contain `position`.56* @param position The position at which to start the search.57*/58findEnclosingBrackets(position: IPosition, maxDuration?: number): [Range, Range] | null;5960/**61* Given a `position`, if the position is on top or near a bracket,62* find the matching bracket of that bracket and return the ranges of both brackets.63* @param position The position at which to look for a bracket.64*/65matchBracket(position: IPosition, maxDuration?: number): [Range, Range] | null;66}6768export interface IFoundBracket {69range: Range;70bracketInfo: OpeningBracketKind | ClosingBracketKind;71}7273export class BracketInfo {74constructor(75public readonly range: Range,76/** 0-based level */77public readonly nestingLevel: number,78public readonly nestingLevelOfEqualBracketType: number,79public readonly isInvalid: boolean,80) { }81}8283export class BracketPairInfo {84constructor(85public readonly range: Range,86public readonly openingBracketRange: Range,87public readonly closingBracketRange: Range | undefined,88/** 0-based */89public readonly nestingLevel: number,90public readonly nestingLevelOfEqualBracketType: number,91private readonly bracketPairNode: PairAstNode,9293) {94}9596public get openingBracketInfo(): OpeningBracketKind {97return this.bracketPairNode.openingBracket.bracketInfo as OpeningBracketKind;98}99100public get closingBracketInfo(): ClosingBracketKind | undefined {101return this.bracketPairNode.closingBracket?.bracketInfo as ClosingBracketKind | undefined;102}103}104105export class BracketPairWithMinIndentationInfo extends BracketPairInfo {106constructor(107range: Range,108openingBracketRange: Range,109closingBracketRange: Range | undefined,110/**111* 0-based112*/113nestingLevel: number,114nestingLevelOfEqualBracketType: number,115bracketPairNode: PairAstNode,116/**117* -1 if not requested, otherwise the size of the minimum indentation in the bracket pair in terms of visible columns.118*/119public readonly minVisibleColumnIndentation: number,120) {121super(range, openingBracketRange, closingBracketRange, nestingLevel, nestingLevelOfEqualBracketType, bracketPairNode);122}123}124125126