@theia/editor 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
  3. package/lib/browser/decorations/editor-decoration-style.js +36 -36
  4. package/lib/browser/decorations/editor-decoration.d.ts +106 -106
  5. package/lib/browser/decorations/editor-decoration.js +37 -37
  6. package/lib/browser/decorations/editor-decorator.d.ts +6 -6
  7. package/lib/browser/decorations/editor-decorator.js +43 -43
  8. package/lib/browser/decorations/index.d.ts +3 -3
  9. package/lib/browser/decorations/index.js +30 -30
  10. package/lib/browser/diff-navigator.d.ts +9 -10
  11. package/lib/browser/diff-navigator.d.ts.map +1 -1
  12. package/lib/browser/diff-navigator.js +19 -19
  13. package/lib/browser/diff-navigator.js.map +1 -1
  14. package/lib/browser/editor-command.d.ts +102 -102
  15. package/lib/browser/editor-command.js +426 -426
  16. package/lib/browser/editor-contribution.d.ts +26 -26
  17. package/lib/browser/editor-contribution.js +198 -198
  18. package/lib/browser/editor-frontend-module.d.ts +5 -5
  19. package/lib/browser/editor-frontend-module.js +74 -74
  20. package/lib/browser/editor-generated-preference-schema.d.ts +282 -249
  21. package/lib/browser/editor-generated-preference-schema.d.ts.map +1 -1
  22. package/lib/browser/editor-generated-preference-schema.js +2451 -2316
  23. package/lib/browser/editor-generated-preference-schema.js.map +1 -1
  24. package/lib/browser/editor-keybinding.d.ts +5 -5
  25. package/lib/browser/editor-keybinding.js +55 -55
  26. package/lib/browser/editor-linenumber-contribution.d.ts +15 -15
  27. package/lib/browser/editor-linenumber-contribution.d.ts.map +1 -1
  28. package/lib/browser/editor-linenumber-contribution.js +95 -96
  29. package/lib/browser/editor-linenumber-contribution.js.map +1 -1
  30. package/lib/browser/editor-manager.d.ts +115 -115
  31. package/lib/browser/editor-manager.js +428 -428
  32. package/lib/browser/editor-menu.d.ts +48 -48
  33. package/lib/browser/editor-menu.js +210 -210
  34. package/lib/browser/editor-navigation-contribution.d.ts +67 -67
  35. package/lib/browser/editor-navigation-contribution.js +343 -343
  36. package/lib/browser/editor-preferences.d.ts +41 -41
  37. package/lib/browser/editor-preferences.js +176 -176
  38. package/lib/browser/editor-variable-contribution.d.ts +8 -8
  39. package/lib/browser/editor-variable-contribution.js +64 -64
  40. package/lib/browser/editor-widget-factory.d.ts +17 -17
  41. package/lib/browser/editor-widget-factory.js +91 -91
  42. package/lib/browser/editor-widget.d.ts +24 -24
  43. package/lib/browser/editor-widget.d.ts.map +1 -1
  44. package/lib/browser/editor-widget.js +122 -114
  45. package/lib/browser/editor-widget.js.map +1 -1
  46. package/lib/browser/editor.d.ts +295 -293
  47. package/lib/browser/editor.d.ts.map +1 -1
  48. package/lib/browser/editor.js +103 -103
  49. package/lib/browser/editor.js.map +1 -1
  50. package/lib/browser/index.d.ts +10 -10
  51. package/lib/browser/index.js +37 -37
  52. package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
  53. package/lib/browser/language-status/editor-language-status-service.js +251 -251
  54. package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
  55. package/lib/browser/navigation/navigation-location-service.js +281 -281
  56. package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
  57. package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
  58. package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
  59. package/lib/browser/navigation/navigation-location-similarity.js +62 -62
  60. package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
  61. package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
  62. package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
  63. package/lib/browser/navigation/navigation-location-updater.js +210 -210
  64. package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
  65. package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
  66. package/lib/browser/navigation/navigation-location.d.ts +191 -191
  67. package/lib/browser/navigation/navigation-location.js +300 -300
  68. package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
  69. package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
  70. package/lib/browser/quick-editor-service.d.ts +16 -16
  71. package/lib/browser/quick-editor-service.js +109 -109
  72. package/lib/browser/undo-redo-service.d.ts +23 -23
  73. package/lib/browser/undo-redo-service.js +110 -110
  74. package/lib/common/language-selector.d.ts +13 -13
  75. package/lib/common/language-selector.js +90 -90
  76. package/lib/package.spec.js +25 -25
  77. package/package.json +5 -5
  78. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  79. package/src/browser/decorations/editor-decoration.ts +127 -127
  80. package/src/browser/decorations/editor-decorator.ts +36 -36
  81. package/src/browser/decorations/index.ts +19 -19
  82. package/src/browser/diff-navigator.ts +27 -28
  83. package/src/browser/editor-command.ts +414 -414
  84. package/src/browser/editor-contribution.ts +185 -185
  85. package/src/browser/editor-frontend-module.ts +87 -87
  86. package/src/browser/editor-generated-preference-schema.ts +2707 -2539
  87. package/src/browser/editor-keybinding.ts +55 -55
  88. package/src/browser/editor-linenumber-contribution.ts +88 -89
  89. package/src/browser/editor-manager.ts +442 -442
  90. package/src/browser/editor-menu.ts +224 -224
  91. package/src/browser/editor-navigation-contribution.ts +343 -343
  92. package/src/browser/editor-preferences.ts +226 -226
  93. package/src/browser/editor-variable-contribution.ts +54 -54
  94. package/src/browser/editor-widget-factory.ts +82 -82
  95. package/src/browser/editor-widget.ts +137 -130
  96. package/src/browser/editor.ts +360 -358
  97. package/src/browser/index.ts +26 -26
  98. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  99. package/src/browser/language-status/editor-language-status.css +101 -101
  100. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  101. package/src/browser/navigation/navigation-location-service.ts +284 -284
  102. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  103. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  104. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  105. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  106. package/src/browser/navigation/navigation-location.ts +418 -418
  107. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  108. package/src/browser/quick-editor-service.ts +94 -94
  109. package/src/browser/style/index.css +19 -19
  110. package/src/browser/undo-redo-service.ts +120 -120
  111. package/src/common/language-selector.ts +104 -104
  112. package/src/package.spec.ts +28 -28
@@ -1,418 +1,418 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import URI from '@theia/core/lib/common/uri';
18
- import { Position, Range, TextDocumentContentChangeDelta } from '../editor';
19
- export { Position, Range };
20
-
21
- export namespace NavigationLocation {
22
-
23
- /**
24
- * The navigation location type.
25
- */
26
- export enum Type {
27
-
28
- /**
29
- * Cursor position change type.
30
- */
31
- CURSOR,
32
-
33
- /**
34
- * Text selection change type.
35
- */
36
- SELECTION,
37
-
38
- /**
39
- * Content change type.
40
- */
41
- CONTENT_CHANGE
42
-
43
- }
44
-
45
- /**
46
- * The type of the context for the navigation location.
47
- */
48
- export type Context = Position | Range | TextDocumentContentChangeDelta;
49
-
50
- export namespace Context {
51
-
52
- /**
53
- * Returns with the type for the context.
54
- */
55
- export function getType(context: Context): Type {
56
- if (Position.is(context)) {
57
- return Type.CURSOR;
58
- }
59
- if (Range.is(context)) {
60
- return Type.SELECTION;
61
- }
62
- if (TextDocumentContentChangeDelta.is(context)) {
63
- return Type.CONTENT_CHANGE;
64
- }
65
- throw new Error(`Unexpected context for type: ${context}.`);
66
- }
67
-
68
- }
69
-
70
- }
71
-
72
- /**
73
- * Representation of a navigation location in a text editor.
74
- */
75
- export interface NavigationLocation {
76
-
77
- /**
78
- * The URI of the resource opened in the editor.
79
- */
80
- readonly uri: URI;
81
-
82
- /**
83
- * The type of the navigation location.
84
- */
85
- readonly type: NavigationLocation.Type;
86
-
87
- /**
88
- * Context of the navigation location.
89
- */
90
- readonly context: NavigationLocation.Context;
91
-
92
- }
93
-
94
- export namespace NavigationLocation {
95
-
96
- /**
97
- * Transforms the location into an object that can be safely serialized.
98
- */
99
- export function toObject(location: NavigationLocation): object {
100
- const { uri, type } = location;
101
- const context = (() => {
102
- if (CursorLocation.is(location)) {
103
- return CursorLocation.toObject(location.context);
104
- }
105
- if (SelectionLocation.is(location)) {
106
- return SelectionLocation.toObject(location.context);
107
- }
108
- if (ContentChangeLocation.is(location)) {
109
- return ContentChangeLocation.toObject(location.context);
110
- }
111
- })();
112
- return {
113
- uri: uri.toString(),
114
- type,
115
- context
116
- };
117
- }
118
-
119
- /**
120
- * Returns with the navigation location object from its serialized counterpart.
121
- */
122
- export function fromObject(object: Partial<NavigationLocation>): NavigationLocation | undefined {
123
- const { uri, type } = object;
124
- if (uri !== undefined && type !== undefined && object.context !== undefined) {
125
- const context = (() => {
126
- switch (type) {
127
- case NavigationLocation.Type.CURSOR: return CursorLocation.fromObject(object.context as Position);
128
- case NavigationLocation.Type.SELECTION: return SelectionLocation.fromObject(object.context as Range);
129
- case NavigationLocation.Type.CONTENT_CHANGE: return ContentChangeLocation.fromObject(object.context as TextDocumentContentChangeDelta);
130
- }
131
- })();
132
- if (context) {
133
- return {
134
- uri: toUri(uri),
135
- context,
136
- type
137
- };
138
- }
139
- }
140
- return undefined;
141
- }
142
-
143
- /**
144
- * Returns with the context of the location as a `Range`.
145
- */
146
- export function range(location: NavigationLocation): Range {
147
- if (CursorLocation.is(location)) {
148
- return Range.create(location.context, location.context);
149
- }
150
- if (SelectionLocation.is(location)) {
151
- return location.context;
152
- }
153
- if (ContentChangeLocation.is(location)) {
154
- return location.context.range;
155
- }
156
- throw new Error(`Unexpected navigation location: ${location}.`);
157
- }
158
-
159
- /**
160
- * Creates a new cursor location.
161
- */
162
- export function create(uri: URI | { uri: URI } | string, context: Position): CursorLocation;
163
-
164
- /**
165
- * Creates a new selection location.
166
- */
167
- export function create(uri: URI | { uri: URI } | string, context: Range): SelectionLocation;
168
-
169
- /**
170
- * Creates a new text content change location type.
171
- */
172
- export function create(uri: URI | { uri: URI } | string, context: TextDocumentContentChangeDelta): ContentChangeLocation;
173
-
174
- /**
175
- * Creates a new navigation location object.
176
- */
177
- export function create(uri: URI | { uri: URI } | string, context: NavigationLocation.Context): NavigationLocation {
178
- const type = NavigationLocation.Context.getType(context);
179
- return {
180
- uri: toUri(uri),
181
- type,
182
- context
183
- };
184
- }
185
-
186
- /**
187
- * Returns with the human-consumable (JSON) string representation of the location argument.
188
- */
189
- export function toString(location: NavigationLocation): string {
190
- return JSON.stringify(toObject(location));
191
- }
192
-
193
- }
194
-
195
- function toUri(arg: URI | { uri: URI } | string): URI {
196
- if (arg instanceof URI) {
197
- return arg;
198
- }
199
- if (typeof arg === 'string') {
200
- return new URI(arg);
201
- }
202
- return arg.uri;
203
- }
204
-
205
- /**
206
- * Representation of a closed editor.
207
- */
208
- export interface RecentlyClosedEditor {
209
-
210
- /**
211
- * The uri of the closed editor.
212
- */
213
- readonly uri: URI,
214
-
215
- /**
216
- * The serializable view state of the closed editor.
217
- */
218
- readonly viewState: object
219
-
220
- }
221
-
222
- export namespace RecentlyClosedEditor {
223
-
224
- /**
225
- * Transform a RecentlyClosedEditor into an object for storing.
226
- *
227
- * @param closedEditor the editor needs to be transformed.
228
- */
229
- export function toObject(closedEditor: RecentlyClosedEditor): object {
230
- const { uri, viewState } = closedEditor;
231
- return {
232
- uri: uri.toString(),
233
- viewState: viewState
234
- };
235
- }
236
-
237
- /**
238
- * Transform the given object to a RecentlyClosedEditor object if possible.
239
- */
240
- export function fromObject(object: Partial<RecentlyClosedEditor>): RecentlyClosedEditor | undefined {
241
- const { uri, viewState } = object;
242
- if (uri !== undefined && viewState !== undefined) {
243
- return {
244
- uri: toUri(uri),
245
- viewState: viewState
246
- };
247
- }
248
- return undefined;
249
- }
250
-
251
- }
252
-
253
- /**
254
- * Navigation location representing the cursor location change.
255
- */
256
- export interface CursorLocation extends NavigationLocation {
257
-
258
- /**
259
- * The type is always `cursor`.
260
- */
261
- readonly type: NavigationLocation.Type.CURSOR;
262
-
263
- /**
264
- * The context for the location, that is always a position.
265
- */
266
- readonly context: Position;
267
-
268
- }
269
-
270
- export namespace CursorLocation {
271
-
272
- /**
273
- * `true` if the argument is a cursor location. Otherwise, `false`.
274
- */
275
- export function is(location: NavigationLocation): location is CursorLocation {
276
- return location.type === NavigationLocation.Type.CURSOR;
277
- }
278
-
279
- /**
280
- * Returns with the serialized format of the position argument.
281
- */
282
- export function toObject(context: Position): object {
283
- const { line, character } = context;
284
- return {
285
- line,
286
- character
287
- };
288
- }
289
-
290
- /**
291
- * Returns with the position from its serializable counterpart, or `undefined`.
292
- */
293
- export function fromObject(object: Partial<Position>): Position | undefined {
294
- if (object.line !== undefined && object.character !== undefined) {
295
- const { line, character } = object;
296
- return {
297
- line,
298
- character
299
- };
300
- }
301
- return undefined;
302
- }
303
-
304
- }
305
-
306
- /**
307
- * Representation of a selection location.
308
- */
309
- export interface SelectionLocation extends NavigationLocation {
310
-
311
- /**
312
- * The `selection` type.
313
- */
314
- readonly type: NavigationLocation.Type.SELECTION;
315
-
316
- /**
317
- * The context of the selection; a range.
318
- */
319
- readonly context: Range;
320
-
321
- }
322
-
323
- export namespace SelectionLocation {
324
-
325
- /**
326
- * `true` if the argument is a selection location.
327
- */
328
- export function is(location: NavigationLocation): location is SelectionLocation {
329
- return location.type === NavigationLocation.Type.SELECTION;
330
- }
331
-
332
- /**
333
- * Converts the range argument into a serializable object.
334
- */
335
- export function toObject(context: Range): object {
336
- const { start, end } = context;
337
- return {
338
- start: CursorLocation.toObject(start),
339
- end: CursorLocation.toObject(end)
340
- };
341
- }
342
-
343
- /**
344
- * Creates a range object from its serializable counterpart. Returns with `undefined` if the argument cannot be converted into a range.
345
- */
346
- export function fromObject(object: Partial<Range>): Range | undefined {
347
- if (!!object.start && !!object.end) {
348
- const start = CursorLocation.fromObject(object.start);
349
- const end = CursorLocation.fromObject(object.end);
350
- if (start && end) {
351
- return {
352
- start,
353
- end
354
- };
355
- }
356
- }
357
- return undefined;
358
- }
359
- }
360
-
361
- /**
362
- * Content change location type.
363
- */
364
- export interface ContentChangeLocation extends NavigationLocation {
365
-
366
- /**
367
- * The type, that is always `content change`.
368
- */
369
- readonly type: NavigationLocation.Type.CONTENT_CHANGE;
370
-
371
- /**
372
- * A text document content change deltas as the context.
373
- */
374
- readonly context: TextDocumentContentChangeDelta;
375
-
376
- }
377
-
378
- export namespace ContentChangeLocation {
379
-
380
- /**
381
- * `true` if the argument is a content change location. Otherwise, `false`.
382
- */
383
- export function is(location: NavigationLocation): location is ContentChangeLocation {
384
- return location.type === NavigationLocation.Type.CONTENT_CHANGE;
385
- }
386
-
387
- /**
388
- * Returns with a serializable object representing the arguments.
389
- */
390
- export function toObject(context: TextDocumentContentChangeDelta): object {
391
- return {
392
- range: SelectionLocation.toObject(context.range),
393
- rangeLength: context.rangeLength,
394
- text: context.text
395
- };
396
- }
397
-
398
- /**
399
- * Returns with a text document change delta for the argument. `undefined` if the argument cannot be mapped to a content change delta.
400
- */
401
- export function fromObject(object: Partial<TextDocumentContentChangeDelta>): TextDocumentContentChangeDelta | undefined {
402
- if (!!object.range && object.rangeLength !== undefined && object.text !== undefined) {
403
- const range = SelectionLocation.fromObject(object.range!);
404
- const rangeLength = object.rangeLength;
405
- const text = object.text;
406
- if (!!range) {
407
- return {
408
- range,
409
- rangeLength: rangeLength!,
410
- text: text!
411
- };
412
- }
413
- } else {
414
- return undefined;
415
- }
416
- }
417
-
418
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import URI from '@theia/core/lib/common/uri';
18
+ import { Position, Range, TextDocumentContentChangeDelta } from '../editor';
19
+ export { Position, Range };
20
+
21
+ export namespace NavigationLocation {
22
+
23
+ /**
24
+ * The navigation location type.
25
+ */
26
+ export enum Type {
27
+
28
+ /**
29
+ * Cursor position change type.
30
+ */
31
+ CURSOR,
32
+
33
+ /**
34
+ * Text selection change type.
35
+ */
36
+ SELECTION,
37
+
38
+ /**
39
+ * Content change type.
40
+ */
41
+ CONTENT_CHANGE
42
+
43
+ }
44
+
45
+ /**
46
+ * The type of the context for the navigation location.
47
+ */
48
+ export type Context = Position | Range | TextDocumentContentChangeDelta;
49
+
50
+ export namespace Context {
51
+
52
+ /**
53
+ * Returns with the type for the context.
54
+ */
55
+ export function getType(context: Context): Type {
56
+ if (Position.is(context)) {
57
+ return Type.CURSOR;
58
+ }
59
+ if (Range.is(context)) {
60
+ return Type.SELECTION;
61
+ }
62
+ if (TextDocumentContentChangeDelta.is(context)) {
63
+ return Type.CONTENT_CHANGE;
64
+ }
65
+ throw new Error(`Unexpected context for type: ${context}.`);
66
+ }
67
+
68
+ }
69
+
70
+ }
71
+
72
+ /**
73
+ * Representation of a navigation location in a text editor.
74
+ */
75
+ export interface NavigationLocation {
76
+
77
+ /**
78
+ * The URI of the resource opened in the editor.
79
+ */
80
+ readonly uri: URI;
81
+
82
+ /**
83
+ * The type of the navigation location.
84
+ */
85
+ readonly type: NavigationLocation.Type;
86
+
87
+ /**
88
+ * Context of the navigation location.
89
+ */
90
+ readonly context: NavigationLocation.Context;
91
+
92
+ }
93
+
94
+ export namespace NavigationLocation {
95
+
96
+ /**
97
+ * Transforms the location into an object that can be safely serialized.
98
+ */
99
+ export function toObject(location: NavigationLocation): object {
100
+ const { uri, type } = location;
101
+ const context = (() => {
102
+ if (CursorLocation.is(location)) {
103
+ return CursorLocation.toObject(location.context);
104
+ }
105
+ if (SelectionLocation.is(location)) {
106
+ return SelectionLocation.toObject(location.context);
107
+ }
108
+ if (ContentChangeLocation.is(location)) {
109
+ return ContentChangeLocation.toObject(location.context);
110
+ }
111
+ })();
112
+ return {
113
+ uri: uri.toString(),
114
+ type,
115
+ context
116
+ };
117
+ }
118
+
119
+ /**
120
+ * Returns with the navigation location object from its serialized counterpart.
121
+ */
122
+ export function fromObject(object: Partial<NavigationLocation>): NavigationLocation | undefined {
123
+ const { uri, type } = object;
124
+ if (uri !== undefined && type !== undefined && object.context !== undefined) {
125
+ const context = (() => {
126
+ switch (type) {
127
+ case NavigationLocation.Type.CURSOR: return CursorLocation.fromObject(object.context as Position);
128
+ case NavigationLocation.Type.SELECTION: return SelectionLocation.fromObject(object.context as Range);
129
+ case NavigationLocation.Type.CONTENT_CHANGE: return ContentChangeLocation.fromObject(object.context as TextDocumentContentChangeDelta);
130
+ }
131
+ })();
132
+ if (context) {
133
+ return {
134
+ uri: toUri(uri),
135
+ context,
136
+ type
137
+ };
138
+ }
139
+ }
140
+ return undefined;
141
+ }
142
+
143
+ /**
144
+ * Returns with the context of the location as a `Range`.
145
+ */
146
+ export function range(location: NavigationLocation): Range {
147
+ if (CursorLocation.is(location)) {
148
+ return Range.create(location.context, location.context);
149
+ }
150
+ if (SelectionLocation.is(location)) {
151
+ return location.context;
152
+ }
153
+ if (ContentChangeLocation.is(location)) {
154
+ return location.context.range;
155
+ }
156
+ throw new Error(`Unexpected navigation location: ${location}.`);
157
+ }
158
+
159
+ /**
160
+ * Creates a new cursor location.
161
+ */
162
+ export function create(uri: URI | { uri: URI } | string, context: Position): CursorLocation;
163
+
164
+ /**
165
+ * Creates a new selection location.
166
+ */
167
+ export function create(uri: URI | { uri: URI } | string, context: Range): SelectionLocation;
168
+
169
+ /**
170
+ * Creates a new text content change location type.
171
+ */
172
+ export function create(uri: URI | { uri: URI } | string, context: TextDocumentContentChangeDelta): ContentChangeLocation;
173
+
174
+ /**
175
+ * Creates a new navigation location object.
176
+ */
177
+ export function create(uri: URI | { uri: URI } | string, context: NavigationLocation.Context): NavigationLocation {
178
+ const type = NavigationLocation.Context.getType(context);
179
+ return {
180
+ uri: toUri(uri),
181
+ type,
182
+ context
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Returns with the human-consumable (JSON) string representation of the location argument.
188
+ */
189
+ export function toString(location: NavigationLocation): string {
190
+ return JSON.stringify(toObject(location));
191
+ }
192
+
193
+ }
194
+
195
+ function toUri(arg: URI | { uri: URI } | string): URI {
196
+ if (arg instanceof URI) {
197
+ return arg;
198
+ }
199
+ if (typeof arg === 'string') {
200
+ return new URI(arg);
201
+ }
202
+ return arg.uri;
203
+ }
204
+
205
+ /**
206
+ * Representation of a closed editor.
207
+ */
208
+ export interface RecentlyClosedEditor {
209
+
210
+ /**
211
+ * The uri of the closed editor.
212
+ */
213
+ readonly uri: URI,
214
+
215
+ /**
216
+ * The serializable view state of the closed editor.
217
+ */
218
+ readonly viewState: object
219
+
220
+ }
221
+
222
+ export namespace RecentlyClosedEditor {
223
+
224
+ /**
225
+ * Transform a RecentlyClosedEditor into an object for storing.
226
+ *
227
+ * @param closedEditor the editor needs to be transformed.
228
+ */
229
+ export function toObject(closedEditor: RecentlyClosedEditor): object {
230
+ const { uri, viewState } = closedEditor;
231
+ return {
232
+ uri: uri.toString(),
233
+ viewState: viewState
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Transform the given object to a RecentlyClosedEditor object if possible.
239
+ */
240
+ export function fromObject(object: Partial<RecentlyClosedEditor>): RecentlyClosedEditor | undefined {
241
+ const { uri, viewState } = object;
242
+ if (uri !== undefined && viewState !== undefined) {
243
+ return {
244
+ uri: toUri(uri),
245
+ viewState: viewState
246
+ };
247
+ }
248
+ return undefined;
249
+ }
250
+
251
+ }
252
+
253
+ /**
254
+ * Navigation location representing the cursor location change.
255
+ */
256
+ export interface CursorLocation extends NavigationLocation {
257
+
258
+ /**
259
+ * The type is always `cursor`.
260
+ */
261
+ readonly type: NavigationLocation.Type.CURSOR;
262
+
263
+ /**
264
+ * The context for the location, that is always a position.
265
+ */
266
+ readonly context: Position;
267
+
268
+ }
269
+
270
+ export namespace CursorLocation {
271
+
272
+ /**
273
+ * `true` if the argument is a cursor location. Otherwise, `false`.
274
+ */
275
+ export function is(location: NavigationLocation): location is CursorLocation {
276
+ return location.type === NavigationLocation.Type.CURSOR;
277
+ }
278
+
279
+ /**
280
+ * Returns with the serialized format of the position argument.
281
+ */
282
+ export function toObject(context: Position): object {
283
+ const { line, character } = context;
284
+ return {
285
+ line,
286
+ character
287
+ };
288
+ }
289
+
290
+ /**
291
+ * Returns with the position from its serializable counterpart, or `undefined`.
292
+ */
293
+ export function fromObject(object: Partial<Position>): Position | undefined {
294
+ if (object.line !== undefined && object.character !== undefined) {
295
+ const { line, character } = object;
296
+ return {
297
+ line,
298
+ character
299
+ };
300
+ }
301
+ return undefined;
302
+ }
303
+
304
+ }
305
+
306
+ /**
307
+ * Representation of a selection location.
308
+ */
309
+ export interface SelectionLocation extends NavigationLocation {
310
+
311
+ /**
312
+ * The `selection` type.
313
+ */
314
+ readonly type: NavigationLocation.Type.SELECTION;
315
+
316
+ /**
317
+ * The context of the selection; a range.
318
+ */
319
+ readonly context: Range;
320
+
321
+ }
322
+
323
+ export namespace SelectionLocation {
324
+
325
+ /**
326
+ * `true` if the argument is a selection location.
327
+ */
328
+ export function is(location: NavigationLocation): location is SelectionLocation {
329
+ return location.type === NavigationLocation.Type.SELECTION;
330
+ }
331
+
332
+ /**
333
+ * Converts the range argument into a serializable object.
334
+ */
335
+ export function toObject(context: Range): object {
336
+ const { start, end } = context;
337
+ return {
338
+ start: CursorLocation.toObject(start),
339
+ end: CursorLocation.toObject(end)
340
+ };
341
+ }
342
+
343
+ /**
344
+ * Creates a range object from its serializable counterpart. Returns with `undefined` if the argument cannot be converted into a range.
345
+ */
346
+ export function fromObject(object: Partial<Range>): Range | undefined {
347
+ if (!!object.start && !!object.end) {
348
+ const start = CursorLocation.fromObject(object.start);
349
+ const end = CursorLocation.fromObject(object.end);
350
+ if (start && end) {
351
+ return {
352
+ start,
353
+ end
354
+ };
355
+ }
356
+ }
357
+ return undefined;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Content change location type.
363
+ */
364
+ export interface ContentChangeLocation extends NavigationLocation {
365
+
366
+ /**
367
+ * The type, that is always `content change`.
368
+ */
369
+ readonly type: NavigationLocation.Type.CONTENT_CHANGE;
370
+
371
+ /**
372
+ * A text document content change deltas as the context.
373
+ */
374
+ readonly context: TextDocumentContentChangeDelta;
375
+
376
+ }
377
+
378
+ export namespace ContentChangeLocation {
379
+
380
+ /**
381
+ * `true` if the argument is a content change location. Otherwise, `false`.
382
+ */
383
+ export function is(location: NavigationLocation): location is ContentChangeLocation {
384
+ return location.type === NavigationLocation.Type.CONTENT_CHANGE;
385
+ }
386
+
387
+ /**
388
+ * Returns with a serializable object representing the arguments.
389
+ */
390
+ export function toObject(context: TextDocumentContentChangeDelta): object {
391
+ return {
392
+ range: SelectionLocation.toObject(context.range),
393
+ rangeLength: context.rangeLength,
394
+ text: context.text
395
+ };
396
+ }
397
+
398
+ /**
399
+ * Returns with a text document change delta for the argument. `undefined` if the argument cannot be mapped to a content change delta.
400
+ */
401
+ export function fromObject(object: Partial<TextDocumentContentChangeDelta>): TextDocumentContentChangeDelta | undefined {
402
+ if (!!object.range && object.rangeLength !== undefined && object.text !== undefined) {
403
+ const range = SelectionLocation.fromObject(object.range!);
404
+ const rangeLength = object.rangeLength;
405
+ const text = object.text;
406
+ if (!!range) {
407
+ return {
408
+ range,
409
+ rangeLength: rangeLength!,
410
+ text: text!
411
+ };
412
+ }
413
+ } else {
414
+ return undefined;
415
+ }
416
+ }
417
+
418
+ }