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