1
>
/*---------------------------------------------------------------------------------------------
findSectionHeaders.ts
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 { IRange } from '../core/range.js';
7
>
import { FoldingRules } from '../languages/languageConfiguration.js';
8
>
import { isMultilineRegexSource } from '../model/textModelSearch.js';
9
>
import { regExpLeadsToEndlessLoop } from '../../../base/common/strings.js';
10
>
11
>
export interface ISectionHeaderFinderTarget {
12
>
getLineCount(): number;
13
>
getLineContent(lineNumber: number): string;
14
>
}
15
>
16
>
export interface FindSectionHeaderOptions {
17
>
foldingRules?: FoldingRules;
18
>
findRegionSectionHeaders: boolean;
19
>
findMarkSectionHeaders: boolean;
20
>
markSectionHeaderRegex: string;
21
>
}
22
>
23
>
export interface SectionHeader {
24
>
/**
25
>
* The location of the header text in the text model.
26
>
*/
27
>
range: IRange;
28
>
/**
29
>
* The section header text.
30
>
*/
31
>
text: string;
32
>
/**
33
>
* Whether the section header includes a separator line.
34
>
*/
35
>
hasSeparatorLine: boolean;
36
>
/**
37
>
* This section should be omitted before rendering if it's not in a comment.
38
>
*/
39
>
shouldBeInComments: boolean;
40
>
}
41
>
42
>
const trimDashesRegex = /^-+|-+$/g;
43
>
44
>
const CHUNK_SIZE = 100;
45
>
const MAX_SECTION_LINES = 5;
46
>
47
>
/**
48
>
* Find section headers in the model.
49
>
*
50
>
* @param model the text model to search in
51
>
* @param options options to search with
52
>
* @returns an array of section headers
53
>
*/
54
>
export function findSectionHeaders(model: ISectionHeaderFinderTarget, options: FindSectionHeaderOptions): SectionHeader[] {
55
let headers: SectionHeader[] = [];
56
if (options.findRegionSectionHeaders && options.foldingRules?.markers) {