1
>
/*---------------------------------------------------------------------------------------------
jsonFormatter.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 { createScanner, ScanError, SyntaxKind } from './json.js';
7
>
8
>
export interface FormattingOptions {
9
>
/**
10
>
* If indentation is based on spaces (`insertSpaces` = true), then what is the number of spaces that make an indent?
11
>
*/
12
>
tabSize?: number;
13
>
/**
14
>
* Is indentation based on spaces?
15
>
*/
16
>
insertSpaces?: boolean;
17
>
/**
18
>
* The default 'end of line' character. If not set, '\n' is used as default.
19
>
*/
20
>
eol?: string;
21
>
}
22
>
23
>
/**
24
>
* Represents a text modification
25
>
*/
26
>
export interface Edit {
27
>
/**
28
>
* The start offset of the modification.
29
>
*/
30
>
offset: number;
31
>
/**
32
>
* The length of the modification. Must not be negative. Empty length represents an *insert*.
33
>
*/
34
>
length: number;
35
>
/**
36
>
* The new content. Empty content represents a *remove*.
37
>
*/
38
>
content: string;
39
>
}
40
>
41
>
/**
42
>
* A text range in the document
43
>
*/
44
>
export interface Range {
45
>
/**
46
>
* The start offset of the range.
47
>
*/
48
>
offset: number;
49
>
/**
50
>
* The length of the range. Must not be negative.
51
>
*/
52
>
length: number;
53
>
}
54
>
55
>
56
>
export function format(documentText: string, range: Range | undefined, options: FormattingOptions): Edit[] {
57
let initialIndentLevel: number;
58
let formatText: string;