-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.ts
135 lines (125 loc) · 3.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
export type ParserOptions = Record<string, unknown>;
export type ParserName = string;
export interface Parser {
/** Name of parser */
readonly name: ParserName;
/**
* Parse Method
* @param content - full content of the file
* @param filename - filename
*/
parse(content: string, filename: string): ParseResult;
}
export interface ParseResult {
readonly content: string;
readonly filename: string;
readonly parsedTexts: Iterable<ParsedText>;
}
export interface ParsedText {
/**
* The text extracted and possibly transformed
*/
readonly text: string;
/**
* The raw text before it has been transformed
*/
readonly rawText?: string | undefined;
/**
* start and end offsets of the text
*/
readonly range: Range;
/**
* The Scope annotation for a segment of text.
* Used by the spell checker to apply spell checking options
* based upon the value of the scope.
*/
readonly scope?: Scope | undefined;
/**
* The source map is used to support text transformations.
*
* See: {@link SourceMap}
*/
readonly map?: SourceMap | undefined;
/**
* Used to delegate parsing the contents of `text` to another parser.
*
*/
readonly delegate?: DelegateInfo | undefined;
}
/**
* A SourceMap is used to map transform a piece of text back to its original text.
* This is necessary in order to report the correct location of a spelling issue.
* An empty source map indicates that it was a 1:1 transformation.
*
* The values in a source map are number pairs (even, odd) relative to the beginning of each
* string segment.
* - even - offset in the source text
* - odd - offset in the transformed text
*
* Offsets start a 0
*
* Example:
*
* - Original text: `Grand Caf\u00e9 Bj\u00f8rvika`
* - Transformed text: `Grand Café Bjørvika`
* - Map: [9, 9, 15, 10, 18, 13, 24, 14]
*
* | offset | original | offset | transformed |
* | ------ | ----------- | ------ | ----------- |
* | 0-9 | `Grand Caf` | 0-9 | `Grand Caf` |
* | 9-15 | `\u00e9` | 9-10 | `é` |
* | 15-18 | ` Bj` | 10-13 | ` Bj` |
* | 18-24 | `\u00f8` | 13-14 | `ø` |
* | 24-29 | `rvika` | 14-19 | `rvika` |
*
* <!--- cspell:ignore Bjørvika rvika --->
*/
export type SourceMap = number[];
export type Range = readonly [start: number, end: number];
/**
* DelegateInfo is used by a parser to delegate parsing a subsection of a document to
* another parser. The following information is used by the spell checker to match
* the parser.
*/
export interface DelegateInfo {
/**
* Proposed virtual file name including the extension.
* Format: `./${source_filename}/${block_number}.${ext}
* Example: `./README.md/1.js`
*/
readonly filename: string;
/**
* The filename of the origin of the virtual file block.
* Example: `./README.md`
*/
readonly originFilename: string;
/**
* Proposed file extension
* Example: `.js`
*/
readonly extension: string;
/**
* Filetype to use
* Example: `javascript`
*/
readonly fileType?: string;
}
/**
* Scope - chain of scope going from local to global
*
* Example:
* ```
* `comment.block.documentation.ts` -> `meta.interface.ts` -> `source.ts`
* ```
*/
export interface ScopeChain {
readonly value: string;
readonly parent?: ScopeChain | undefined;
}
/**
* A string representing a scope chain separated by spaces
*
* Example: `comment.block.documentation.ts meta.interface.ts source.ts`
*/
export type ScopeString = string;
export type Scope = ScopeChain | ScopeString;