UNPKG

6.35 kBTypeScriptView Raw
1/**
2 * A tagging type for string properties that are actually URIs.
3 */
4export type DocumentUri = string;
5/**
6 * Position in a text document expressed as zero-based line and character offset.
7 * The offsets are based on a UTF-16 string representation. So a string of the form
8 * `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀`
9 * is 1 and the character offset of b is 3 since `𐐀` is represented using two code
10 * units in UTF-16.
11 *
12 * Positions are line end character agnostic. So you can not specify a position that
13 * denotes `\r|\n` or `\n|` where `|` represents the character offset.
14 */
15export interface Position {
16 /**
17 * Line position in a document (zero-based).
18 *
19 * If a line number is greater than the number of lines in a document, it
20 * defaults back to the number of lines in the document.
21 * If a line number is negative, it defaults to 0.
22 *
23 * The above two properties are implementation specific.
24 */
25 line: number;
26 /**
27 * Character offset on a line in a document (zero-based).
28 *
29 * The meaning of this offset is determined by the negotiated
30 * `PositionEncodingKind`.
31 *
32 * If the character value is greater than the line length it defaults back
33 * to the line length. This property is implementation specific.
34 */
35 character: number;
36}
37/**
38 * A range in a text document expressed as (zero-based) start and end positions.
39 *
40 * If you want to specify a range that contains a line including the line ending
41 * character(s) then use an end position denoting the start of the next line.
42 * For example:
43 * ```ts
44 * {
45 * start: { line: 5, character: 23 }
46 * end : { line 6, character : 0 }
47 * }
48 * ```
49 */
50export interface Range {
51 /**
52 * The range's start position.
53 */
54 start: Position;
55 /**
56 * The range's end position.
57 */
58 end: Position;
59}
60/**
61 * A text edit applicable to a text document.
62 */
63export interface TextEdit {
64 /**
65 * The range of the text document to be manipulated. To insert
66 * text into a document create a range where start === end.
67 */
68 range: Range;
69 /**
70 * The string to be inserted. For delete operations use an
71 * empty string.
72 */
73 newText: string;
74}
75/**
76 * An event describing a change to a text document. If range and rangeLength are omitted
77 * the new text is considered to be the full content of the document.
78 */
79export type TextDocumentContentChangeEvent = {
80 /**
81 * The range of the document that changed.
82 */
83 range: Range;
84 /**
85 * The optional length of the range that got replaced.
86 *
87 * @deprecated use range instead.
88 */
89 rangeLength?: number;
90 /**
91 * The new text for the provided range.
92 */
93 text: string;
94} | {
95 /**
96 * The new text of the whole document.
97 */
98 text: string;
99};
100/**
101 * A simple text document. Not to be implemented. The document keeps the content
102 * as string.
103 */
104export interface TextDocument {
105 /**
106 * The associated URI for this document. Most documents have the __file__-scheme, indicating that they
107 * represent files on disk. However, some documents may have other schemes indicating that they are not
108 * available on disk.
109 *
110 * @readonly
111 */
112 readonly uri: DocumentUri;
113 /**
114 * The identifier of the language associated with this document.
115 *
116 * @readonly
117 */
118 readonly languageId: string;
119 /**
120 * The version number of this document (it will increase after each
121 * change, including undo/redo).
122 *
123 * @readonly
124 */
125 readonly version: number;
126 /**
127 * Get the text of this document. A substring can be retrieved by
128 * providing a range.
129 *
130 * @param range (optional) An range within the document to return.
131 * If no range is passed, the full content is returned.
132 * Invalid range positions are adjusted as described in {@link Position.line}
133 * and {@link Position.character}.
134 * If the start range position is greater than the end range position,
135 * then the effect of getText is as if the two positions were swapped.
136
137 * @return The text of this document or a substring of the text if a
138 * range is provided.
139 */
140 getText(range?: Range): string;
141 /**
142 * Converts a zero-based offset to a position.
143 *
144 * @param offset A zero-based offset.
145 * @return A valid {@link Position position}.
146 * @example The text document "ab\ncd" produces:
147 * * position { line: 0, character: 0 } for `offset` 0.
148 * * position { line: 0, character: 1 } for `offset` 1.
149 * * position { line: 0, character: 2 } for `offset` 2.
150 * * position { line: 1, character: 0 } for `offset` 3.
151 * * position { line: 1, character: 1 } for `offset` 4.
152 */
153 positionAt(offset: number): Position;
154 /**
155 * Converts the position to a zero-based offset.
156 * Invalid positions are adjusted as described in {@link Position.line}
157 * and {@link Position.character}.
158 *
159 * @param position A position.
160 * @return A valid zero-based offset.
161 */
162 offsetAt(position: Position): number;
163 /**
164 * The number of lines in this document.
165 *
166 * @readonly
167 */
168 readonly lineCount: number;
169}
170export declare namespace TextDocument {
171 /**
172 * Creates a new text document.
173 *
174 * @param uri The document's uri.
175 * @param languageId The document's language Id.
176 * @param version The document's initial version number.
177 * @param content The document's content.
178 */
179 function create(uri: DocumentUri, languageId: string, version: number, content: string): TextDocument;
180 /**
181 * Updates a TextDocument by modifying its content.
182 *
183 * @param document the document to update. Only documents created by TextDocument.create are valid inputs.
184 * @param changes the changes to apply to the document.
185 * @param version the changes version for the document.
186 * @returns The updated TextDocument. Note: That's the same document instance passed in as first parameter.
187 *
188 */
189 function update(document: TextDocument, changes: TextDocumentContentChangeEvent[], version: number): TextDocument;
190 function applyEdits(document: TextDocument, edits: TextEdit[]): string;
191}