@codingame/monaco-vscode-standalone-html-language-features 3.2.0

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 (4) hide show
  1. package/htmlMode.js +2139 -0
  2. package/index.js +146 -0
  3. package/package.json +30 -0
  4. package/worker.js +16244 -0
package/htmlMode.js ADDED
@@ -0,0 +1,2139 @@
1
+ import * as monaco_editor_core_star from 'monaco-editor';
2
+
3
+ /*!-----------------------------------------------------------------------------
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
+ * Version: 0.47.0(undefined)
6
+ * Released under the MIT license
7
+ * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
8
+ *-----------------------------------------------------------------------------*/
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
23
+
24
+ // src/fillers/monaco-editor-core.ts
25
+ var monaco_editor_core_exports = {};
26
+ __reExport(monaco_editor_core_exports, monaco_editor_core_star);
27
+
28
+ // src/language/html/workerManager.ts
29
+ var STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
30
+ var WorkerManager = class {
31
+ constructor(defaults) {
32
+ this._defaults = defaults;
33
+ this._worker = null;
34
+ this._client = null;
35
+ this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
36
+ this._lastUsedTime = 0;
37
+ this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
38
+ }
39
+ _stopWorker() {
40
+ if (this._worker) {
41
+ this._worker.dispose();
42
+ this._worker = null;
43
+ }
44
+ this._client = null;
45
+ }
46
+ dispose() {
47
+ clearInterval(this._idleCheckInterval);
48
+ this._configChangeListener.dispose();
49
+ this._stopWorker();
50
+ }
51
+ _checkIfIdle() {
52
+ if (!this._worker) {
53
+ return;
54
+ }
55
+ let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
56
+ if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
57
+ this._stopWorker();
58
+ }
59
+ }
60
+ _getClient() {
61
+ this._lastUsedTime = Date.now();
62
+ if (!this._client) {
63
+ this._worker = monaco_editor_core_exports.editor.createWebWorker({
64
+ // module that exports the create() method and returns a `HTMLWorker` instance
65
+ moduleId: "vs/language/html/htmlWorker",
66
+ // passed in to the create() method
67
+ createData: {
68
+ languageSettings: this._defaults.options,
69
+ languageId: this._defaults.languageId
70
+ },
71
+ label: this._defaults.languageId
72
+ });
73
+ this._client = this._worker.getProxy();
74
+ }
75
+ return this._client;
76
+ }
77
+ getLanguageServiceWorker(...resources) {
78
+ let _client;
79
+ return this._getClient().then((client) => {
80
+ _client = client;
81
+ }).then((_) => {
82
+ if (this._worker) {
83
+ return this._worker.withSyncedResources(resources);
84
+ }
85
+ }).then((_) => _client);
86
+ }
87
+ };
88
+
89
+ // node_modules/vscode-languageserver-types/lib/esm/main.js
90
+ var integer;
91
+ (function(integer2) {
92
+ integer2.MIN_VALUE = -2147483648;
93
+ integer2.MAX_VALUE = 2147483647;
94
+ })(integer || (integer = {}));
95
+ var uinteger;
96
+ (function(uinteger2) {
97
+ uinteger2.MIN_VALUE = 0;
98
+ uinteger2.MAX_VALUE = 2147483647;
99
+ })(uinteger || (uinteger = {}));
100
+ var Position;
101
+ (function(Position3) {
102
+ function create(line, character) {
103
+ if (line === Number.MAX_VALUE) {
104
+ line = uinteger.MAX_VALUE;
105
+ }
106
+ if (character === Number.MAX_VALUE) {
107
+ character = uinteger.MAX_VALUE;
108
+ }
109
+ return { line, character };
110
+ }
111
+ Position3.create = create;
112
+ function is(value) {
113
+ var candidate = value;
114
+ return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
115
+ }
116
+ Position3.is = is;
117
+ })(Position || (Position = {}));
118
+ var Range;
119
+ (function(Range3) {
120
+ function create(one, two, three, four) {
121
+ if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
122
+ return { start: Position.create(one, two), end: Position.create(three, four) };
123
+ } else if (Position.is(one) && Position.is(two)) {
124
+ return { start: one, end: two };
125
+ } else {
126
+ throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
127
+ }
128
+ }
129
+ Range3.create = create;
130
+ function is(value) {
131
+ var candidate = value;
132
+ return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
133
+ }
134
+ Range3.is = is;
135
+ })(Range || (Range = {}));
136
+ var Location;
137
+ (function(Location2) {
138
+ function create(uri, range) {
139
+ return { uri, range };
140
+ }
141
+ Location2.create = create;
142
+ function is(value) {
143
+ var candidate = value;
144
+ return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
145
+ }
146
+ Location2.is = is;
147
+ })(Location || (Location = {}));
148
+ var LocationLink;
149
+ (function(LocationLink2) {
150
+ function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
151
+ return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
152
+ }
153
+ LocationLink2.create = create;
154
+ function is(value) {
155
+ var candidate = value;
156
+ return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange)) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
157
+ }
158
+ LocationLink2.is = is;
159
+ })(LocationLink || (LocationLink = {}));
160
+ var Color;
161
+ (function(Color2) {
162
+ function create(red, green, blue, alpha) {
163
+ return {
164
+ red,
165
+ green,
166
+ blue,
167
+ alpha
168
+ };
169
+ }
170
+ Color2.create = create;
171
+ function is(value) {
172
+ var candidate = value;
173
+ return Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1);
174
+ }
175
+ Color2.is = is;
176
+ })(Color || (Color = {}));
177
+ var ColorInformation;
178
+ (function(ColorInformation2) {
179
+ function create(range, color) {
180
+ return {
181
+ range,
182
+ color
183
+ };
184
+ }
185
+ ColorInformation2.create = create;
186
+ function is(value) {
187
+ var candidate = value;
188
+ return Range.is(candidate.range) && Color.is(candidate.color);
189
+ }
190
+ ColorInformation2.is = is;
191
+ })(ColorInformation || (ColorInformation = {}));
192
+ var ColorPresentation;
193
+ (function(ColorPresentation2) {
194
+ function create(label, textEdit, additionalTextEdits) {
195
+ return {
196
+ label,
197
+ textEdit,
198
+ additionalTextEdits
199
+ };
200
+ }
201
+ ColorPresentation2.create = create;
202
+ function is(value) {
203
+ var candidate = value;
204
+ return Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
205
+ }
206
+ ColorPresentation2.is = is;
207
+ })(ColorPresentation || (ColorPresentation = {}));
208
+ var FoldingRangeKind;
209
+ (function(FoldingRangeKind2) {
210
+ FoldingRangeKind2["Comment"] = "comment";
211
+ FoldingRangeKind2["Imports"] = "imports";
212
+ FoldingRangeKind2["Region"] = "region";
213
+ })(FoldingRangeKind || (FoldingRangeKind = {}));
214
+ var FoldingRange;
215
+ (function(FoldingRange2) {
216
+ function create(startLine, endLine, startCharacter, endCharacter, kind) {
217
+ var result = {
218
+ startLine,
219
+ endLine
220
+ };
221
+ if (Is.defined(startCharacter)) {
222
+ result.startCharacter = startCharacter;
223
+ }
224
+ if (Is.defined(endCharacter)) {
225
+ result.endCharacter = endCharacter;
226
+ }
227
+ if (Is.defined(kind)) {
228
+ result.kind = kind;
229
+ }
230
+ return result;
231
+ }
232
+ FoldingRange2.create = create;
233
+ function is(value) {
234
+ var candidate = value;
235
+ return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine) && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter)) && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter)) && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
236
+ }
237
+ FoldingRange2.is = is;
238
+ })(FoldingRange || (FoldingRange = {}));
239
+ var DiagnosticRelatedInformation;
240
+ (function(DiagnosticRelatedInformation2) {
241
+ function create(location, message) {
242
+ return {
243
+ location,
244
+ message
245
+ };
246
+ }
247
+ DiagnosticRelatedInformation2.create = create;
248
+ function is(value) {
249
+ var candidate = value;
250
+ return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
251
+ }
252
+ DiagnosticRelatedInformation2.is = is;
253
+ })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
254
+ var DiagnosticSeverity;
255
+ (function(DiagnosticSeverity2) {
256
+ DiagnosticSeverity2.Error = 1;
257
+ DiagnosticSeverity2.Warning = 2;
258
+ DiagnosticSeverity2.Information = 3;
259
+ DiagnosticSeverity2.Hint = 4;
260
+ })(DiagnosticSeverity || (DiagnosticSeverity = {}));
261
+ var DiagnosticTag;
262
+ (function(DiagnosticTag2) {
263
+ DiagnosticTag2.Unnecessary = 1;
264
+ DiagnosticTag2.Deprecated = 2;
265
+ })(DiagnosticTag || (DiagnosticTag = {}));
266
+ var CodeDescription;
267
+ (function(CodeDescription2) {
268
+ function is(value) {
269
+ var candidate = value;
270
+ return candidate !== void 0 && candidate !== null && Is.string(candidate.href);
271
+ }
272
+ CodeDescription2.is = is;
273
+ })(CodeDescription || (CodeDescription = {}));
274
+ var Diagnostic;
275
+ (function(Diagnostic2) {
276
+ function create(range, message, severity, code, source, relatedInformation) {
277
+ var result = { range, message };
278
+ if (Is.defined(severity)) {
279
+ result.severity = severity;
280
+ }
281
+ if (Is.defined(code)) {
282
+ result.code = code;
283
+ }
284
+ if (Is.defined(source)) {
285
+ result.source = source;
286
+ }
287
+ if (Is.defined(relatedInformation)) {
288
+ result.relatedInformation = relatedInformation;
289
+ }
290
+ return result;
291
+ }
292
+ Diagnostic2.create = create;
293
+ function is(value) {
294
+ var _a;
295
+ var candidate = value;
296
+ return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
297
+ }
298
+ Diagnostic2.is = is;
299
+ })(Diagnostic || (Diagnostic = {}));
300
+ var Command;
301
+ (function(Command2) {
302
+ function create(title, command) {
303
+ var args = [];
304
+ for (var _i = 2; _i < arguments.length; _i++) {
305
+ args[_i - 2] = arguments[_i];
306
+ }
307
+ var result = { title, command };
308
+ if (Is.defined(args) && args.length > 0) {
309
+ result.arguments = args;
310
+ }
311
+ return result;
312
+ }
313
+ Command2.create = create;
314
+ function is(value) {
315
+ var candidate = value;
316
+ return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
317
+ }
318
+ Command2.is = is;
319
+ })(Command || (Command = {}));
320
+ var TextEdit;
321
+ (function(TextEdit2) {
322
+ function replace(range, newText) {
323
+ return { range, newText };
324
+ }
325
+ TextEdit2.replace = replace;
326
+ function insert(position, newText) {
327
+ return { range: { start: position, end: position }, newText };
328
+ }
329
+ TextEdit2.insert = insert;
330
+ function del(range) {
331
+ return { range, newText: "" };
332
+ }
333
+ TextEdit2.del = del;
334
+ function is(value) {
335
+ var candidate = value;
336
+ return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
337
+ }
338
+ TextEdit2.is = is;
339
+ })(TextEdit || (TextEdit = {}));
340
+ var ChangeAnnotation;
341
+ (function(ChangeAnnotation2) {
342
+ function create(label, needsConfirmation, description) {
343
+ var result = { label };
344
+ if (needsConfirmation !== void 0) {
345
+ result.needsConfirmation = needsConfirmation;
346
+ }
347
+ if (description !== void 0) {
348
+ result.description = description;
349
+ }
350
+ return result;
351
+ }
352
+ ChangeAnnotation2.create = create;
353
+ function is(value) {
354
+ var candidate = value;
355
+ return candidate !== void 0 && Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === void 0) && (Is.string(candidate.description) || candidate.description === void 0);
356
+ }
357
+ ChangeAnnotation2.is = is;
358
+ })(ChangeAnnotation || (ChangeAnnotation = {}));
359
+ var ChangeAnnotationIdentifier;
360
+ (function(ChangeAnnotationIdentifier2) {
361
+ function is(value) {
362
+ var candidate = value;
363
+ return typeof candidate === "string";
364
+ }
365
+ ChangeAnnotationIdentifier2.is = is;
366
+ })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
367
+ var AnnotatedTextEdit;
368
+ (function(AnnotatedTextEdit2) {
369
+ function replace(range, newText, annotation) {
370
+ return { range, newText, annotationId: annotation };
371
+ }
372
+ AnnotatedTextEdit2.replace = replace;
373
+ function insert(position, newText, annotation) {
374
+ return { range: { start: position, end: position }, newText, annotationId: annotation };
375
+ }
376
+ AnnotatedTextEdit2.insert = insert;
377
+ function del(range, annotation) {
378
+ return { range, newText: "", annotationId: annotation };
379
+ }
380
+ AnnotatedTextEdit2.del = del;
381
+ function is(value) {
382
+ var candidate = value;
383
+ return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
384
+ }
385
+ AnnotatedTextEdit2.is = is;
386
+ })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
387
+ var TextDocumentEdit;
388
+ (function(TextDocumentEdit2) {
389
+ function create(textDocument, edits) {
390
+ return { textDocument, edits };
391
+ }
392
+ TextDocumentEdit2.create = create;
393
+ function is(value) {
394
+ var candidate = value;
395
+ return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
396
+ }
397
+ TextDocumentEdit2.is = is;
398
+ })(TextDocumentEdit || (TextDocumentEdit = {}));
399
+ var CreateFile;
400
+ (function(CreateFile2) {
401
+ function create(uri, options, annotation) {
402
+ var result = {
403
+ kind: "create",
404
+ uri
405
+ };
406
+ if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
407
+ result.options = options;
408
+ }
409
+ if (annotation !== void 0) {
410
+ result.annotationId = annotation;
411
+ }
412
+ return result;
413
+ }
414
+ CreateFile2.create = create;
415
+ function is(value) {
416
+ var candidate = value;
417
+ return candidate && candidate.kind === "create" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
418
+ }
419
+ CreateFile2.is = is;
420
+ })(CreateFile || (CreateFile = {}));
421
+ var RenameFile;
422
+ (function(RenameFile2) {
423
+ function create(oldUri, newUri, options, annotation) {
424
+ var result = {
425
+ kind: "rename",
426
+ oldUri,
427
+ newUri
428
+ };
429
+ if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
430
+ result.options = options;
431
+ }
432
+ if (annotation !== void 0) {
433
+ result.annotationId = annotation;
434
+ }
435
+ return result;
436
+ }
437
+ RenameFile2.create = create;
438
+ function is(value) {
439
+ var candidate = value;
440
+ return candidate && candidate.kind === "rename" && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
441
+ }
442
+ RenameFile2.is = is;
443
+ })(RenameFile || (RenameFile = {}));
444
+ var DeleteFile;
445
+ (function(DeleteFile2) {
446
+ function create(uri, options, annotation) {
447
+ var result = {
448
+ kind: "delete",
449
+ uri
450
+ };
451
+ if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
452
+ result.options = options;
453
+ }
454
+ if (annotation !== void 0) {
455
+ result.annotationId = annotation;
456
+ }
457
+ return result;
458
+ }
459
+ DeleteFile2.create = create;
460
+ function is(value) {
461
+ var candidate = value;
462
+ return candidate && candidate.kind === "delete" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.recursive === void 0 || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === void 0 || Is.boolean(candidate.options.ignoreIfNotExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
463
+ }
464
+ DeleteFile2.is = is;
465
+ })(DeleteFile || (DeleteFile = {}));
466
+ var WorkspaceEdit;
467
+ (function(WorkspaceEdit2) {
468
+ function is(value) {
469
+ var candidate = value;
470
+ return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every(function(change) {
471
+ if (Is.string(change.kind)) {
472
+ return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
473
+ } else {
474
+ return TextDocumentEdit.is(change);
475
+ }
476
+ }));
477
+ }
478
+ WorkspaceEdit2.is = is;
479
+ })(WorkspaceEdit || (WorkspaceEdit = {}));
480
+ var TextEditChangeImpl = (
481
+ /** @class */
482
+ function() {
483
+ function TextEditChangeImpl2(edits, changeAnnotations) {
484
+ this.edits = edits;
485
+ this.changeAnnotations = changeAnnotations;
486
+ }
487
+ TextEditChangeImpl2.prototype.insert = function(position, newText, annotation) {
488
+ var edit;
489
+ var id;
490
+ if (annotation === void 0) {
491
+ edit = TextEdit.insert(position, newText);
492
+ } else if (ChangeAnnotationIdentifier.is(annotation)) {
493
+ id = annotation;
494
+ edit = AnnotatedTextEdit.insert(position, newText, annotation);
495
+ } else {
496
+ this.assertChangeAnnotations(this.changeAnnotations);
497
+ id = this.changeAnnotations.manage(annotation);
498
+ edit = AnnotatedTextEdit.insert(position, newText, id);
499
+ }
500
+ this.edits.push(edit);
501
+ if (id !== void 0) {
502
+ return id;
503
+ }
504
+ };
505
+ TextEditChangeImpl2.prototype.replace = function(range, newText, annotation) {
506
+ var edit;
507
+ var id;
508
+ if (annotation === void 0) {
509
+ edit = TextEdit.replace(range, newText);
510
+ } else if (ChangeAnnotationIdentifier.is(annotation)) {
511
+ id = annotation;
512
+ edit = AnnotatedTextEdit.replace(range, newText, annotation);
513
+ } else {
514
+ this.assertChangeAnnotations(this.changeAnnotations);
515
+ id = this.changeAnnotations.manage(annotation);
516
+ edit = AnnotatedTextEdit.replace(range, newText, id);
517
+ }
518
+ this.edits.push(edit);
519
+ if (id !== void 0) {
520
+ return id;
521
+ }
522
+ };
523
+ TextEditChangeImpl2.prototype.delete = function(range, annotation) {
524
+ var edit;
525
+ var id;
526
+ if (annotation === void 0) {
527
+ edit = TextEdit.del(range);
528
+ } else if (ChangeAnnotationIdentifier.is(annotation)) {
529
+ id = annotation;
530
+ edit = AnnotatedTextEdit.del(range, annotation);
531
+ } else {
532
+ this.assertChangeAnnotations(this.changeAnnotations);
533
+ id = this.changeAnnotations.manage(annotation);
534
+ edit = AnnotatedTextEdit.del(range, id);
535
+ }
536
+ this.edits.push(edit);
537
+ if (id !== void 0) {
538
+ return id;
539
+ }
540
+ };
541
+ TextEditChangeImpl2.prototype.add = function(edit) {
542
+ this.edits.push(edit);
543
+ };
544
+ TextEditChangeImpl2.prototype.all = function() {
545
+ return this.edits;
546
+ };
547
+ TextEditChangeImpl2.prototype.clear = function() {
548
+ this.edits.splice(0, this.edits.length);
549
+ };
550
+ TextEditChangeImpl2.prototype.assertChangeAnnotations = function(value) {
551
+ if (value === void 0) {
552
+ throw new Error("Text edit change is not configured to manage change annotations.");
553
+ }
554
+ };
555
+ return TextEditChangeImpl2;
556
+ }()
557
+ );
558
+ var ChangeAnnotations = (
559
+ /** @class */
560
+ function() {
561
+ function ChangeAnnotations2(annotations) {
562
+ this._annotations = annotations === void 0 ? /* @__PURE__ */ Object.create(null) : annotations;
563
+ this._counter = 0;
564
+ this._size = 0;
565
+ }
566
+ ChangeAnnotations2.prototype.all = function() {
567
+ return this._annotations;
568
+ };
569
+ Object.defineProperty(ChangeAnnotations2.prototype, "size", {
570
+ get: function() {
571
+ return this._size;
572
+ },
573
+ enumerable: false,
574
+ configurable: true
575
+ });
576
+ ChangeAnnotations2.prototype.manage = function(idOrAnnotation, annotation) {
577
+ var id;
578
+ if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
579
+ id = idOrAnnotation;
580
+ } else {
581
+ id = this.nextId();
582
+ annotation = idOrAnnotation;
583
+ }
584
+ if (this._annotations[id] !== void 0) {
585
+ throw new Error("Id " + id + " is already in use.");
586
+ }
587
+ if (annotation === void 0) {
588
+ throw new Error("No annotation provided for id " + id);
589
+ }
590
+ this._annotations[id] = annotation;
591
+ this._size++;
592
+ return id;
593
+ };
594
+ ChangeAnnotations2.prototype.nextId = function() {
595
+ this._counter++;
596
+ return this._counter.toString();
597
+ };
598
+ return ChangeAnnotations2;
599
+ }()
600
+ );
601
+ (
602
+ /** @class */
603
+ (function() {
604
+ function WorkspaceChange2(workspaceEdit) {
605
+ var _this = this;
606
+ this._textEditChanges = /* @__PURE__ */ Object.create(null);
607
+ if (workspaceEdit !== void 0) {
608
+ this._workspaceEdit = workspaceEdit;
609
+ if (workspaceEdit.documentChanges) {
610
+ this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
611
+ workspaceEdit.changeAnnotations = this._changeAnnotations.all();
612
+ workspaceEdit.documentChanges.forEach(function(change) {
613
+ if (TextDocumentEdit.is(change)) {
614
+ var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
615
+ _this._textEditChanges[change.textDocument.uri] = textEditChange;
616
+ }
617
+ });
618
+ } else if (workspaceEdit.changes) {
619
+ Object.keys(workspaceEdit.changes).forEach(function(key) {
620
+ var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
621
+ _this._textEditChanges[key] = textEditChange;
622
+ });
623
+ }
624
+ } else {
625
+ this._workspaceEdit = {};
626
+ }
627
+ }
628
+ Object.defineProperty(WorkspaceChange2.prototype, "edit", {
629
+ /**
630
+ * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
631
+ * use to be returned from a workspace edit operation like rename.
632
+ */
633
+ get: function() {
634
+ this.initDocumentChanges();
635
+ if (this._changeAnnotations !== void 0) {
636
+ if (this._changeAnnotations.size === 0) {
637
+ this._workspaceEdit.changeAnnotations = void 0;
638
+ } else {
639
+ this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
640
+ }
641
+ }
642
+ return this._workspaceEdit;
643
+ },
644
+ enumerable: false,
645
+ configurable: true
646
+ });
647
+ WorkspaceChange2.prototype.getTextEditChange = function(key) {
648
+ if (OptionalVersionedTextDocumentIdentifier.is(key)) {
649
+ this.initDocumentChanges();
650
+ if (this._workspaceEdit.documentChanges === void 0) {
651
+ throw new Error("Workspace edit is not configured for document changes.");
652
+ }
653
+ var textDocument = { uri: key.uri, version: key.version };
654
+ var result = this._textEditChanges[textDocument.uri];
655
+ if (!result) {
656
+ var edits = [];
657
+ var textDocumentEdit = {
658
+ textDocument,
659
+ edits
660
+ };
661
+ this._workspaceEdit.documentChanges.push(textDocumentEdit);
662
+ result = new TextEditChangeImpl(edits, this._changeAnnotations);
663
+ this._textEditChanges[textDocument.uri] = result;
664
+ }
665
+ return result;
666
+ } else {
667
+ this.initChanges();
668
+ if (this._workspaceEdit.changes === void 0) {
669
+ throw new Error("Workspace edit is not configured for normal text edit changes.");
670
+ }
671
+ var result = this._textEditChanges[key];
672
+ if (!result) {
673
+ var edits = [];
674
+ this._workspaceEdit.changes[key] = edits;
675
+ result = new TextEditChangeImpl(edits);
676
+ this._textEditChanges[key] = result;
677
+ }
678
+ return result;
679
+ }
680
+ };
681
+ WorkspaceChange2.prototype.initDocumentChanges = function() {
682
+ if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
683
+ this._changeAnnotations = new ChangeAnnotations();
684
+ this._workspaceEdit.documentChanges = [];
685
+ this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
686
+ }
687
+ };
688
+ WorkspaceChange2.prototype.initChanges = function() {
689
+ if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
690
+ this._workspaceEdit.changes = /* @__PURE__ */ Object.create(null);
691
+ }
692
+ };
693
+ WorkspaceChange2.prototype.createFile = function(uri, optionsOrAnnotation, options) {
694
+ this.initDocumentChanges();
695
+ if (this._workspaceEdit.documentChanges === void 0) {
696
+ throw new Error("Workspace edit is not configured for document changes.");
697
+ }
698
+ var annotation;
699
+ if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
700
+ annotation = optionsOrAnnotation;
701
+ } else {
702
+ options = optionsOrAnnotation;
703
+ }
704
+ var operation;
705
+ var id;
706
+ if (annotation === void 0) {
707
+ operation = CreateFile.create(uri, options);
708
+ } else {
709
+ id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
710
+ operation = CreateFile.create(uri, options, id);
711
+ }
712
+ this._workspaceEdit.documentChanges.push(operation);
713
+ if (id !== void 0) {
714
+ return id;
715
+ }
716
+ };
717
+ WorkspaceChange2.prototype.renameFile = function(oldUri, newUri, optionsOrAnnotation, options) {
718
+ this.initDocumentChanges();
719
+ if (this._workspaceEdit.documentChanges === void 0) {
720
+ throw new Error("Workspace edit is not configured for document changes.");
721
+ }
722
+ var annotation;
723
+ if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
724
+ annotation = optionsOrAnnotation;
725
+ } else {
726
+ options = optionsOrAnnotation;
727
+ }
728
+ var operation;
729
+ var id;
730
+ if (annotation === void 0) {
731
+ operation = RenameFile.create(oldUri, newUri, options);
732
+ } else {
733
+ id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
734
+ operation = RenameFile.create(oldUri, newUri, options, id);
735
+ }
736
+ this._workspaceEdit.documentChanges.push(operation);
737
+ if (id !== void 0) {
738
+ return id;
739
+ }
740
+ };
741
+ WorkspaceChange2.prototype.deleteFile = function(uri, optionsOrAnnotation, options) {
742
+ this.initDocumentChanges();
743
+ if (this._workspaceEdit.documentChanges === void 0) {
744
+ throw new Error("Workspace edit is not configured for document changes.");
745
+ }
746
+ var annotation;
747
+ if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
748
+ annotation = optionsOrAnnotation;
749
+ } else {
750
+ options = optionsOrAnnotation;
751
+ }
752
+ var operation;
753
+ var id;
754
+ if (annotation === void 0) {
755
+ operation = DeleteFile.create(uri, options);
756
+ } else {
757
+ id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
758
+ operation = DeleteFile.create(uri, options, id);
759
+ }
760
+ this._workspaceEdit.documentChanges.push(operation);
761
+ if (id !== void 0) {
762
+ return id;
763
+ }
764
+ };
765
+ return WorkspaceChange2;
766
+ })()
767
+ );
768
+ var TextDocumentIdentifier;
769
+ (function(TextDocumentIdentifier2) {
770
+ function create(uri) {
771
+ return { uri };
772
+ }
773
+ TextDocumentIdentifier2.create = create;
774
+ function is(value) {
775
+ var candidate = value;
776
+ return Is.defined(candidate) && Is.string(candidate.uri);
777
+ }
778
+ TextDocumentIdentifier2.is = is;
779
+ })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
780
+ var VersionedTextDocumentIdentifier;
781
+ (function(VersionedTextDocumentIdentifier2) {
782
+ function create(uri, version) {
783
+ return { uri, version };
784
+ }
785
+ VersionedTextDocumentIdentifier2.create = create;
786
+ function is(value) {
787
+ var candidate = value;
788
+ return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
789
+ }
790
+ VersionedTextDocumentIdentifier2.is = is;
791
+ })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
792
+ var OptionalVersionedTextDocumentIdentifier;
793
+ (function(OptionalVersionedTextDocumentIdentifier2) {
794
+ function create(uri, version) {
795
+ return { uri, version };
796
+ }
797
+ OptionalVersionedTextDocumentIdentifier2.create = create;
798
+ function is(value) {
799
+ var candidate = value;
800
+ return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
801
+ }
802
+ OptionalVersionedTextDocumentIdentifier2.is = is;
803
+ })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
804
+ var TextDocumentItem;
805
+ (function(TextDocumentItem2) {
806
+ function create(uri, languageId, version, text) {
807
+ return { uri, languageId, version, text };
808
+ }
809
+ TextDocumentItem2.create = create;
810
+ function is(value) {
811
+ var candidate = value;
812
+ return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
813
+ }
814
+ TextDocumentItem2.is = is;
815
+ })(TextDocumentItem || (TextDocumentItem = {}));
816
+ var MarkupKind;
817
+ (function(MarkupKind2) {
818
+ MarkupKind2.PlainText = "plaintext";
819
+ MarkupKind2.Markdown = "markdown";
820
+ })(MarkupKind || (MarkupKind = {}));
821
+ (function(MarkupKind2) {
822
+ function is(value) {
823
+ var candidate = value;
824
+ return candidate === MarkupKind2.PlainText || candidate === MarkupKind2.Markdown;
825
+ }
826
+ MarkupKind2.is = is;
827
+ })(MarkupKind || (MarkupKind = {}));
828
+ var MarkupContent;
829
+ (function(MarkupContent2) {
830
+ function is(value) {
831
+ var candidate = value;
832
+ return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
833
+ }
834
+ MarkupContent2.is = is;
835
+ })(MarkupContent || (MarkupContent = {}));
836
+ var CompletionItemKind;
837
+ (function(CompletionItemKind2) {
838
+ CompletionItemKind2.Text = 1;
839
+ CompletionItemKind2.Method = 2;
840
+ CompletionItemKind2.Function = 3;
841
+ CompletionItemKind2.Constructor = 4;
842
+ CompletionItemKind2.Field = 5;
843
+ CompletionItemKind2.Variable = 6;
844
+ CompletionItemKind2.Class = 7;
845
+ CompletionItemKind2.Interface = 8;
846
+ CompletionItemKind2.Module = 9;
847
+ CompletionItemKind2.Property = 10;
848
+ CompletionItemKind2.Unit = 11;
849
+ CompletionItemKind2.Value = 12;
850
+ CompletionItemKind2.Enum = 13;
851
+ CompletionItemKind2.Keyword = 14;
852
+ CompletionItemKind2.Snippet = 15;
853
+ CompletionItemKind2.Color = 16;
854
+ CompletionItemKind2.File = 17;
855
+ CompletionItemKind2.Reference = 18;
856
+ CompletionItemKind2.Folder = 19;
857
+ CompletionItemKind2.EnumMember = 20;
858
+ CompletionItemKind2.Constant = 21;
859
+ CompletionItemKind2.Struct = 22;
860
+ CompletionItemKind2.Event = 23;
861
+ CompletionItemKind2.Operator = 24;
862
+ CompletionItemKind2.TypeParameter = 25;
863
+ })(CompletionItemKind || (CompletionItemKind = {}));
864
+ var InsertTextFormat;
865
+ (function(InsertTextFormat2) {
866
+ InsertTextFormat2.PlainText = 1;
867
+ InsertTextFormat2.Snippet = 2;
868
+ })(InsertTextFormat || (InsertTextFormat = {}));
869
+ var CompletionItemTag;
870
+ (function(CompletionItemTag2) {
871
+ CompletionItemTag2.Deprecated = 1;
872
+ })(CompletionItemTag || (CompletionItemTag = {}));
873
+ var InsertReplaceEdit;
874
+ (function(InsertReplaceEdit2) {
875
+ function create(newText, insert, replace) {
876
+ return { newText, insert, replace };
877
+ }
878
+ InsertReplaceEdit2.create = create;
879
+ function is(value) {
880
+ var candidate = value;
881
+ return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
882
+ }
883
+ InsertReplaceEdit2.is = is;
884
+ })(InsertReplaceEdit || (InsertReplaceEdit = {}));
885
+ var InsertTextMode;
886
+ (function(InsertTextMode2) {
887
+ InsertTextMode2.asIs = 1;
888
+ InsertTextMode2.adjustIndentation = 2;
889
+ })(InsertTextMode || (InsertTextMode = {}));
890
+ var CompletionItem;
891
+ (function(CompletionItem2) {
892
+ function create(label) {
893
+ return { label };
894
+ }
895
+ CompletionItem2.create = create;
896
+ })(CompletionItem || (CompletionItem = {}));
897
+ var CompletionList;
898
+ (function(CompletionList2) {
899
+ function create(items, isIncomplete) {
900
+ return { items: items ? items : [], isIncomplete: !!isIncomplete };
901
+ }
902
+ CompletionList2.create = create;
903
+ })(CompletionList || (CompletionList = {}));
904
+ var MarkedString;
905
+ (function(MarkedString2) {
906
+ function fromPlainText(plainText) {
907
+ return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
908
+ }
909
+ MarkedString2.fromPlainText = fromPlainText;
910
+ function is(value) {
911
+ var candidate = value;
912
+ return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
913
+ }
914
+ MarkedString2.is = is;
915
+ })(MarkedString || (MarkedString = {}));
916
+ var Hover;
917
+ (function(Hover2) {
918
+ function is(value) {
919
+ var candidate = value;
920
+ return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
921
+ }
922
+ Hover2.is = is;
923
+ })(Hover || (Hover = {}));
924
+ var ParameterInformation;
925
+ (function(ParameterInformation2) {
926
+ function create(label, documentation) {
927
+ return documentation ? { label, documentation } : { label };
928
+ }
929
+ ParameterInformation2.create = create;
930
+ })(ParameterInformation || (ParameterInformation = {}));
931
+ var SignatureInformation;
932
+ (function(SignatureInformation2) {
933
+ function create(label, documentation) {
934
+ var parameters = [];
935
+ for (var _i = 2; _i < arguments.length; _i++) {
936
+ parameters[_i - 2] = arguments[_i];
937
+ }
938
+ var result = { label };
939
+ if (Is.defined(documentation)) {
940
+ result.documentation = documentation;
941
+ }
942
+ if (Is.defined(parameters)) {
943
+ result.parameters = parameters;
944
+ } else {
945
+ result.parameters = [];
946
+ }
947
+ return result;
948
+ }
949
+ SignatureInformation2.create = create;
950
+ })(SignatureInformation || (SignatureInformation = {}));
951
+ var DocumentHighlightKind;
952
+ (function(DocumentHighlightKind2) {
953
+ DocumentHighlightKind2.Text = 1;
954
+ DocumentHighlightKind2.Read = 2;
955
+ DocumentHighlightKind2.Write = 3;
956
+ })(DocumentHighlightKind || (DocumentHighlightKind = {}));
957
+ var DocumentHighlight;
958
+ (function(DocumentHighlight2) {
959
+ function create(range, kind) {
960
+ var result = { range };
961
+ if (Is.number(kind)) {
962
+ result.kind = kind;
963
+ }
964
+ return result;
965
+ }
966
+ DocumentHighlight2.create = create;
967
+ })(DocumentHighlight || (DocumentHighlight = {}));
968
+ var SymbolKind;
969
+ (function(SymbolKind2) {
970
+ SymbolKind2.File = 1;
971
+ SymbolKind2.Module = 2;
972
+ SymbolKind2.Namespace = 3;
973
+ SymbolKind2.Package = 4;
974
+ SymbolKind2.Class = 5;
975
+ SymbolKind2.Method = 6;
976
+ SymbolKind2.Property = 7;
977
+ SymbolKind2.Field = 8;
978
+ SymbolKind2.Constructor = 9;
979
+ SymbolKind2.Enum = 10;
980
+ SymbolKind2.Interface = 11;
981
+ SymbolKind2.Function = 12;
982
+ SymbolKind2.Variable = 13;
983
+ SymbolKind2.Constant = 14;
984
+ SymbolKind2.String = 15;
985
+ SymbolKind2.Number = 16;
986
+ SymbolKind2.Boolean = 17;
987
+ SymbolKind2.Array = 18;
988
+ SymbolKind2.Object = 19;
989
+ SymbolKind2.Key = 20;
990
+ SymbolKind2.Null = 21;
991
+ SymbolKind2.EnumMember = 22;
992
+ SymbolKind2.Struct = 23;
993
+ SymbolKind2.Event = 24;
994
+ SymbolKind2.Operator = 25;
995
+ SymbolKind2.TypeParameter = 26;
996
+ })(SymbolKind || (SymbolKind = {}));
997
+ var SymbolTag;
998
+ (function(SymbolTag2) {
999
+ SymbolTag2.Deprecated = 1;
1000
+ })(SymbolTag || (SymbolTag = {}));
1001
+ var SymbolInformation;
1002
+ (function(SymbolInformation2) {
1003
+ function create(name, kind, range, uri, containerName) {
1004
+ var result = {
1005
+ name,
1006
+ kind,
1007
+ location: { uri, range }
1008
+ };
1009
+ if (containerName) {
1010
+ result.containerName = containerName;
1011
+ }
1012
+ return result;
1013
+ }
1014
+ SymbolInformation2.create = create;
1015
+ })(SymbolInformation || (SymbolInformation = {}));
1016
+ var DocumentSymbol;
1017
+ (function(DocumentSymbol2) {
1018
+ function create(name, detail, kind, range, selectionRange, children) {
1019
+ var result = {
1020
+ name,
1021
+ detail,
1022
+ kind,
1023
+ range,
1024
+ selectionRange
1025
+ };
1026
+ if (children !== void 0) {
1027
+ result.children = children;
1028
+ }
1029
+ return result;
1030
+ }
1031
+ DocumentSymbol2.create = create;
1032
+ function is(value) {
1033
+ var candidate = value;
1034
+ return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range.is(candidate.range) && Range.is(candidate.selectionRange) && (candidate.detail === void 0 || Is.string(candidate.detail)) && (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) && (candidate.children === void 0 || Array.isArray(candidate.children)) && (candidate.tags === void 0 || Array.isArray(candidate.tags));
1035
+ }
1036
+ DocumentSymbol2.is = is;
1037
+ })(DocumentSymbol || (DocumentSymbol = {}));
1038
+ var CodeActionKind;
1039
+ (function(CodeActionKind2) {
1040
+ CodeActionKind2.Empty = "";
1041
+ CodeActionKind2.QuickFix = "quickfix";
1042
+ CodeActionKind2.Refactor = "refactor";
1043
+ CodeActionKind2.RefactorExtract = "refactor.extract";
1044
+ CodeActionKind2.RefactorInline = "refactor.inline";
1045
+ CodeActionKind2.RefactorRewrite = "refactor.rewrite";
1046
+ CodeActionKind2.Source = "source";
1047
+ CodeActionKind2.SourceOrganizeImports = "source.organizeImports";
1048
+ CodeActionKind2.SourceFixAll = "source.fixAll";
1049
+ })(CodeActionKind || (CodeActionKind = {}));
1050
+ var CodeActionContext;
1051
+ (function(CodeActionContext2) {
1052
+ function create(diagnostics, only) {
1053
+ var result = { diagnostics };
1054
+ if (only !== void 0 && only !== null) {
1055
+ result.only = only;
1056
+ }
1057
+ return result;
1058
+ }
1059
+ CodeActionContext2.create = create;
1060
+ function is(value) {
1061
+ var candidate = value;
1062
+ return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
1063
+ }
1064
+ CodeActionContext2.is = is;
1065
+ })(CodeActionContext || (CodeActionContext = {}));
1066
+ var CodeAction;
1067
+ (function(CodeAction2) {
1068
+ function create(title, kindOrCommandOrEdit, kind) {
1069
+ var result = { title };
1070
+ var checkKind = true;
1071
+ if (typeof kindOrCommandOrEdit === "string") {
1072
+ checkKind = false;
1073
+ result.kind = kindOrCommandOrEdit;
1074
+ } else if (Command.is(kindOrCommandOrEdit)) {
1075
+ result.command = kindOrCommandOrEdit;
1076
+ } else {
1077
+ result.edit = kindOrCommandOrEdit;
1078
+ }
1079
+ if (checkKind && kind !== void 0) {
1080
+ result.kind = kind;
1081
+ }
1082
+ return result;
1083
+ }
1084
+ CodeAction2.create = create;
1085
+ function is(value) {
1086
+ var candidate = value;
1087
+ return candidate && Is.string(candidate.title) && (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) && (candidate.kind === void 0 || Is.string(candidate.kind)) && (candidate.edit !== void 0 || candidate.command !== void 0) && (candidate.command === void 0 || Command.is(candidate.command)) && (candidate.isPreferred === void 0 || Is.boolean(candidate.isPreferred)) && (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
1088
+ }
1089
+ CodeAction2.is = is;
1090
+ })(CodeAction || (CodeAction = {}));
1091
+ var CodeLens;
1092
+ (function(CodeLens2) {
1093
+ function create(range, data) {
1094
+ var result = { range };
1095
+ if (Is.defined(data)) {
1096
+ result.data = data;
1097
+ }
1098
+ return result;
1099
+ }
1100
+ CodeLens2.create = create;
1101
+ function is(value) {
1102
+ var candidate = value;
1103
+ return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
1104
+ }
1105
+ CodeLens2.is = is;
1106
+ })(CodeLens || (CodeLens = {}));
1107
+ var FormattingOptions;
1108
+ (function(FormattingOptions2) {
1109
+ function create(tabSize, insertSpaces) {
1110
+ return { tabSize, insertSpaces };
1111
+ }
1112
+ FormattingOptions2.create = create;
1113
+ function is(value) {
1114
+ var candidate = value;
1115
+ return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
1116
+ }
1117
+ FormattingOptions2.is = is;
1118
+ })(FormattingOptions || (FormattingOptions = {}));
1119
+ var DocumentLink;
1120
+ (function(DocumentLink2) {
1121
+ function create(range, target, data) {
1122
+ return { range, target, data };
1123
+ }
1124
+ DocumentLink2.create = create;
1125
+ function is(value) {
1126
+ var candidate = value;
1127
+ return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
1128
+ }
1129
+ DocumentLink2.is = is;
1130
+ })(DocumentLink || (DocumentLink = {}));
1131
+ var SelectionRange;
1132
+ (function(SelectionRange2) {
1133
+ function create(range, parent) {
1134
+ return { range, parent };
1135
+ }
1136
+ SelectionRange2.create = create;
1137
+ function is(value) {
1138
+ var candidate = value;
1139
+ return candidate !== void 0 && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
1140
+ }
1141
+ SelectionRange2.is = is;
1142
+ })(SelectionRange || (SelectionRange = {}));
1143
+ var TextDocument;
1144
+ (function(TextDocument2) {
1145
+ function create(uri, languageId, version, content) {
1146
+ return new FullTextDocument(uri, languageId, version, content);
1147
+ }
1148
+ TextDocument2.create = create;
1149
+ function is(value) {
1150
+ var candidate = value;
1151
+ return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount) && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
1152
+ }
1153
+ TextDocument2.is = is;
1154
+ function applyEdits(document, edits) {
1155
+ var text = document.getText();
1156
+ var sortedEdits = mergeSort(edits, function(a, b) {
1157
+ var diff = a.range.start.line - b.range.start.line;
1158
+ if (diff === 0) {
1159
+ return a.range.start.character - b.range.start.character;
1160
+ }
1161
+ return diff;
1162
+ });
1163
+ var lastModifiedOffset = text.length;
1164
+ for (var i = sortedEdits.length - 1; i >= 0; i--) {
1165
+ var e = sortedEdits[i];
1166
+ var startOffset = document.offsetAt(e.range.start);
1167
+ var endOffset = document.offsetAt(e.range.end);
1168
+ if (endOffset <= lastModifiedOffset) {
1169
+ text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
1170
+ } else {
1171
+ throw new Error("Overlapping edit");
1172
+ }
1173
+ lastModifiedOffset = startOffset;
1174
+ }
1175
+ return text;
1176
+ }
1177
+ TextDocument2.applyEdits = applyEdits;
1178
+ function mergeSort(data, compare) {
1179
+ if (data.length <= 1) {
1180
+ return data;
1181
+ }
1182
+ var p = data.length / 2 | 0;
1183
+ var left = data.slice(0, p);
1184
+ var right = data.slice(p);
1185
+ mergeSort(left, compare);
1186
+ mergeSort(right, compare);
1187
+ var leftIdx = 0;
1188
+ var rightIdx = 0;
1189
+ var i = 0;
1190
+ while (leftIdx < left.length && rightIdx < right.length) {
1191
+ var ret = compare(left[leftIdx], right[rightIdx]);
1192
+ if (ret <= 0) {
1193
+ data[i++] = left[leftIdx++];
1194
+ } else {
1195
+ data[i++] = right[rightIdx++];
1196
+ }
1197
+ }
1198
+ while (leftIdx < left.length) {
1199
+ data[i++] = left[leftIdx++];
1200
+ }
1201
+ while (rightIdx < right.length) {
1202
+ data[i++] = right[rightIdx++];
1203
+ }
1204
+ return data;
1205
+ }
1206
+ })(TextDocument || (TextDocument = {}));
1207
+ var FullTextDocument = (
1208
+ /** @class */
1209
+ function() {
1210
+ function FullTextDocument2(uri, languageId, version, content) {
1211
+ this._uri = uri;
1212
+ this._languageId = languageId;
1213
+ this._version = version;
1214
+ this._content = content;
1215
+ this._lineOffsets = void 0;
1216
+ }
1217
+ Object.defineProperty(FullTextDocument2.prototype, "uri", {
1218
+ get: function() {
1219
+ return this._uri;
1220
+ },
1221
+ enumerable: false,
1222
+ configurable: true
1223
+ });
1224
+ Object.defineProperty(FullTextDocument2.prototype, "languageId", {
1225
+ get: function() {
1226
+ return this._languageId;
1227
+ },
1228
+ enumerable: false,
1229
+ configurable: true
1230
+ });
1231
+ Object.defineProperty(FullTextDocument2.prototype, "version", {
1232
+ get: function() {
1233
+ return this._version;
1234
+ },
1235
+ enumerable: false,
1236
+ configurable: true
1237
+ });
1238
+ FullTextDocument2.prototype.getText = function(range) {
1239
+ if (range) {
1240
+ var start = this.offsetAt(range.start);
1241
+ var end = this.offsetAt(range.end);
1242
+ return this._content.substring(start, end);
1243
+ }
1244
+ return this._content;
1245
+ };
1246
+ FullTextDocument2.prototype.update = function(event, version) {
1247
+ this._content = event.text;
1248
+ this._version = version;
1249
+ this._lineOffsets = void 0;
1250
+ };
1251
+ FullTextDocument2.prototype.getLineOffsets = function() {
1252
+ if (this._lineOffsets === void 0) {
1253
+ var lineOffsets = [];
1254
+ var text = this._content;
1255
+ var isLineStart = true;
1256
+ for (var i = 0; i < text.length; i++) {
1257
+ if (isLineStart) {
1258
+ lineOffsets.push(i);
1259
+ isLineStart = false;
1260
+ }
1261
+ var ch = text.charAt(i);
1262
+ isLineStart = ch === "\r" || ch === "\n";
1263
+ if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
1264
+ i++;
1265
+ }
1266
+ }
1267
+ if (isLineStart && text.length > 0) {
1268
+ lineOffsets.push(text.length);
1269
+ }
1270
+ this._lineOffsets = lineOffsets;
1271
+ }
1272
+ return this._lineOffsets;
1273
+ };
1274
+ FullTextDocument2.prototype.positionAt = function(offset) {
1275
+ offset = Math.max(Math.min(offset, this._content.length), 0);
1276
+ var lineOffsets = this.getLineOffsets();
1277
+ var low = 0, high = lineOffsets.length;
1278
+ if (high === 0) {
1279
+ return Position.create(0, offset);
1280
+ }
1281
+ while (low < high) {
1282
+ var mid = Math.floor((low + high) / 2);
1283
+ if (lineOffsets[mid] > offset) {
1284
+ high = mid;
1285
+ } else {
1286
+ low = mid + 1;
1287
+ }
1288
+ }
1289
+ var line = low - 1;
1290
+ return Position.create(line, offset - lineOffsets[line]);
1291
+ };
1292
+ FullTextDocument2.prototype.offsetAt = function(position) {
1293
+ var lineOffsets = this.getLineOffsets();
1294
+ if (position.line >= lineOffsets.length) {
1295
+ return this._content.length;
1296
+ } else if (position.line < 0) {
1297
+ return 0;
1298
+ }
1299
+ var lineOffset = lineOffsets[position.line];
1300
+ var nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
1301
+ return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
1302
+ };
1303
+ Object.defineProperty(FullTextDocument2.prototype, "lineCount", {
1304
+ get: function() {
1305
+ return this.getLineOffsets().length;
1306
+ },
1307
+ enumerable: false,
1308
+ configurable: true
1309
+ });
1310
+ return FullTextDocument2;
1311
+ }()
1312
+ );
1313
+ var Is;
1314
+ (function(Is2) {
1315
+ var toString = Object.prototype.toString;
1316
+ function defined(value) {
1317
+ return typeof value !== "undefined";
1318
+ }
1319
+ Is2.defined = defined;
1320
+ function undefined2(value) {
1321
+ return typeof value === "undefined";
1322
+ }
1323
+ Is2.undefined = undefined2;
1324
+ function boolean(value) {
1325
+ return value === true || value === false;
1326
+ }
1327
+ Is2.boolean = boolean;
1328
+ function string(value) {
1329
+ return toString.call(value) === "[object String]";
1330
+ }
1331
+ Is2.string = string;
1332
+ function number(value) {
1333
+ return toString.call(value) === "[object Number]";
1334
+ }
1335
+ Is2.number = number;
1336
+ function numberRange(value, min, max) {
1337
+ return toString.call(value) === "[object Number]" && min <= value && value <= max;
1338
+ }
1339
+ Is2.numberRange = numberRange;
1340
+ function integer2(value) {
1341
+ return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
1342
+ }
1343
+ Is2.integer = integer2;
1344
+ function uinteger2(value) {
1345
+ return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
1346
+ }
1347
+ Is2.uinteger = uinteger2;
1348
+ function func(value) {
1349
+ return toString.call(value) === "[object Function]";
1350
+ }
1351
+ Is2.func = func;
1352
+ function objectLiteral(value) {
1353
+ return value !== null && typeof value === "object";
1354
+ }
1355
+ Is2.objectLiteral = objectLiteral;
1356
+ function typedArray(value, check) {
1357
+ return Array.isArray(value) && value.every(check);
1358
+ }
1359
+ Is2.typedArray = typedArray;
1360
+ })(Is || (Is = {}));
1361
+
1362
+ // src/language/common/lspLanguageFeatures.ts
1363
+ var DiagnosticsAdapter = class {
1364
+ constructor(_languageId, _worker, configChangeEvent) {
1365
+ this._languageId = _languageId;
1366
+ this._worker = _worker;
1367
+ this._disposables = [];
1368
+ this._listener = /* @__PURE__ */ Object.create(null);
1369
+ const onModelAdd = (model) => {
1370
+ let modeId = model.getLanguageId();
1371
+ if (modeId !== this._languageId) {
1372
+ return;
1373
+ }
1374
+ let handle;
1375
+ this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
1376
+ window.clearTimeout(handle);
1377
+ handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
1378
+ });
1379
+ this._doValidate(model.uri, modeId);
1380
+ };
1381
+ const onModelRemoved = (model) => {
1382
+ monaco_editor_core_exports.editor.setModelMarkers(model, this._languageId, []);
1383
+ let uriStr = model.uri.toString();
1384
+ let listener = this._listener[uriStr];
1385
+ if (listener) {
1386
+ listener.dispose();
1387
+ delete this._listener[uriStr];
1388
+ }
1389
+ };
1390
+ this._disposables.push(monaco_editor_core_exports.editor.onDidCreateModel(onModelAdd));
1391
+ this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel(onModelRemoved));
1392
+ this._disposables.push(
1393
+ monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
1394
+ onModelRemoved(event.model);
1395
+ onModelAdd(event.model);
1396
+ })
1397
+ );
1398
+ this._disposables.push(
1399
+ configChangeEvent((_) => {
1400
+ monaco_editor_core_exports.editor.getModels().forEach((model) => {
1401
+ if (model.getLanguageId() === this._languageId) {
1402
+ onModelRemoved(model);
1403
+ onModelAdd(model);
1404
+ }
1405
+ });
1406
+ })
1407
+ );
1408
+ this._disposables.push({
1409
+ dispose: () => {
1410
+ monaco_editor_core_exports.editor.getModels().forEach(onModelRemoved);
1411
+ for (let key in this._listener) {
1412
+ this._listener[key].dispose();
1413
+ }
1414
+ }
1415
+ });
1416
+ monaco_editor_core_exports.editor.getModels().forEach(onModelAdd);
1417
+ }
1418
+ dispose() {
1419
+ this._disposables.forEach((d) => d && d.dispose());
1420
+ this._disposables.length = 0;
1421
+ }
1422
+ _doValidate(resource, languageId) {
1423
+ this._worker(resource).then((worker) => {
1424
+ return worker.doValidation(resource.toString());
1425
+ }).then((diagnostics) => {
1426
+ const markers = diagnostics.map((d) => toDiagnostics(resource, d));
1427
+ let model = monaco_editor_core_exports.editor.getModel(resource);
1428
+ if (model && model.getLanguageId() === languageId) {
1429
+ monaco_editor_core_exports.editor.setModelMarkers(model, languageId, markers);
1430
+ }
1431
+ }).then(void 0, (err) => {
1432
+ console.error(err);
1433
+ });
1434
+ }
1435
+ };
1436
+ function toSeverity(lsSeverity) {
1437
+ switch (lsSeverity) {
1438
+ case DiagnosticSeverity.Error:
1439
+ return monaco_editor_core_exports.MarkerSeverity.Error;
1440
+ case DiagnosticSeverity.Warning:
1441
+ return monaco_editor_core_exports.MarkerSeverity.Warning;
1442
+ case DiagnosticSeverity.Information:
1443
+ return monaco_editor_core_exports.MarkerSeverity.Info;
1444
+ case DiagnosticSeverity.Hint:
1445
+ return monaco_editor_core_exports.MarkerSeverity.Hint;
1446
+ default:
1447
+ return monaco_editor_core_exports.MarkerSeverity.Info;
1448
+ }
1449
+ }
1450
+ function toDiagnostics(resource, diag) {
1451
+ let code = typeof diag.code === "number" ? String(diag.code) : diag.code;
1452
+ return {
1453
+ severity: toSeverity(diag.severity),
1454
+ startLineNumber: diag.range.start.line + 1,
1455
+ startColumn: diag.range.start.character + 1,
1456
+ endLineNumber: diag.range.end.line + 1,
1457
+ endColumn: diag.range.end.character + 1,
1458
+ message: diag.message,
1459
+ code,
1460
+ source: diag.source
1461
+ };
1462
+ }
1463
+ var CompletionAdapter = class {
1464
+ constructor(_worker, _triggerCharacters) {
1465
+ this._worker = _worker;
1466
+ this._triggerCharacters = _triggerCharacters;
1467
+ }
1468
+ get triggerCharacters() {
1469
+ return this._triggerCharacters;
1470
+ }
1471
+ provideCompletionItems(model, position, context, token) {
1472
+ const resource = model.uri;
1473
+ return this._worker(resource).then((worker) => {
1474
+ return worker.doComplete(resource.toString(), fromPosition(position));
1475
+ }).then((info) => {
1476
+ if (!info) {
1477
+ return;
1478
+ }
1479
+ const wordInfo = model.getWordUntilPosition(position);
1480
+ const wordRange = new monaco_editor_core_exports.Range(
1481
+ position.lineNumber,
1482
+ wordInfo.startColumn,
1483
+ position.lineNumber,
1484
+ wordInfo.endColumn
1485
+ );
1486
+ const items = info.items.map((entry) => {
1487
+ const item = {
1488
+ label: entry.label,
1489
+ insertText: entry.insertText || entry.label,
1490
+ sortText: entry.sortText,
1491
+ filterText: entry.filterText,
1492
+ documentation: entry.documentation,
1493
+ detail: entry.detail,
1494
+ command: toCommand(entry.command),
1495
+ range: wordRange,
1496
+ kind: toCompletionItemKind(entry.kind)
1497
+ };
1498
+ if (entry.textEdit) {
1499
+ if (isInsertReplaceEdit(entry.textEdit)) {
1500
+ item.range = {
1501
+ insert: toRange(entry.textEdit.insert),
1502
+ replace: toRange(entry.textEdit.replace)
1503
+ };
1504
+ } else {
1505
+ item.range = toRange(entry.textEdit.range);
1506
+ }
1507
+ item.insertText = entry.textEdit.newText;
1508
+ }
1509
+ if (entry.additionalTextEdits) {
1510
+ item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
1511
+ }
1512
+ if (entry.insertTextFormat === InsertTextFormat.Snippet) {
1513
+ item.insertTextRules = monaco_editor_core_exports.languages.CompletionItemInsertTextRule.InsertAsSnippet;
1514
+ }
1515
+ return item;
1516
+ });
1517
+ return {
1518
+ isIncomplete: info.isIncomplete,
1519
+ suggestions: items
1520
+ };
1521
+ });
1522
+ }
1523
+ };
1524
+ function fromPosition(position) {
1525
+ if (!position) {
1526
+ return void 0;
1527
+ }
1528
+ return { character: position.column - 1, line: position.lineNumber - 1 };
1529
+ }
1530
+ function fromRange(range) {
1531
+ if (!range) {
1532
+ return void 0;
1533
+ }
1534
+ return {
1535
+ start: {
1536
+ line: range.startLineNumber - 1,
1537
+ character: range.startColumn - 1
1538
+ },
1539
+ end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
1540
+ };
1541
+ }
1542
+ function toRange(range) {
1543
+ if (!range) {
1544
+ return void 0;
1545
+ }
1546
+ return new monaco_editor_core_exports.Range(
1547
+ range.start.line + 1,
1548
+ range.start.character + 1,
1549
+ range.end.line + 1,
1550
+ range.end.character + 1
1551
+ );
1552
+ }
1553
+ function isInsertReplaceEdit(edit) {
1554
+ return typeof edit.insert !== "undefined" && typeof edit.replace !== "undefined";
1555
+ }
1556
+ function toCompletionItemKind(kind) {
1557
+ const mItemKind = monaco_editor_core_exports.languages.CompletionItemKind;
1558
+ switch (kind) {
1559
+ case CompletionItemKind.Text:
1560
+ return mItemKind.Text;
1561
+ case CompletionItemKind.Method:
1562
+ return mItemKind.Method;
1563
+ case CompletionItemKind.Function:
1564
+ return mItemKind.Function;
1565
+ case CompletionItemKind.Constructor:
1566
+ return mItemKind.Constructor;
1567
+ case CompletionItemKind.Field:
1568
+ return mItemKind.Field;
1569
+ case CompletionItemKind.Variable:
1570
+ return mItemKind.Variable;
1571
+ case CompletionItemKind.Class:
1572
+ return mItemKind.Class;
1573
+ case CompletionItemKind.Interface:
1574
+ return mItemKind.Interface;
1575
+ case CompletionItemKind.Module:
1576
+ return mItemKind.Module;
1577
+ case CompletionItemKind.Property:
1578
+ return mItemKind.Property;
1579
+ case CompletionItemKind.Unit:
1580
+ return mItemKind.Unit;
1581
+ case CompletionItemKind.Value:
1582
+ return mItemKind.Value;
1583
+ case CompletionItemKind.Enum:
1584
+ return mItemKind.Enum;
1585
+ case CompletionItemKind.Keyword:
1586
+ return mItemKind.Keyword;
1587
+ case CompletionItemKind.Snippet:
1588
+ return mItemKind.Snippet;
1589
+ case CompletionItemKind.Color:
1590
+ return mItemKind.Color;
1591
+ case CompletionItemKind.File:
1592
+ return mItemKind.File;
1593
+ case CompletionItemKind.Reference:
1594
+ return mItemKind.Reference;
1595
+ }
1596
+ return mItemKind.Property;
1597
+ }
1598
+ function toTextEdit(textEdit) {
1599
+ if (!textEdit) {
1600
+ return void 0;
1601
+ }
1602
+ return {
1603
+ range: toRange(textEdit.range),
1604
+ text: textEdit.newText
1605
+ };
1606
+ }
1607
+ function toCommand(c) {
1608
+ return c && c.command === "editor.action.triggerSuggest" ? { id: c.command, title: c.title, arguments: c.arguments } : void 0;
1609
+ }
1610
+ var HoverAdapter = class {
1611
+ constructor(_worker) {
1612
+ this._worker = _worker;
1613
+ }
1614
+ provideHover(model, position, token) {
1615
+ let resource = model.uri;
1616
+ return this._worker(resource).then((worker) => {
1617
+ return worker.doHover(resource.toString(), fromPosition(position));
1618
+ }).then((info) => {
1619
+ if (!info) {
1620
+ return;
1621
+ }
1622
+ return {
1623
+ range: toRange(info.range),
1624
+ contents: toMarkedStringArray(info.contents)
1625
+ };
1626
+ });
1627
+ }
1628
+ };
1629
+ function isMarkupContent(thing) {
1630
+ return thing && typeof thing === "object" && typeof thing.kind === "string";
1631
+ }
1632
+ function toMarkdownString(entry) {
1633
+ if (typeof entry === "string") {
1634
+ return {
1635
+ value: entry
1636
+ };
1637
+ }
1638
+ if (isMarkupContent(entry)) {
1639
+ if (entry.kind === "plaintext") {
1640
+ return {
1641
+ value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
1642
+ };
1643
+ }
1644
+ return {
1645
+ value: entry.value
1646
+ };
1647
+ }
1648
+ return { value: "```" + entry.language + "\n" + entry.value + "\n```\n" };
1649
+ }
1650
+ function toMarkedStringArray(contents) {
1651
+ if (!contents) {
1652
+ return void 0;
1653
+ }
1654
+ if (Array.isArray(contents)) {
1655
+ return contents.map(toMarkdownString);
1656
+ }
1657
+ return [toMarkdownString(contents)];
1658
+ }
1659
+ var DocumentHighlightAdapter = class {
1660
+ constructor(_worker) {
1661
+ this._worker = _worker;
1662
+ }
1663
+ provideDocumentHighlights(model, position, token) {
1664
+ const resource = model.uri;
1665
+ return this._worker(resource).then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then((entries) => {
1666
+ if (!entries) {
1667
+ return;
1668
+ }
1669
+ return entries.map((entry) => {
1670
+ return {
1671
+ range: toRange(entry.range),
1672
+ kind: toDocumentHighlightKind(entry.kind)
1673
+ };
1674
+ });
1675
+ });
1676
+ }
1677
+ };
1678
+ function toDocumentHighlightKind(kind) {
1679
+ switch (kind) {
1680
+ case DocumentHighlightKind.Read:
1681
+ return monaco_editor_core_exports.languages.DocumentHighlightKind.Read;
1682
+ case DocumentHighlightKind.Write:
1683
+ return monaco_editor_core_exports.languages.DocumentHighlightKind.Write;
1684
+ case DocumentHighlightKind.Text:
1685
+ return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
1686
+ }
1687
+ return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
1688
+ }
1689
+ var DefinitionAdapter = class {
1690
+ constructor(_worker) {
1691
+ this._worker = _worker;
1692
+ }
1693
+ provideDefinition(model, position, token) {
1694
+ const resource = model.uri;
1695
+ return this._worker(resource).then((worker) => {
1696
+ return worker.findDefinition(resource.toString(), fromPosition(position));
1697
+ }).then((definition) => {
1698
+ if (!definition) {
1699
+ return;
1700
+ }
1701
+ return [toLocation(definition)];
1702
+ });
1703
+ }
1704
+ };
1705
+ function toLocation(location) {
1706
+ return {
1707
+ uri: monaco_editor_core_exports.Uri.parse(location.uri),
1708
+ range: toRange(location.range)
1709
+ };
1710
+ }
1711
+ var ReferenceAdapter = class {
1712
+ constructor(_worker) {
1713
+ this._worker = _worker;
1714
+ }
1715
+ provideReferences(model, position, context, token) {
1716
+ const resource = model.uri;
1717
+ return this._worker(resource).then((worker) => {
1718
+ return worker.findReferences(resource.toString(), fromPosition(position));
1719
+ }).then((entries) => {
1720
+ if (!entries) {
1721
+ return;
1722
+ }
1723
+ return entries.map(toLocation);
1724
+ });
1725
+ }
1726
+ };
1727
+ var RenameAdapter = class {
1728
+ constructor(_worker) {
1729
+ this._worker = _worker;
1730
+ }
1731
+ provideRenameEdits(model, position, newName, token) {
1732
+ const resource = model.uri;
1733
+ return this._worker(resource).then((worker) => {
1734
+ return worker.doRename(resource.toString(), fromPosition(position), newName);
1735
+ }).then((edit) => {
1736
+ return toWorkspaceEdit(edit);
1737
+ });
1738
+ }
1739
+ };
1740
+ function toWorkspaceEdit(edit) {
1741
+ if (!edit || !edit.changes) {
1742
+ return void 0;
1743
+ }
1744
+ let resourceEdits = [];
1745
+ for (let uri in edit.changes) {
1746
+ const _uri = monaco_editor_core_exports.Uri.parse(uri);
1747
+ for (let e of edit.changes[uri]) {
1748
+ resourceEdits.push({
1749
+ resource: _uri,
1750
+ versionId: void 0,
1751
+ textEdit: {
1752
+ range: toRange(e.range),
1753
+ text: e.newText
1754
+ }
1755
+ });
1756
+ }
1757
+ }
1758
+ return {
1759
+ edits: resourceEdits
1760
+ };
1761
+ }
1762
+ var DocumentSymbolAdapter = class {
1763
+ constructor(_worker) {
1764
+ this._worker = _worker;
1765
+ }
1766
+ provideDocumentSymbols(model, token) {
1767
+ const resource = model.uri;
1768
+ return this._worker(resource).then((worker) => worker.findDocumentSymbols(resource.toString())).then((items) => {
1769
+ if (!items) {
1770
+ return;
1771
+ }
1772
+ return items.map((item) => {
1773
+ if (isDocumentSymbol(item)) {
1774
+ return toDocumentSymbol(item);
1775
+ }
1776
+ return {
1777
+ name: item.name,
1778
+ detail: "",
1779
+ containerName: item.containerName,
1780
+ kind: toSymbolKind(item.kind),
1781
+ range: toRange(item.location.range),
1782
+ selectionRange: toRange(item.location.range),
1783
+ tags: []
1784
+ };
1785
+ });
1786
+ });
1787
+ }
1788
+ };
1789
+ function isDocumentSymbol(symbol) {
1790
+ return "children" in symbol;
1791
+ }
1792
+ function toDocumentSymbol(symbol) {
1793
+ return {
1794
+ name: symbol.name,
1795
+ detail: symbol.detail ?? "",
1796
+ kind: toSymbolKind(symbol.kind),
1797
+ range: toRange(symbol.range),
1798
+ selectionRange: toRange(symbol.selectionRange),
1799
+ tags: symbol.tags ?? [],
1800
+ children: (symbol.children ?? []).map((item) => toDocumentSymbol(item))
1801
+ };
1802
+ }
1803
+ function toSymbolKind(kind) {
1804
+ let mKind = monaco_editor_core_exports.languages.SymbolKind;
1805
+ switch (kind) {
1806
+ case SymbolKind.File:
1807
+ return mKind.File;
1808
+ case SymbolKind.Module:
1809
+ return mKind.Module;
1810
+ case SymbolKind.Namespace:
1811
+ return mKind.Namespace;
1812
+ case SymbolKind.Package:
1813
+ return mKind.Package;
1814
+ case SymbolKind.Class:
1815
+ return mKind.Class;
1816
+ case SymbolKind.Method:
1817
+ return mKind.Method;
1818
+ case SymbolKind.Property:
1819
+ return mKind.Property;
1820
+ case SymbolKind.Field:
1821
+ return mKind.Field;
1822
+ case SymbolKind.Constructor:
1823
+ return mKind.Constructor;
1824
+ case SymbolKind.Enum:
1825
+ return mKind.Enum;
1826
+ case SymbolKind.Interface:
1827
+ return mKind.Interface;
1828
+ case SymbolKind.Function:
1829
+ return mKind.Function;
1830
+ case SymbolKind.Variable:
1831
+ return mKind.Variable;
1832
+ case SymbolKind.Constant:
1833
+ return mKind.Constant;
1834
+ case SymbolKind.String:
1835
+ return mKind.String;
1836
+ case SymbolKind.Number:
1837
+ return mKind.Number;
1838
+ case SymbolKind.Boolean:
1839
+ return mKind.Boolean;
1840
+ case SymbolKind.Array:
1841
+ return mKind.Array;
1842
+ }
1843
+ return mKind.Function;
1844
+ }
1845
+ var DocumentLinkAdapter = class {
1846
+ constructor(_worker) {
1847
+ this._worker = _worker;
1848
+ }
1849
+ provideLinks(model, token) {
1850
+ const resource = model.uri;
1851
+ return this._worker(resource).then((worker) => worker.findDocumentLinks(resource.toString())).then((items) => {
1852
+ if (!items) {
1853
+ return;
1854
+ }
1855
+ return {
1856
+ links: items.map((item) => ({
1857
+ range: toRange(item.range),
1858
+ url: item.target
1859
+ }))
1860
+ };
1861
+ });
1862
+ }
1863
+ };
1864
+ var DocumentFormattingEditProvider = class {
1865
+ constructor(_worker) {
1866
+ this._worker = _worker;
1867
+ }
1868
+ provideDocumentFormattingEdits(model, options, token) {
1869
+ const resource = model.uri;
1870
+ return this._worker(resource).then((worker) => {
1871
+ return worker.format(resource.toString(), null, fromFormattingOptions(options)).then((edits) => {
1872
+ if (!edits || edits.length === 0) {
1873
+ return;
1874
+ }
1875
+ return edits.map(toTextEdit);
1876
+ });
1877
+ });
1878
+ }
1879
+ };
1880
+ var DocumentRangeFormattingEditProvider = class {
1881
+ constructor(_worker) {
1882
+ this._worker = _worker;
1883
+ this.canFormatMultipleRanges = false;
1884
+ }
1885
+ provideDocumentRangeFormattingEdits(model, range, options, token) {
1886
+ const resource = model.uri;
1887
+ return this._worker(resource).then((worker) => {
1888
+ return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
1889
+ if (!edits || edits.length === 0) {
1890
+ return;
1891
+ }
1892
+ return edits.map(toTextEdit);
1893
+ });
1894
+ });
1895
+ }
1896
+ };
1897
+ function fromFormattingOptions(options) {
1898
+ return {
1899
+ tabSize: options.tabSize,
1900
+ insertSpaces: options.insertSpaces
1901
+ };
1902
+ }
1903
+ var DocumentColorAdapter = class {
1904
+ constructor(_worker) {
1905
+ this._worker = _worker;
1906
+ }
1907
+ provideDocumentColors(model, token) {
1908
+ const resource = model.uri;
1909
+ return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
1910
+ if (!infos) {
1911
+ return;
1912
+ }
1913
+ return infos.map((item) => ({
1914
+ color: item.color,
1915
+ range: toRange(item.range)
1916
+ }));
1917
+ });
1918
+ }
1919
+ provideColorPresentations(model, info, token) {
1920
+ const resource = model.uri;
1921
+ return this._worker(resource).then(
1922
+ (worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))
1923
+ ).then((presentations) => {
1924
+ if (!presentations) {
1925
+ return;
1926
+ }
1927
+ return presentations.map((presentation) => {
1928
+ let item = {
1929
+ label: presentation.label
1930
+ };
1931
+ if (presentation.textEdit) {
1932
+ item.textEdit = toTextEdit(presentation.textEdit);
1933
+ }
1934
+ if (presentation.additionalTextEdits) {
1935
+ item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
1936
+ }
1937
+ return item;
1938
+ });
1939
+ });
1940
+ }
1941
+ };
1942
+ var FoldingRangeAdapter = class {
1943
+ constructor(_worker) {
1944
+ this._worker = _worker;
1945
+ }
1946
+ provideFoldingRanges(model, context, token) {
1947
+ const resource = model.uri;
1948
+ return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
1949
+ if (!ranges) {
1950
+ return;
1951
+ }
1952
+ return ranges.map((range) => {
1953
+ const result = {
1954
+ start: range.startLine + 1,
1955
+ end: range.endLine + 1
1956
+ };
1957
+ if (typeof range.kind !== "undefined") {
1958
+ result.kind = toFoldingRangeKind(range.kind);
1959
+ }
1960
+ return result;
1961
+ });
1962
+ });
1963
+ }
1964
+ };
1965
+ function toFoldingRangeKind(kind) {
1966
+ switch (kind) {
1967
+ case FoldingRangeKind.Comment:
1968
+ return monaco_editor_core_exports.languages.FoldingRangeKind.Comment;
1969
+ case FoldingRangeKind.Imports:
1970
+ return monaco_editor_core_exports.languages.FoldingRangeKind.Imports;
1971
+ case FoldingRangeKind.Region:
1972
+ return monaco_editor_core_exports.languages.FoldingRangeKind.Region;
1973
+ }
1974
+ return void 0;
1975
+ }
1976
+ var SelectionRangeAdapter = class {
1977
+ constructor(_worker) {
1978
+ this._worker = _worker;
1979
+ }
1980
+ provideSelectionRanges(model, positions, token) {
1981
+ const resource = model.uri;
1982
+ return this._worker(resource).then(
1983
+ (worker) => worker.getSelectionRanges(
1984
+ resource.toString(),
1985
+ positions.map(fromPosition)
1986
+ )
1987
+ ).then((selectionRanges) => {
1988
+ if (!selectionRanges) {
1989
+ return;
1990
+ }
1991
+ return selectionRanges.map((selectionRange) => {
1992
+ const result = [];
1993
+ while (selectionRange) {
1994
+ result.push({ range: toRange(selectionRange.range) });
1995
+ selectionRange = selectionRange.parent;
1996
+ }
1997
+ return result;
1998
+ });
1999
+ });
2000
+ }
2001
+ };
2002
+
2003
+ // src/language/html/htmlMode.ts
2004
+ var HTMLCompletionAdapter = class extends CompletionAdapter {
2005
+ constructor(worker) {
2006
+ super(worker, [".", ":", "<", '"', "=", "/"]);
2007
+ }
2008
+ };
2009
+ function setupMode1(defaults) {
2010
+ const client = new WorkerManager(defaults);
2011
+ const worker = (...uris) => {
2012
+ return client.getLanguageServiceWorker(...uris);
2013
+ };
2014
+ let languageId = defaults.languageId;
2015
+ monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker));
2016
+ monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker));
2017
+ monaco_editor_core_exports.languages.registerDocumentHighlightProvider(
2018
+ languageId,
2019
+ new DocumentHighlightAdapter(worker)
2020
+ );
2021
+ monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker));
2022
+ monaco_editor_core_exports.languages.registerFoldingRangeProvider(
2023
+ languageId,
2024
+ new FoldingRangeAdapter(worker)
2025
+ );
2026
+ monaco_editor_core_exports.languages.registerDocumentSymbolProvider(
2027
+ languageId,
2028
+ new DocumentSymbolAdapter(worker)
2029
+ );
2030
+ monaco_editor_core_exports.languages.registerSelectionRangeProvider(
2031
+ languageId,
2032
+ new SelectionRangeAdapter(worker)
2033
+ );
2034
+ monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker));
2035
+ if (languageId === "html") {
2036
+ monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(
2037
+ languageId,
2038
+ new DocumentFormattingEditProvider(worker)
2039
+ );
2040
+ monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(
2041
+ languageId,
2042
+ new DocumentRangeFormattingEditProvider(worker)
2043
+ );
2044
+ }
2045
+ }
2046
+ function setupMode(defaults) {
2047
+ const disposables = [];
2048
+ const providers = [];
2049
+ const client = new WorkerManager(defaults);
2050
+ disposables.push(client);
2051
+ const worker = (...uris) => {
2052
+ return client.getLanguageServiceWorker(...uris);
2053
+ };
2054
+ function registerProviders() {
2055
+ const { languageId, modeConfiguration } = defaults;
2056
+ disposeAll(providers);
2057
+ if (modeConfiguration.completionItems) {
2058
+ providers.push(
2059
+ monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker))
2060
+ );
2061
+ }
2062
+ if (modeConfiguration.hovers) {
2063
+ providers.push(
2064
+ monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker))
2065
+ );
2066
+ }
2067
+ if (modeConfiguration.documentHighlights) {
2068
+ providers.push(
2069
+ monaco_editor_core_exports.languages.registerDocumentHighlightProvider(
2070
+ languageId,
2071
+ new DocumentHighlightAdapter(worker)
2072
+ )
2073
+ );
2074
+ }
2075
+ if (modeConfiguration.links) {
2076
+ providers.push(
2077
+ monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker))
2078
+ );
2079
+ }
2080
+ if (modeConfiguration.documentSymbols) {
2081
+ providers.push(
2082
+ monaco_editor_core_exports.languages.registerDocumentSymbolProvider(
2083
+ languageId,
2084
+ new DocumentSymbolAdapter(worker)
2085
+ )
2086
+ );
2087
+ }
2088
+ if (modeConfiguration.rename) {
2089
+ providers.push(
2090
+ monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker))
2091
+ );
2092
+ }
2093
+ if (modeConfiguration.foldingRanges) {
2094
+ providers.push(
2095
+ monaco_editor_core_exports.languages.registerFoldingRangeProvider(
2096
+ languageId,
2097
+ new FoldingRangeAdapter(worker)
2098
+ )
2099
+ );
2100
+ }
2101
+ if (modeConfiguration.selectionRanges) {
2102
+ providers.push(
2103
+ monaco_editor_core_exports.languages.registerSelectionRangeProvider(
2104
+ languageId,
2105
+ new SelectionRangeAdapter(worker)
2106
+ )
2107
+ );
2108
+ }
2109
+ if (modeConfiguration.documentFormattingEdits) {
2110
+ providers.push(
2111
+ monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(
2112
+ languageId,
2113
+ new DocumentFormattingEditProvider(worker)
2114
+ )
2115
+ );
2116
+ }
2117
+ if (modeConfiguration.documentRangeFormattingEdits) {
2118
+ providers.push(
2119
+ monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(
2120
+ languageId,
2121
+ new DocumentRangeFormattingEditProvider(worker)
2122
+ )
2123
+ );
2124
+ }
2125
+ }
2126
+ registerProviders();
2127
+ disposables.push(asDisposable(providers));
2128
+ return asDisposable(disposables);
2129
+ }
2130
+ function asDisposable(disposables) {
2131
+ return { dispose: () => disposeAll(disposables) };
2132
+ }
2133
+ function disposeAll(disposables) {
2134
+ while (disposables.length) {
2135
+ disposables.pop().dispose();
2136
+ }
2137
+ }
2138
+
2139
+ export { CompletionAdapter, DefinitionAdapter, DiagnosticsAdapter, DocumentColorAdapter, DocumentFormattingEditProvider, DocumentHighlightAdapter, DocumentLinkAdapter, DocumentRangeFormattingEditProvider, DocumentSymbolAdapter, FoldingRangeAdapter, HoverAdapter, ReferenceAdapter, RenameAdapter, SelectionRangeAdapter, WorkerManager, fromPosition, fromRange, setupMode, setupMode1, toRange, toTextEdit };