modern-monaco 0.0.0-beta.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.
@@ -0,0 +1,2858 @@
1
+ // node_modules/.pnpm/@esm.sh+import-map@0.1.1/node_modules/@esm.sh/import-map/dist/import-map.mjs
2
+ function resolve(importMap, specifier, containingFile) {
3
+ const { $baseURL, imports, scopes } = importMap;
4
+ const { origin, pathname } = new URL(containingFile, $baseURL);
5
+ const sameOriginScopes = [];
6
+ for (const scopeName in scopes) {
7
+ const scopeUrl = new URL(scopeName, $baseURL);
8
+ if (scopeUrl.origin === origin) {
9
+ sameOriginScopes.push([scopeUrl.pathname, scopes[scopeName]]);
10
+ }
11
+ }
12
+ sameOriginScopes.sort(([a], [b]) => b.split("/").length - a.split("/").length);
13
+ if (sameOriginScopes.length > 0) {
14
+ for (const [scopePathname, scopeImports] of sameOriginScopes) {
15
+ if (pathname.startsWith(scopePathname)) {
16
+ const url = matchImport(specifier, scopeImports);
17
+ if (url) {
18
+ return [url, true];
19
+ }
20
+ }
21
+ }
22
+ }
23
+ if (origin === new URL($baseURL).origin) {
24
+ const url = matchImport(specifier, imports);
25
+ if (url) {
26
+ return [url, true];
27
+ }
28
+ }
29
+ return [specifier, false];
30
+ }
31
+ function isBlankImportMap(importMap) {
32
+ const { imports, scopes } = importMap;
33
+ if (isObject(imports) && Object.keys(imports).length > 0 || isObject(scopes) && Object.keys(scopes).length > 0) {
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+ function matchImport(specifier, imports) {
39
+ if (specifier in imports) {
40
+ return imports[specifier];
41
+ }
42
+ for (const [k, v] of Object.entries(imports)) {
43
+ if (k.endsWith("/")) {
44
+ if (specifier.startsWith(k)) {
45
+ return v + specifier.slice(k.length);
46
+ }
47
+ } else if (specifier.startsWith(k + "/")) {
48
+ return v + specifier.slice(k.length);
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ function isObject(v) {
54
+ return typeof v === "object" && v !== null && !Array.isArray(v);
55
+ }
56
+
57
+ // src/lsp/typescript/worker.ts
58
+ import ts from "typescript";
59
+
60
+ // node_modules/.pnpm/vscode-languageserver-types@3.17.5/node_modules/vscode-languageserver-types/lib/esm/main.js
61
+ var DocumentUri;
62
+ (function(DocumentUri2) {
63
+ function is(value) {
64
+ return typeof value === "string";
65
+ }
66
+ DocumentUri2.is = is;
67
+ })(DocumentUri || (DocumentUri = {}));
68
+ var URI;
69
+ (function(URI2) {
70
+ function is(value) {
71
+ return typeof value === "string";
72
+ }
73
+ URI2.is = is;
74
+ })(URI || (URI = {}));
75
+ var integer;
76
+ (function(integer2) {
77
+ integer2.MIN_VALUE = -2147483648;
78
+ integer2.MAX_VALUE = 2147483647;
79
+ function is(value) {
80
+ return typeof value === "number" && integer2.MIN_VALUE <= value && value <= integer2.MAX_VALUE;
81
+ }
82
+ integer2.is = is;
83
+ })(integer || (integer = {}));
84
+ var uinteger;
85
+ (function(uinteger2) {
86
+ uinteger2.MIN_VALUE = 0;
87
+ uinteger2.MAX_VALUE = 2147483647;
88
+ function is(value) {
89
+ return typeof value === "number" && uinteger2.MIN_VALUE <= value && value <= uinteger2.MAX_VALUE;
90
+ }
91
+ uinteger2.is = is;
92
+ })(uinteger || (uinteger = {}));
93
+ var Position;
94
+ (function(Position2) {
95
+ function create(line, character) {
96
+ if (line === Number.MAX_VALUE) {
97
+ line = uinteger.MAX_VALUE;
98
+ }
99
+ if (character === Number.MAX_VALUE) {
100
+ character = uinteger.MAX_VALUE;
101
+ }
102
+ return { line, character };
103
+ }
104
+ Position2.create = create;
105
+ function is(value) {
106
+ let candidate = value;
107
+ return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
108
+ }
109
+ Position2.is = is;
110
+ })(Position || (Position = {}));
111
+ var Range;
112
+ (function(Range2) {
113
+ function create(one, two, three, four) {
114
+ if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
115
+ return { start: Position.create(one, two), end: Position.create(three, four) };
116
+ } else if (Position.is(one) && Position.is(two)) {
117
+ return { start: one, end: two };
118
+ } else {
119
+ throw new Error(`Range#create called with invalid arguments[${one}, ${two}, ${three}, ${four}]`);
120
+ }
121
+ }
122
+ Range2.create = create;
123
+ function is(value) {
124
+ let candidate = value;
125
+ return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
126
+ }
127
+ Range2.is = is;
128
+ })(Range || (Range = {}));
129
+ var Location;
130
+ (function(Location2) {
131
+ function create(uri, range) {
132
+ return { uri, range };
133
+ }
134
+ Location2.create = create;
135
+ function is(value) {
136
+ let candidate = value;
137
+ return Is.objectLiteral(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
138
+ }
139
+ Location2.is = is;
140
+ })(Location || (Location = {}));
141
+ var LocationLink;
142
+ (function(LocationLink2) {
143
+ function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
144
+ return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
145
+ }
146
+ LocationLink2.create = create;
147
+ function is(value) {
148
+ let candidate = value;
149
+ return Is.objectLiteral(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && Range.is(candidate.targetSelectionRange) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
150
+ }
151
+ LocationLink2.is = is;
152
+ })(LocationLink || (LocationLink = {}));
153
+ var Color;
154
+ (function(Color2) {
155
+ function create(red, green, blue, alpha) {
156
+ return {
157
+ red,
158
+ green,
159
+ blue,
160
+ alpha
161
+ };
162
+ }
163
+ Color2.create = create;
164
+ function is(value) {
165
+ const candidate = value;
166
+ return Is.objectLiteral(candidate) && Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1);
167
+ }
168
+ Color2.is = is;
169
+ })(Color || (Color = {}));
170
+ var ColorInformation;
171
+ (function(ColorInformation2) {
172
+ function create(range, color) {
173
+ return {
174
+ range,
175
+ color
176
+ };
177
+ }
178
+ ColorInformation2.create = create;
179
+ function is(value) {
180
+ const candidate = value;
181
+ return Is.objectLiteral(candidate) && Range.is(candidate.range) && Color.is(candidate.color);
182
+ }
183
+ ColorInformation2.is = is;
184
+ })(ColorInformation || (ColorInformation = {}));
185
+ var ColorPresentation;
186
+ (function(ColorPresentation2) {
187
+ function create(label, textEdit, additionalTextEdits) {
188
+ return {
189
+ label,
190
+ textEdit,
191
+ additionalTextEdits
192
+ };
193
+ }
194
+ ColorPresentation2.create = create;
195
+ function is(value) {
196
+ const candidate = value;
197
+ return Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
198
+ }
199
+ ColorPresentation2.is = is;
200
+ })(ColorPresentation || (ColorPresentation = {}));
201
+ var FoldingRangeKind;
202
+ (function(FoldingRangeKind2) {
203
+ FoldingRangeKind2.Comment = "comment";
204
+ FoldingRangeKind2.Imports = "imports";
205
+ FoldingRangeKind2.Region = "region";
206
+ })(FoldingRangeKind || (FoldingRangeKind = {}));
207
+ var FoldingRange;
208
+ (function(FoldingRange2) {
209
+ function create(startLine, endLine, startCharacter, endCharacter, kind, collapsedText) {
210
+ const result = {
211
+ startLine,
212
+ endLine
213
+ };
214
+ if (Is.defined(startCharacter)) {
215
+ result.startCharacter = startCharacter;
216
+ }
217
+ if (Is.defined(endCharacter)) {
218
+ result.endCharacter = endCharacter;
219
+ }
220
+ if (Is.defined(kind)) {
221
+ result.kind = kind;
222
+ }
223
+ if (Is.defined(collapsedText)) {
224
+ result.collapsedText = collapsedText;
225
+ }
226
+ return result;
227
+ }
228
+ FoldingRange2.create = create;
229
+ function is(value) {
230
+ const candidate = value;
231
+ return Is.objectLiteral(candidate) && 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));
232
+ }
233
+ FoldingRange2.is = is;
234
+ })(FoldingRange || (FoldingRange = {}));
235
+ var DiagnosticRelatedInformation;
236
+ (function(DiagnosticRelatedInformation2) {
237
+ function create(location, message) {
238
+ return {
239
+ location,
240
+ message
241
+ };
242
+ }
243
+ DiagnosticRelatedInformation2.create = create;
244
+ function is(value) {
245
+ let candidate = value;
246
+ return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
247
+ }
248
+ DiagnosticRelatedInformation2.is = is;
249
+ })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
250
+ var DiagnosticSeverity;
251
+ (function(DiagnosticSeverity2) {
252
+ DiagnosticSeverity2.Error = 1;
253
+ DiagnosticSeverity2.Warning = 2;
254
+ DiagnosticSeverity2.Information = 3;
255
+ DiagnosticSeverity2.Hint = 4;
256
+ })(DiagnosticSeverity || (DiagnosticSeverity = {}));
257
+ var DiagnosticTag;
258
+ (function(DiagnosticTag2) {
259
+ DiagnosticTag2.Unnecessary = 1;
260
+ DiagnosticTag2.Deprecated = 2;
261
+ })(DiagnosticTag || (DiagnosticTag = {}));
262
+ var CodeDescription;
263
+ (function(CodeDescription2) {
264
+ function is(value) {
265
+ const candidate = value;
266
+ return Is.objectLiteral(candidate) && Is.string(candidate.href);
267
+ }
268
+ CodeDescription2.is = is;
269
+ })(CodeDescription || (CodeDescription = {}));
270
+ var Diagnostic;
271
+ (function(Diagnostic2) {
272
+ function create(range, message, severity, code, source, relatedInformation) {
273
+ let result = { range, message };
274
+ if (Is.defined(severity)) {
275
+ result.severity = severity;
276
+ }
277
+ if (Is.defined(code)) {
278
+ result.code = code;
279
+ }
280
+ if (Is.defined(source)) {
281
+ result.source = source;
282
+ }
283
+ if (Is.defined(relatedInformation)) {
284
+ result.relatedInformation = relatedInformation;
285
+ }
286
+ return result;
287
+ }
288
+ Diagnostic2.create = create;
289
+ function is(value) {
290
+ var _a;
291
+ let candidate = value;
292
+ 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));
293
+ }
294
+ Diagnostic2.is = is;
295
+ })(Diagnostic || (Diagnostic = {}));
296
+ var Command;
297
+ (function(Command2) {
298
+ function create(title, command, ...args) {
299
+ let result = { title, command };
300
+ if (Is.defined(args) && args.length > 0) {
301
+ result.arguments = args;
302
+ }
303
+ return result;
304
+ }
305
+ Command2.create = create;
306
+ function is(value) {
307
+ let candidate = value;
308
+ return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
309
+ }
310
+ Command2.is = is;
311
+ })(Command || (Command = {}));
312
+ var TextEdit;
313
+ (function(TextEdit2) {
314
+ function replace(range, newText) {
315
+ return { range, newText };
316
+ }
317
+ TextEdit2.replace = replace;
318
+ function insert(position, newText) {
319
+ return { range: { start: position, end: position }, newText };
320
+ }
321
+ TextEdit2.insert = insert;
322
+ function del(range) {
323
+ return { range, newText: "" };
324
+ }
325
+ TextEdit2.del = del;
326
+ function is(value) {
327
+ const candidate = value;
328
+ return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
329
+ }
330
+ TextEdit2.is = is;
331
+ })(TextEdit || (TextEdit = {}));
332
+ var ChangeAnnotation;
333
+ (function(ChangeAnnotation2) {
334
+ function create(label, needsConfirmation, description) {
335
+ const result = { label };
336
+ if (needsConfirmation !== void 0) {
337
+ result.needsConfirmation = needsConfirmation;
338
+ }
339
+ if (description !== void 0) {
340
+ result.description = description;
341
+ }
342
+ return result;
343
+ }
344
+ ChangeAnnotation2.create = create;
345
+ function is(value) {
346
+ const candidate = value;
347
+ return Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === void 0) && (Is.string(candidate.description) || candidate.description === void 0);
348
+ }
349
+ ChangeAnnotation2.is = is;
350
+ })(ChangeAnnotation || (ChangeAnnotation = {}));
351
+ var ChangeAnnotationIdentifier;
352
+ (function(ChangeAnnotationIdentifier2) {
353
+ function is(value) {
354
+ const candidate = value;
355
+ return Is.string(candidate);
356
+ }
357
+ ChangeAnnotationIdentifier2.is = is;
358
+ })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
359
+ var AnnotatedTextEdit;
360
+ (function(AnnotatedTextEdit2) {
361
+ function replace(range, newText, annotation) {
362
+ return { range, newText, annotationId: annotation };
363
+ }
364
+ AnnotatedTextEdit2.replace = replace;
365
+ function insert(position, newText, annotation) {
366
+ return { range: { start: position, end: position }, newText, annotationId: annotation };
367
+ }
368
+ AnnotatedTextEdit2.insert = insert;
369
+ function del(range, annotation) {
370
+ return { range, newText: "", annotationId: annotation };
371
+ }
372
+ AnnotatedTextEdit2.del = del;
373
+ function is(value) {
374
+ const candidate = value;
375
+ return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
376
+ }
377
+ AnnotatedTextEdit2.is = is;
378
+ })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
379
+ var TextDocumentEdit;
380
+ (function(TextDocumentEdit2) {
381
+ function create(textDocument, edits) {
382
+ return { textDocument, edits };
383
+ }
384
+ TextDocumentEdit2.create = create;
385
+ function is(value) {
386
+ let candidate = value;
387
+ return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
388
+ }
389
+ TextDocumentEdit2.is = is;
390
+ })(TextDocumentEdit || (TextDocumentEdit = {}));
391
+ var CreateFile;
392
+ (function(CreateFile2) {
393
+ function create(uri, options, annotation) {
394
+ let result = {
395
+ kind: "create",
396
+ uri
397
+ };
398
+ if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
399
+ result.options = options;
400
+ }
401
+ if (annotation !== void 0) {
402
+ result.annotationId = annotation;
403
+ }
404
+ return result;
405
+ }
406
+ CreateFile2.create = create;
407
+ function is(value) {
408
+ let candidate = value;
409
+ 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));
410
+ }
411
+ CreateFile2.is = is;
412
+ })(CreateFile || (CreateFile = {}));
413
+ var RenameFile;
414
+ (function(RenameFile2) {
415
+ function create(oldUri, newUri, options, annotation) {
416
+ let result = {
417
+ kind: "rename",
418
+ oldUri,
419
+ newUri
420
+ };
421
+ if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
422
+ result.options = options;
423
+ }
424
+ if (annotation !== void 0) {
425
+ result.annotationId = annotation;
426
+ }
427
+ return result;
428
+ }
429
+ RenameFile2.create = create;
430
+ function is(value) {
431
+ let candidate = value;
432
+ 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));
433
+ }
434
+ RenameFile2.is = is;
435
+ })(RenameFile || (RenameFile = {}));
436
+ var DeleteFile;
437
+ (function(DeleteFile2) {
438
+ function create(uri, options, annotation) {
439
+ let result = {
440
+ kind: "delete",
441
+ uri
442
+ };
443
+ if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
444
+ result.options = options;
445
+ }
446
+ if (annotation !== void 0) {
447
+ result.annotationId = annotation;
448
+ }
449
+ return result;
450
+ }
451
+ DeleteFile2.create = create;
452
+ function is(value) {
453
+ let candidate = value;
454
+ 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));
455
+ }
456
+ DeleteFile2.is = is;
457
+ })(DeleteFile || (DeleteFile = {}));
458
+ var WorkspaceEdit;
459
+ (function(WorkspaceEdit2) {
460
+ function is(value) {
461
+ let candidate = value;
462
+ return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every((change) => {
463
+ if (Is.string(change.kind)) {
464
+ return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
465
+ } else {
466
+ return TextDocumentEdit.is(change);
467
+ }
468
+ }));
469
+ }
470
+ WorkspaceEdit2.is = is;
471
+ })(WorkspaceEdit || (WorkspaceEdit = {}));
472
+ var TextDocumentIdentifier;
473
+ (function(TextDocumentIdentifier2) {
474
+ function create(uri) {
475
+ return { uri };
476
+ }
477
+ TextDocumentIdentifier2.create = create;
478
+ function is(value) {
479
+ let candidate = value;
480
+ return Is.defined(candidate) && Is.string(candidate.uri);
481
+ }
482
+ TextDocumentIdentifier2.is = is;
483
+ })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
484
+ var VersionedTextDocumentIdentifier;
485
+ (function(VersionedTextDocumentIdentifier2) {
486
+ function create(uri, version) {
487
+ return { uri, version };
488
+ }
489
+ VersionedTextDocumentIdentifier2.create = create;
490
+ function is(value) {
491
+ let candidate = value;
492
+ return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
493
+ }
494
+ VersionedTextDocumentIdentifier2.is = is;
495
+ })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
496
+ var OptionalVersionedTextDocumentIdentifier;
497
+ (function(OptionalVersionedTextDocumentIdentifier2) {
498
+ function create(uri, version) {
499
+ return { uri, version };
500
+ }
501
+ OptionalVersionedTextDocumentIdentifier2.create = create;
502
+ function is(value) {
503
+ let candidate = value;
504
+ return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
505
+ }
506
+ OptionalVersionedTextDocumentIdentifier2.is = is;
507
+ })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
508
+ var TextDocumentItem;
509
+ (function(TextDocumentItem2) {
510
+ function create(uri, languageId, version, text) {
511
+ return { uri, languageId, version, text };
512
+ }
513
+ TextDocumentItem2.create = create;
514
+ function is(value) {
515
+ let candidate = value;
516
+ return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
517
+ }
518
+ TextDocumentItem2.is = is;
519
+ })(TextDocumentItem || (TextDocumentItem = {}));
520
+ var MarkupKind;
521
+ (function(MarkupKind2) {
522
+ MarkupKind2.PlainText = "plaintext";
523
+ MarkupKind2.Markdown = "markdown";
524
+ function is(value) {
525
+ const candidate = value;
526
+ return candidate === MarkupKind2.PlainText || candidate === MarkupKind2.Markdown;
527
+ }
528
+ MarkupKind2.is = is;
529
+ })(MarkupKind || (MarkupKind = {}));
530
+ var MarkupContent;
531
+ (function(MarkupContent2) {
532
+ function is(value) {
533
+ const candidate = value;
534
+ return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
535
+ }
536
+ MarkupContent2.is = is;
537
+ })(MarkupContent || (MarkupContent = {}));
538
+ var CompletionItemKind;
539
+ (function(CompletionItemKind2) {
540
+ CompletionItemKind2.Text = 1;
541
+ CompletionItemKind2.Method = 2;
542
+ CompletionItemKind2.Function = 3;
543
+ CompletionItemKind2.Constructor = 4;
544
+ CompletionItemKind2.Field = 5;
545
+ CompletionItemKind2.Variable = 6;
546
+ CompletionItemKind2.Class = 7;
547
+ CompletionItemKind2.Interface = 8;
548
+ CompletionItemKind2.Module = 9;
549
+ CompletionItemKind2.Property = 10;
550
+ CompletionItemKind2.Unit = 11;
551
+ CompletionItemKind2.Value = 12;
552
+ CompletionItemKind2.Enum = 13;
553
+ CompletionItemKind2.Keyword = 14;
554
+ CompletionItemKind2.Snippet = 15;
555
+ CompletionItemKind2.Color = 16;
556
+ CompletionItemKind2.File = 17;
557
+ CompletionItemKind2.Reference = 18;
558
+ CompletionItemKind2.Folder = 19;
559
+ CompletionItemKind2.EnumMember = 20;
560
+ CompletionItemKind2.Constant = 21;
561
+ CompletionItemKind2.Struct = 22;
562
+ CompletionItemKind2.Event = 23;
563
+ CompletionItemKind2.Operator = 24;
564
+ CompletionItemKind2.TypeParameter = 25;
565
+ })(CompletionItemKind || (CompletionItemKind = {}));
566
+ var InsertTextFormat;
567
+ (function(InsertTextFormat2) {
568
+ InsertTextFormat2.PlainText = 1;
569
+ InsertTextFormat2.Snippet = 2;
570
+ })(InsertTextFormat || (InsertTextFormat = {}));
571
+ var CompletionItemTag;
572
+ (function(CompletionItemTag2) {
573
+ CompletionItemTag2.Deprecated = 1;
574
+ })(CompletionItemTag || (CompletionItemTag = {}));
575
+ var InsertReplaceEdit;
576
+ (function(InsertReplaceEdit2) {
577
+ function create(newText, insert, replace) {
578
+ return { newText, insert, replace };
579
+ }
580
+ InsertReplaceEdit2.create = create;
581
+ function is(value) {
582
+ const candidate = value;
583
+ return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
584
+ }
585
+ InsertReplaceEdit2.is = is;
586
+ })(InsertReplaceEdit || (InsertReplaceEdit = {}));
587
+ var InsertTextMode;
588
+ (function(InsertTextMode2) {
589
+ InsertTextMode2.asIs = 1;
590
+ InsertTextMode2.adjustIndentation = 2;
591
+ })(InsertTextMode || (InsertTextMode = {}));
592
+ var CompletionItemLabelDetails;
593
+ (function(CompletionItemLabelDetails2) {
594
+ function is(value) {
595
+ const candidate = value;
596
+ return candidate && (Is.string(candidate.detail) || candidate.detail === void 0) && (Is.string(candidate.description) || candidate.description === void 0);
597
+ }
598
+ CompletionItemLabelDetails2.is = is;
599
+ })(CompletionItemLabelDetails || (CompletionItemLabelDetails = {}));
600
+ var CompletionItem;
601
+ (function(CompletionItem2) {
602
+ function create(label) {
603
+ return { label };
604
+ }
605
+ CompletionItem2.create = create;
606
+ })(CompletionItem || (CompletionItem = {}));
607
+ var CompletionList;
608
+ (function(CompletionList2) {
609
+ function create(items, isIncomplete) {
610
+ return { items: items ? items : [], isIncomplete: !!isIncomplete };
611
+ }
612
+ CompletionList2.create = create;
613
+ })(CompletionList || (CompletionList = {}));
614
+ var MarkedString;
615
+ (function(MarkedString2) {
616
+ function fromPlainText(plainText) {
617
+ return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
618
+ }
619
+ MarkedString2.fromPlainText = fromPlainText;
620
+ function is(value) {
621
+ const candidate = value;
622
+ return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
623
+ }
624
+ MarkedString2.is = is;
625
+ })(MarkedString || (MarkedString = {}));
626
+ var Hover;
627
+ (function(Hover2) {
628
+ function is(value) {
629
+ let candidate = value;
630
+ 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));
631
+ }
632
+ Hover2.is = is;
633
+ })(Hover || (Hover = {}));
634
+ var ParameterInformation;
635
+ (function(ParameterInformation2) {
636
+ function create(label, documentation) {
637
+ return documentation ? { label, documentation } : { label };
638
+ }
639
+ ParameterInformation2.create = create;
640
+ })(ParameterInformation || (ParameterInformation = {}));
641
+ var SignatureInformation;
642
+ (function(SignatureInformation2) {
643
+ function create(label, documentation, ...parameters) {
644
+ let result = { label };
645
+ if (Is.defined(documentation)) {
646
+ result.documentation = documentation;
647
+ }
648
+ if (Is.defined(parameters)) {
649
+ result.parameters = parameters;
650
+ } else {
651
+ result.parameters = [];
652
+ }
653
+ return result;
654
+ }
655
+ SignatureInformation2.create = create;
656
+ })(SignatureInformation || (SignatureInformation = {}));
657
+ var DocumentHighlightKind;
658
+ (function(DocumentHighlightKind2) {
659
+ DocumentHighlightKind2.Text = 1;
660
+ DocumentHighlightKind2.Read = 2;
661
+ DocumentHighlightKind2.Write = 3;
662
+ })(DocumentHighlightKind || (DocumentHighlightKind = {}));
663
+ var DocumentHighlight;
664
+ (function(DocumentHighlight2) {
665
+ function create(range, kind) {
666
+ let result = { range };
667
+ if (Is.number(kind)) {
668
+ result.kind = kind;
669
+ }
670
+ return result;
671
+ }
672
+ DocumentHighlight2.create = create;
673
+ })(DocumentHighlight || (DocumentHighlight = {}));
674
+ var SymbolKind;
675
+ (function(SymbolKind2) {
676
+ SymbolKind2.File = 1;
677
+ SymbolKind2.Module = 2;
678
+ SymbolKind2.Namespace = 3;
679
+ SymbolKind2.Package = 4;
680
+ SymbolKind2.Class = 5;
681
+ SymbolKind2.Method = 6;
682
+ SymbolKind2.Property = 7;
683
+ SymbolKind2.Field = 8;
684
+ SymbolKind2.Constructor = 9;
685
+ SymbolKind2.Enum = 10;
686
+ SymbolKind2.Interface = 11;
687
+ SymbolKind2.Function = 12;
688
+ SymbolKind2.Variable = 13;
689
+ SymbolKind2.Constant = 14;
690
+ SymbolKind2.String = 15;
691
+ SymbolKind2.Number = 16;
692
+ SymbolKind2.Boolean = 17;
693
+ SymbolKind2.Array = 18;
694
+ SymbolKind2.Object = 19;
695
+ SymbolKind2.Key = 20;
696
+ SymbolKind2.Null = 21;
697
+ SymbolKind2.EnumMember = 22;
698
+ SymbolKind2.Struct = 23;
699
+ SymbolKind2.Event = 24;
700
+ SymbolKind2.Operator = 25;
701
+ SymbolKind2.TypeParameter = 26;
702
+ })(SymbolKind || (SymbolKind = {}));
703
+ var SymbolTag;
704
+ (function(SymbolTag2) {
705
+ SymbolTag2.Deprecated = 1;
706
+ })(SymbolTag || (SymbolTag = {}));
707
+ var SymbolInformation;
708
+ (function(SymbolInformation2) {
709
+ function create(name, kind, range, uri, containerName) {
710
+ let result = {
711
+ name,
712
+ kind,
713
+ location: { uri, range }
714
+ };
715
+ if (containerName) {
716
+ result.containerName = containerName;
717
+ }
718
+ return result;
719
+ }
720
+ SymbolInformation2.create = create;
721
+ })(SymbolInformation || (SymbolInformation = {}));
722
+ var WorkspaceSymbol;
723
+ (function(WorkspaceSymbol2) {
724
+ function create(name, kind, uri, range) {
725
+ return range !== void 0 ? { name, kind, location: { uri, range } } : { name, kind, location: { uri } };
726
+ }
727
+ WorkspaceSymbol2.create = create;
728
+ })(WorkspaceSymbol || (WorkspaceSymbol = {}));
729
+ var DocumentSymbol;
730
+ (function(DocumentSymbol2) {
731
+ function create(name, detail, kind, range, selectionRange, children) {
732
+ let result = {
733
+ name,
734
+ detail,
735
+ kind,
736
+ range,
737
+ selectionRange
738
+ };
739
+ if (children !== void 0) {
740
+ result.children = children;
741
+ }
742
+ return result;
743
+ }
744
+ DocumentSymbol2.create = create;
745
+ function is(value) {
746
+ let candidate = value;
747
+ 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));
748
+ }
749
+ DocumentSymbol2.is = is;
750
+ })(DocumentSymbol || (DocumentSymbol = {}));
751
+ var CodeActionKind;
752
+ (function(CodeActionKind2) {
753
+ CodeActionKind2.Empty = "";
754
+ CodeActionKind2.QuickFix = "quickfix";
755
+ CodeActionKind2.Refactor = "refactor";
756
+ CodeActionKind2.RefactorExtract = "refactor.extract";
757
+ CodeActionKind2.RefactorInline = "refactor.inline";
758
+ CodeActionKind2.RefactorRewrite = "refactor.rewrite";
759
+ CodeActionKind2.Source = "source";
760
+ CodeActionKind2.SourceOrganizeImports = "source.organizeImports";
761
+ CodeActionKind2.SourceFixAll = "source.fixAll";
762
+ })(CodeActionKind || (CodeActionKind = {}));
763
+ var CodeActionTriggerKind;
764
+ (function(CodeActionTriggerKind2) {
765
+ CodeActionTriggerKind2.Invoked = 1;
766
+ CodeActionTriggerKind2.Automatic = 2;
767
+ })(CodeActionTriggerKind || (CodeActionTriggerKind = {}));
768
+ var CodeActionContext;
769
+ (function(CodeActionContext2) {
770
+ function create(diagnostics, only, triggerKind) {
771
+ let result = { diagnostics };
772
+ if (only !== void 0 && only !== null) {
773
+ result.only = only;
774
+ }
775
+ if (triggerKind !== void 0 && triggerKind !== null) {
776
+ result.triggerKind = triggerKind;
777
+ }
778
+ return result;
779
+ }
780
+ CodeActionContext2.create = create;
781
+ function is(value) {
782
+ let candidate = value;
783
+ return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string)) && (candidate.triggerKind === void 0 || candidate.triggerKind === CodeActionTriggerKind.Invoked || candidate.triggerKind === CodeActionTriggerKind.Automatic);
784
+ }
785
+ CodeActionContext2.is = is;
786
+ })(CodeActionContext || (CodeActionContext = {}));
787
+ var CodeAction;
788
+ (function(CodeAction2) {
789
+ function create(title, kindOrCommandOrEdit, kind) {
790
+ let result = { title };
791
+ let checkKind = true;
792
+ if (typeof kindOrCommandOrEdit === "string") {
793
+ checkKind = false;
794
+ result.kind = kindOrCommandOrEdit;
795
+ } else if (Command.is(kindOrCommandOrEdit)) {
796
+ result.command = kindOrCommandOrEdit;
797
+ } else {
798
+ result.edit = kindOrCommandOrEdit;
799
+ }
800
+ if (checkKind && kind !== void 0) {
801
+ result.kind = kind;
802
+ }
803
+ return result;
804
+ }
805
+ CodeAction2.create = create;
806
+ function is(value) {
807
+ let candidate = value;
808
+ 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));
809
+ }
810
+ CodeAction2.is = is;
811
+ })(CodeAction || (CodeAction = {}));
812
+ var CodeLens;
813
+ (function(CodeLens2) {
814
+ function create(range, data) {
815
+ let result = { range };
816
+ if (Is.defined(data)) {
817
+ result.data = data;
818
+ }
819
+ return result;
820
+ }
821
+ CodeLens2.create = create;
822
+ function is(value) {
823
+ let candidate = value;
824
+ return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
825
+ }
826
+ CodeLens2.is = is;
827
+ })(CodeLens || (CodeLens = {}));
828
+ var FormattingOptions;
829
+ (function(FormattingOptions2) {
830
+ function create(tabSize, insertSpaces) {
831
+ return { tabSize, insertSpaces };
832
+ }
833
+ FormattingOptions2.create = create;
834
+ function is(value) {
835
+ let candidate = value;
836
+ return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
837
+ }
838
+ FormattingOptions2.is = is;
839
+ })(FormattingOptions || (FormattingOptions = {}));
840
+ var DocumentLink;
841
+ (function(DocumentLink2) {
842
+ function create(range, target, data) {
843
+ return { range, target, data };
844
+ }
845
+ DocumentLink2.create = create;
846
+ function is(value) {
847
+ let candidate = value;
848
+ return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
849
+ }
850
+ DocumentLink2.is = is;
851
+ })(DocumentLink || (DocumentLink = {}));
852
+ var SelectionRange;
853
+ (function(SelectionRange2) {
854
+ function create(range, parent) {
855
+ return { range, parent };
856
+ }
857
+ SelectionRange2.create = create;
858
+ function is(value) {
859
+ let candidate = value;
860
+ return Is.objectLiteral(candidate) && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
861
+ }
862
+ SelectionRange2.is = is;
863
+ })(SelectionRange || (SelectionRange = {}));
864
+ var SemanticTokenTypes;
865
+ (function(SemanticTokenTypes2) {
866
+ SemanticTokenTypes2["namespace"] = "namespace";
867
+ SemanticTokenTypes2["type"] = "type";
868
+ SemanticTokenTypes2["class"] = "class";
869
+ SemanticTokenTypes2["enum"] = "enum";
870
+ SemanticTokenTypes2["interface"] = "interface";
871
+ SemanticTokenTypes2["struct"] = "struct";
872
+ SemanticTokenTypes2["typeParameter"] = "typeParameter";
873
+ SemanticTokenTypes2["parameter"] = "parameter";
874
+ SemanticTokenTypes2["variable"] = "variable";
875
+ SemanticTokenTypes2["property"] = "property";
876
+ SemanticTokenTypes2["enumMember"] = "enumMember";
877
+ SemanticTokenTypes2["event"] = "event";
878
+ SemanticTokenTypes2["function"] = "function";
879
+ SemanticTokenTypes2["method"] = "method";
880
+ SemanticTokenTypes2["macro"] = "macro";
881
+ SemanticTokenTypes2["keyword"] = "keyword";
882
+ SemanticTokenTypes2["modifier"] = "modifier";
883
+ SemanticTokenTypes2["comment"] = "comment";
884
+ SemanticTokenTypes2["string"] = "string";
885
+ SemanticTokenTypes2["number"] = "number";
886
+ SemanticTokenTypes2["regexp"] = "regexp";
887
+ SemanticTokenTypes2["operator"] = "operator";
888
+ SemanticTokenTypes2["decorator"] = "decorator";
889
+ })(SemanticTokenTypes || (SemanticTokenTypes = {}));
890
+ var SemanticTokenModifiers;
891
+ (function(SemanticTokenModifiers2) {
892
+ SemanticTokenModifiers2["declaration"] = "declaration";
893
+ SemanticTokenModifiers2["definition"] = "definition";
894
+ SemanticTokenModifiers2["readonly"] = "readonly";
895
+ SemanticTokenModifiers2["static"] = "static";
896
+ SemanticTokenModifiers2["deprecated"] = "deprecated";
897
+ SemanticTokenModifiers2["abstract"] = "abstract";
898
+ SemanticTokenModifiers2["async"] = "async";
899
+ SemanticTokenModifiers2["modification"] = "modification";
900
+ SemanticTokenModifiers2["documentation"] = "documentation";
901
+ SemanticTokenModifiers2["defaultLibrary"] = "defaultLibrary";
902
+ })(SemanticTokenModifiers || (SemanticTokenModifiers = {}));
903
+ var SemanticTokens;
904
+ (function(SemanticTokens2) {
905
+ function is(value) {
906
+ const candidate = value;
907
+ return Is.objectLiteral(candidate) && (candidate.resultId === void 0 || typeof candidate.resultId === "string") && Array.isArray(candidate.data) && (candidate.data.length === 0 || typeof candidate.data[0] === "number");
908
+ }
909
+ SemanticTokens2.is = is;
910
+ })(SemanticTokens || (SemanticTokens = {}));
911
+ var InlineValueText;
912
+ (function(InlineValueText2) {
913
+ function create(range, text) {
914
+ return { range, text };
915
+ }
916
+ InlineValueText2.create = create;
917
+ function is(value) {
918
+ const candidate = value;
919
+ return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && Is.string(candidate.text);
920
+ }
921
+ InlineValueText2.is = is;
922
+ })(InlineValueText || (InlineValueText = {}));
923
+ var InlineValueVariableLookup;
924
+ (function(InlineValueVariableLookup2) {
925
+ function create(range, variableName, caseSensitiveLookup) {
926
+ return { range, variableName, caseSensitiveLookup };
927
+ }
928
+ InlineValueVariableLookup2.create = create;
929
+ function is(value) {
930
+ const candidate = value;
931
+ return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && Is.boolean(candidate.caseSensitiveLookup) && (Is.string(candidate.variableName) || candidate.variableName === void 0);
932
+ }
933
+ InlineValueVariableLookup2.is = is;
934
+ })(InlineValueVariableLookup || (InlineValueVariableLookup = {}));
935
+ var InlineValueEvaluatableExpression;
936
+ (function(InlineValueEvaluatableExpression2) {
937
+ function create(range, expression) {
938
+ return { range, expression };
939
+ }
940
+ InlineValueEvaluatableExpression2.create = create;
941
+ function is(value) {
942
+ const candidate = value;
943
+ return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && (Is.string(candidate.expression) || candidate.expression === void 0);
944
+ }
945
+ InlineValueEvaluatableExpression2.is = is;
946
+ })(InlineValueEvaluatableExpression || (InlineValueEvaluatableExpression = {}));
947
+ var InlineValueContext;
948
+ (function(InlineValueContext2) {
949
+ function create(frameId, stoppedLocation) {
950
+ return { frameId, stoppedLocation };
951
+ }
952
+ InlineValueContext2.create = create;
953
+ function is(value) {
954
+ const candidate = value;
955
+ return Is.defined(candidate) && Range.is(value.stoppedLocation);
956
+ }
957
+ InlineValueContext2.is = is;
958
+ })(InlineValueContext || (InlineValueContext = {}));
959
+ var InlayHintKind;
960
+ (function(InlayHintKind2) {
961
+ InlayHintKind2.Type = 1;
962
+ InlayHintKind2.Parameter = 2;
963
+ function is(value) {
964
+ return value === 1 || value === 2;
965
+ }
966
+ InlayHintKind2.is = is;
967
+ })(InlayHintKind || (InlayHintKind = {}));
968
+ var InlayHintLabelPart;
969
+ (function(InlayHintLabelPart2) {
970
+ function create(value) {
971
+ return { value };
972
+ }
973
+ InlayHintLabelPart2.create = create;
974
+ function is(value) {
975
+ const candidate = value;
976
+ return Is.objectLiteral(candidate) && (candidate.tooltip === void 0 || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.location === void 0 || Location.is(candidate.location)) && (candidate.command === void 0 || Command.is(candidate.command));
977
+ }
978
+ InlayHintLabelPart2.is = is;
979
+ })(InlayHintLabelPart || (InlayHintLabelPart = {}));
980
+ var InlayHint;
981
+ (function(InlayHint2) {
982
+ function create(position, label, kind) {
983
+ const result = { position, label };
984
+ if (kind !== void 0) {
985
+ result.kind = kind;
986
+ }
987
+ return result;
988
+ }
989
+ InlayHint2.create = create;
990
+ function is(value) {
991
+ const candidate = value;
992
+ return Is.objectLiteral(candidate) && Position.is(candidate.position) && (Is.string(candidate.label) || Is.typedArray(candidate.label, InlayHintLabelPart.is)) && (candidate.kind === void 0 || InlayHintKind.is(candidate.kind)) && candidate.textEdits === void 0 || Is.typedArray(candidate.textEdits, TextEdit.is) && (candidate.tooltip === void 0 || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.paddingLeft === void 0 || Is.boolean(candidate.paddingLeft)) && (candidate.paddingRight === void 0 || Is.boolean(candidate.paddingRight));
993
+ }
994
+ InlayHint2.is = is;
995
+ })(InlayHint || (InlayHint = {}));
996
+ var StringValue;
997
+ (function(StringValue2) {
998
+ function createSnippet(value) {
999
+ return { kind: "snippet", value };
1000
+ }
1001
+ StringValue2.createSnippet = createSnippet;
1002
+ })(StringValue || (StringValue = {}));
1003
+ var InlineCompletionItem;
1004
+ (function(InlineCompletionItem2) {
1005
+ function create(insertText, filterText, range, command) {
1006
+ return { insertText, filterText, range, command };
1007
+ }
1008
+ InlineCompletionItem2.create = create;
1009
+ })(InlineCompletionItem || (InlineCompletionItem = {}));
1010
+ var InlineCompletionList;
1011
+ (function(InlineCompletionList2) {
1012
+ function create(items) {
1013
+ return { items };
1014
+ }
1015
+ InlineCompletionList2.create = create;
1016
+ })(InlineCompletionList || (InlineCompletionList = {}));
1017
+ var InlineCompletionTriggerKind;
1018
+ (function(InlineCompletionTriggerKind2) {
1019
+ InlineCompletionTriggerKind2.Invoked = 0;
1020
+ InlineCompletionTriggerKind2.Automatic = 1;
1021
+ })(InlineCompletionTriggerKind || (InlineCompletionTriggerKind = {}));
1022
+ var SelectedCompletionInfo;
1023
+ (function(SelectedCompletionInfo2) {
1024
+ function create(range, text) {
1025
+ return { range, text };
1026
+ }
1027
+ SelectedCompletionInfo2.create = create;
1028
+ })(SelectedCompletionInfo || (SelectedCompletionInfo = {}));
1029
+ var InlineCompletionContext;
1030
+ (function(InlineCompletionContext2) {
1031
+ function create(triggerKind, selectedCompletionInfo) {
1032
+ return { triggerKind, selectedCompletionInfo };
1033
+ }
1034
+ InlineCompletionContext2.create = create;
1035
+ })(InlineCompletionContext || (InlineCompletionContext = {}));
1036
+ var WorkspaceFolder;
1037
+ (function(WorkspaceFolder2) {
1038
+ function is(value) {
1039
+ const candidate = value;
1040
+ return Is.objectLiteral(candidate) && URI.is(candidate.uri) && Is.string(candidate.name);
1041
+ }
1042
+ WorkspaceFolder2.is = is;
1043
+ })(WorkspaceFolder || (WorkspaceFolder = {}));
1044
+ var TextDocument;
1045
+ (function(TextDocument3) {
1046
+ function create(uri, languageId, version, content) {
1047
+ return new FullTextDocument(uri, languageId, version, content);
1048
+ }
1049
+ TextDocument3.create = create;
1050
+ function is(value) {
1051
+ let candidate = value;
1052
+ 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;
1053
+ }
1054
+ TextDocument3.is = is;
1055
+ function applyEdits(document2, edits) {
1056
+ let text = document2.getText();
1057
+ let sortedEdits = mergeSort2(edits, (a, b) => {
1058
+ let diff = a.range.start.line - b.range.start.line;
1059
+ if (diff === 0) {
1060
+ return a.range.start.character - b.range.start.character;
1061
+ }
1062
+ return diff;
1063
+ });
1064
+ let lastModifiedOffset = text.length;
1065
+ for (let i = sortedEdits.length - 1; i >= 0; i--) {
1066
+ let e = sortedEdits[i];
1067
+ let startOffset = document2.offsetAt(e.range.start);
1068
+ let endOffset = document2.offsetAt(e.range.end);
1069
+ if (endOffset <= lastModifiedOffset) {
1070
+ text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
1071
+ } else {
1072
+ throw new Error("Overlapping edit");
1073
+ }
1074
+ lastModifiedOffset = startOffset;
1075
+ }
1076
+ return text;
1077
+ }
1078
+ TextDocument3.applyEdits = applyEdits;
1079
+ function mergeSort2(data, compare) {
1080
+ if (data.length <= 1) {
1081
+ return data;
1082
+ }
1083
+ const p = data.length / 2 | 0;
1084
+ const left = data.slice(0, p);
1085
+ const right = data.slice(p);
1086
+ mergeSort2(left, compare);
1087
+ mergeSort2(right, compare);
1088
+ let leftIdx = 0;
1089
+ let rightIdx = 0;
1090
+ let i = 0;
1091
+ while (leftIdx < left.length && rightIdx < right.length) {
1092
+ let ret = compare(left[leftIdx], right[rightIdx]);
1093
+ if (ret <= 0) {
1094
+ data[i++] = left[leftIdx++];
1095
+ } else {
1096
+ data[i++] = right[rightIdx++];
1097
+ }
1098
+ }
1099
+ while (leftIdx < left.length) {
1100
+ data[i++] = left[leftIdx++];
1101
+ }
1102
+ while (rightIdx < right.length) {
1103
+ data[i++] = right[rightIdx++];
1104
+ }
1105
+ return data;
1106
+ }
1107
+ })(TextDocument || (TextDocument = {}));
1108
+ var FullTextDocument = class {
1109
+ constructor(uri, languageId, version, content) {
1110
+ this._uri = uri;
1111
+ this._languageId = languageId;
1112
+ this._version = version;
1113
+ this._content = content;
1114
+ this._lineOffsets = void 0;
1115
+ }
1116
+ get uri() {
1117
+ return this._uri;
1118
+ }
1119
+ get languageId() {
1120
+ return this._languageId;
1121
+ }
1122
+ get version() {
1123
+ return this._version;
1124
+ }
1125
+ getText(range) {
1126
+ if (range) {
1127
+ let start = this.offsetAt(range.start);
1128
+ let end = this.offsetAt(range.end);
1129
+ return this._content.substring(start, end);
1130
+ }
1131
+ return this._content;
1132
+ }
1133
+ update(event, version) {
1134
+ this._content = event.text;
1135
+ this._version = version;
1136
+ this._lineOffsets = void 0;
1137
+ }
1138
+ getLineOffsets() {
1139
+ if (this._lineOffsets === void 0) {
1140
+ let lineOffsets = [];
1141
+ let text = this._content;
1142
+ let isLineStart = true;
1143
+ for (let i = 0; i < text.length; i++) {
1144
+ if (isLineStart) {
1145
+ lineOffsets.push(i);
1146
+ isLineStart = false;
1147
+ }
1148
+ let ch = text.charAt(i);
1149
+ isLineStart = ch === "\r" || ch === "\n";
1150
+ if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
1151
+ i++;
1152
+ }
1153
+ }
1154
+ if (isLineStart && text.length > 0) {
1155
+ lineOffsets.push(text.length);
1156
+ }
1157
+ this._lineOffsets = lineOffsets;
1158
+ }
1159
+ return this._lineOffsets;
1160
+ }
1161
+ positionAt(offset) {
1162
+ offset = Math.max(Math.min(offset, this._content.length), 0);
1163
+ let lineOffsets = this.getLineOffsets();
1164
+ let low = 0, high = lineOffsets.length;
1165
+ if (high === 0) {
1166
+ return Position.create(0, offset);
1167
+ }
1168
+ while (low < high) {
1169
+ let mid = Math.floor((low + high) / 2);
1170
+ if (lineOffsets[mid] > offset) {
1171
+ high = mid;
1172
+ } else {
1173
+ low = mid + 1;
1174
+ }
1175
+ }
1176
+ let line = low - 1;
1177
+ return Position.create(line, offset - lineOffsets[line]);
1178
+ }
1179
+ offsetAt(position) {
1180
+ let lineOffsets = this.getLineOffsets();
1181
+ if (position.line >= lineOffsets.length) {
1182
+ return this._content.length;
1183
+ } else if (position.line < 0) {
1184
+ return 0;
1185
+ }
1186
+ let lineOffset = lineOffsets[position.line];
1187
+ let nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
1188
+ return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
1189
+ }
1190
+ get lineCount() {
1191
+ return this.getLineOffsets().length;
1192
+ }
1193
+ };
1194
+ var Is;
1195
+ (function(Is2) {
1196
+ const toString = Object.prototype.toString;
1197
+ function defined(value) {
1198
+ return typeof value !== "undefined";
1199
+ }
1200
+ Is2.defined = defined;
1201
+ function undefined2(value) {
1202
+ return typeof value === "undefined";
1203
+ }
1204
+ Is2.undefined = undefined2;
1205
+ function boolean(value) {
1206
+ return value === true || value === false;
1207
+ }
1208
+ Is2.boolean = boolean;
1209
+ function string(value) {
1210
+ return toString.call(value) === "[object String]";
1211
+ }
1212
+ Is2.string = string;
1213
+ function number(value) {
1214
+ return toString.call(value) === "[object Number]";
1215
+ }
1216
+ Is2.number = number;
1217
+ function numberRange(value, min, max) {
1218
+ return toString.call(value) === "[object Number]" && min <= value && value <= max;
1219
+ }
1220
+ Is2.numberRange = numberRange;
1221
+ function integer2(value) {
1222
+ return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
1223
+ }
1224
+ Is2.integer = integer2;
1225
+ function uinteger2(value) {
1226
+ return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
1227
+ }
1228
+ Is2.uinteger = uinteger2;
1229
+ function func(value) {
1230
+ return toString.call(value) === "[object Function]";
1231
+ }
1232
+ Is2.func = func;
1233
+ function objectLiteral(value) {
1234
+ return value !== null && typeof value === "object";
1235
+ }
1236
+ Is2.objectLiteral = objectLiteral;
1237
+ function typedArray(value, check) {
1238
+ return Array.isArray(value) && value.every(check);
1239
+ }
1240
+ Is2.typedArray = typedArray;
1241
+ })(Is || (Is = {}));
1242
+
1243
+ // node_modules/.pnpm/vscode-languageserver-textdocument@1.0.12/node_modules/vscode-languageserver-textdocument/lib/esm/main.js
1244
+ var FullTextDocument2 = class _FullTextDocument {
1245
+ constructor(uri, languageId, version, content) {
1246
+ this._uri = uri;
1247
+ this._languageId = languageId;
1248
+ this._version = version;
1249
+ this._content = content;
1250
+ this._lineOffsets = void 0;
1251
+ }
1252
+ get uri() {
1253
+ return this._uri;
1254
+ }
1255
+ get languageId() {
1256
+ return this._languageId;
1257
+ }
1258
+ get version() {
1259
+ return this._version;
1260
+ }
1261
+ getText(range) {
1262
+ if (range) {
1263
+ const start = this.offsetAt(range.start);
1264
+ const end = this.offsetAt(range.end);
1265
+ return this._content.substring(start, end);
1266
+ }
1267
+ return this._content;
1268
+ }
1269
+ update(changes, version) {
1270
+ for (const change of changes) {
1271
+ if (_FullTextDocument.isIncremental(change)) {
1272
+ const range = getWellformedRange(change.range);
1273
+ const startOffset = this.offsetAt(range.start);
1274
+ const endOffset = this.offsetAt(range.end);
1275
+ this._content = this._content.substring(0, startOffset) + change.text + this._content.substring(endOffset, this._content.length);
1276
+ const startLine = Math.max(range.start.line, 0);
1277
+ const endLine = Math.max(range.end.line, 0);
1278
+ let lineOffsets = this._lineOffsets;
1279
+ const addedLineOffsets = computeLineOffsets(change.text, false, startOffset);
1280
+ if (endLine - startLine === addedLineOffsets.length) {
1281
+ for (let i = 0, len = addedLineOffsets.length; i < len; i++) {
1282
+ lineOffsets[i + startLine + 1] = addedLineOffsets[i];
1283
+ }
1284
+ } else {
1285
+ if (addedLineOffsets.length < 1e4) {
1286
+ lineOffsets.splice(startLine + 1, endLine - startLine, ...addedLineOffsets);
1287
+ } else {
1288
+ this._lineOffsets = lineOffsets = lineOffsets.slice(0, startLine + 1).concat(addedLineOffsets, lineOffsets.slice(endLine + 1));
1289
+ }
1290
+ }
1291
+ const diff = change.text.length - (endOffset - startOffset);
1292
+ if (diff !== 0) {
1293
+ for (let i = startLine + 1 + addedLineOffsets.length, len = lineOffsets.length; i < len; i++) {
1294
+ lineOffsets[i] = lineOffsets[i] + diff;
1295
+ }
1296
+ }
1297
+ } else if (_FullTextDocument.isFull(change)) {
1298
+ this._content = change.text;
1299
+ this._lineOffsets = void 0;
1300
+ } else {
1301
+ throw new Error("Unknown change event received");
1302
+ }
1303
+ }
1304
+ this._version = version;
1305
+ }
1306
+ getLineOffsets() {
1307
+ if (this._lineOffsets === void 0) {
1308
+ this._lineOffsets = computeLineOffsets(this._content, true);
1309
+ }
1310
+ return this._lineOffsets;
1311
+ }
1312
+ positionAt(offset) {
1313
+ offset = Math.max(Math.min(offset, this._content.length), 0);
1314
+ const lineOffsets = this.getLineOffsets();
1315
+ let low = 0, high = lineOffsets.length;
1316
+ if (high === 0) {
1317
+ return { line: 0, character: offset };
1318
+ }
1319
+ while (low < high) {
1320
+ const mid = Math.floor((low + high) / 2);
1321
+ if (lineOffsets[mid] > offset) {
1322
+ high = mid;
1323
+ } else {
1324
+ low = mid + 1;
1325
+ }
1326
+ }
1327
+ const line = low - 1;
1328
+ offset = this.ensureBeforeEOL(offset, lineOffsets[line]);
1329
+ return { line, character: offset - lineOffsets[line] };
1330
+ }
1331
+ offsetAt(position) {
1332
+ const lineOffsets = this.getLineOffsets();
1333
+ if (position.line >= lineOffsets.length) {
1334
+ return this._content.length;
1335
+ } else if (position.line < 0) {
1336
+ return 0;
1337
+ }
1338
+ const lineOffset = lineOffsets[position.line];
1339
+ if (position.character <= 0) {
1340
+ return lineOffset;
1341
+ }
1342
+ const nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
1343
+ const offset = Math.min(lineOffset + position.character, nextLineOffset);
1344
+ return this.ensureBeforeEOL(offset, lineOffset);
1345
+ }
1346
+ ensureBeforeEOL(offset, lineOffset) {
1347
+ while (offset > lineOffset && isEOL(this._content.charCodeAt(offset - 1))) {
1348
+ offset--;
1349
+ }
1350
+ return offset;
1351
+ }
1352
+ get lineCount() {
1353
+ return this.getLineOffsets().length;
1354
+ }
1355
+ static isIncremental(event) {
1356
+ const candidate = event;
1357
+ return candidate !== void 0 && candidate !== null && typeof candidate.text === "string" && candidate.range !== void 0 && (candidate.rangeLength === void 0 || typeof candidate.rangeLength === "number");
1358
+ }
1359
+ static isFull(event) {
1360
+ const candidate = event;
1361
+ return candidate !== void 0 && candidate !== null && typeof candidate.text === "string" && candidate.range === void 0 && candidate.rangeLength === void 0;
1362
+ }
1363
+ };
1364
+ var TextDocument2;
1365
+ (function(TextDocument3) {
1366
+ function create(uri, languageId, version, content) {
1367
+ return new FullTextDocument2(uri, languageId, version, content);
1368
+ }
1369
+ TextDocument3.create = create;
1370
+ function update(document2, changes, version) {
1371
+ if (document2 instanceof FullTextDocument2) {
1372
+ document2.update(changes, version);
1373
+ return document2;
1374
+ } else {
1375
+ throw new Error("TextDocument.update: document must be created by TextDocument.create");
1376
+ }
1377
+ }
1378
+ TextDocument3.update = update;
1379
+ function applyEdits(document2, edits) {
1380
+ const text = document2.getText();
1381
+ const sortedEdits = mergeSort(edits.map(getWellformedEdit), (a, b) => {
1382
+ const diff = a.range.start.line - b.range.start.line;
1383
+ if (diff === 0) {
1384
+ return a.range.start.character - b.range.start.character;
1385
+ }
1386
+ return diff;
1387
+ });
1388
+ let lastModifiedOffset = 0;
1389
+ const spans = [];
1390
+ for (const e of sortedEdits) {
1391
+ const startOffset = document2.offsetAt(e.range.start);
1392
+ if (startOffset < lastModifiedOffset) {
1393
+ throw new Error("Overlapping edit");
1394
+ } else if (startOffset > lastModifiedOffset) {
1395
+ spans.push(text.substring(lastModifiedOffset, startOffset));
1396
+ }
1397
+ if (e.newText.length) {
1398
+ spans.push(e.newText);
1399
+ }
1400
+ lastModifiedOffset = document2.offsetAt(e.range.end);
1401
+ }
1402
+ spans.push(text.substr(lastModifiedOffset));
1403
+ return spans.join("");
1404
+ }
1405
+ TextDocument3.applyEdits = applyEdits;
1406
+ })(TextDocument2 || (TextDocument2 = {}));
1407
+ function mergeSort(data, compare) {
1408
+ if (data.length <= 1) {
1409
+ return data;
1410
+ }
1411
+ const p = data.length / 2 | 0;
1412
+ const left = data.slice(0, p);
1413
+ const right = data.slice(p);
1414
+ mergeSort(left, compare);
1415
+ mergeSort(right, compare);
1416
+ let leftIdx = 0;
1417
+ let rightIdx = 0;
1418
+ let i = 0;
1419
+ while (leftIdx < left.length && rightIdx < right.length) {
1420
+ const ret = compare(left[leftIdx], right[rightIdx]);
1421
+ if (ret <= 0) {
1422
+ data[i++] = left[leftIdx++];
1423
+ } else {
1424
+ data[i++] = right[rightIdx++];
1425
+ }
1426
+ }
1427
+ while (leftIdx < left.length) {
1428
+ data[i++] = left[leftIdx++];
1429
+ }
1430
+ while (rightIdx < right.length) {
1431
+ data[i++] = right[rightIdx++];
1432
+ }
1433
+ return data;
1434
+ }
1435
+ function computeLineOffsets(text, isAtLineStart, textOffset = 0) {
1436
+ const result = isAtLineStart ? [textOffset] : [];
1437
+ for (let i = 0; i < text.length; i++) {
1438
+ const ch = text.charCodeAt(i);
1439
+ if (isEOL(ch)) {
1440
+ if (ch === 13 && i + 1 < text.length && text.charCodeAt(i + 1) === 10) {
1441
+ i++;
1442
+ }
1443
+ result.push(textOffset + i + 1);
1444
+ }
1445
+ }
1446
+ return result;
1447
+ }
1448
+ function isEOL(char) {
1449
+ return char === 13 || char === 10;
1450
+ }
1451
+ function getWellformedRange(range) {
1452
+ const start = range.start;
1453
+ const end = range.end;
1454
+ if (start.line > end.line || start.line === end.line && start.character > end.character) {
1455
+ return { start: end, end: start };
1456
+ }
1457
+ return range;
1458
+ }
1459
+ function getWellformedEdit(textEdit) {
1460
+ const range = getWellformedRange(textEdit.range);
1461
+ if (range !== textEdit.range) {
1462
+ return { newText: textEdit.newText, range };
1463
+ }
1464
+ return textEdit;
1465
+ }
1466
+
1467
+ // src/lsp/worker-base.ts
1468
+ var WorkerBase = class {
1469
+ constructor(_ctx, _createLanguageDocument) {
1470
+ this._ctx = _ctx;
1471
+ this._createLanguageDocument = _createLanguageDocument;
1472
+ }
1473
+ _documentCache = /* @__PURE__ */ new Map();
1474
+ _fsEntries;
1475
+ get hasFileSystemProvider() {
1476
+ return !!this._fsEntries;
1477
+ }
1478
+ get host() {
1479
+ return this._ctx.host;
1480
+ }
1481
+ getMirrorModels() {
1482
+ return this._ctx.getMirrorModels();
1483
+ }
1484
+ hasModel(fileName) {
1485
+ const models = this.getMirrorModels();
1486
+ for (let i = 0; i < models.length; i++) {
1487
+ const uri = models[i].uri;
1488
+ if (uri.toString() === fileName || uri.toString(true) === fileName) {
1489
+ return true;
1490
+ }
1491
+ }
1492
+ return false;
1493
+ }
1494
+ getModel(fileName) {
1495
+ const models = this.getMirrorModels();
1496
+ for (let i = 0; i < models.length; i++) {
1497
+ const uri = models[i].uri;
1498
+ if (uri.toString() === fileName || uri.toString(true) === fileName) {
1499
+ return models[i];
1500
+ }
1501
+ }
1502
+ return null;
1503
+ }
1504
+ getTextDocument(uri) {
1505
+ const model = this.getModel(uri);
1506
+ if (!model) {
1507
+ return null;
1508
+ }
1509
+ const cached = this._documentCache.get(uri);
1510
+ if (cached && cached[0] === model.version) {
1511
+ return cached[1];
1512
+ }
1513
+ const document2 = TextDocument2.create(uri, "-", model.version, model.getValue());
1514
+ this._documentCache.set(uri, [model.version, document2, void 0]);
1515
+ return document2;
1516
+ }
1517
+ getLanguageDocument(document2) {
1518
+ const { uri, version } = document2;
1519
+ const cached = this._documentCache.get(uri);
1520
+ if (cached && cached[0] === version && cached[2]) {
1521
+ return cached[2];
1522
+ }
1523
+ if (!this._createLanguageDocument) {
1524
+ throw new Error("createLanguageDocument is not provided");
1525
+ }
1526
+ const languageDocument = this._createLanguageDocument(document2);
1527
+ this._documentCache.set(uri, [version, document2, languageDocument]);
1528
+ return languageDocument;
1529
+ }
1530
+ readDir(uri, extensions) {
1531
+ const entries = [];
1532
+ const fsTree = this._fsEntries;
1533
+ if (fsTree) {
1534
+ for (const [path, type] of fsTree) {
1535
+ if (path.startsWith(uri)) {
1536
+ const name = path.slice(uri.length);
1537
+ if (!name.includes("/")) {
1538
+ if (type === 2) {
1539
+ entries.push([name, 2 /* Directory */]);
1540
+ } else if (!extensions || extensions.some((ext) => name.endsWith(ext))) {
1541
+ entries.push([name, 1 /* File */]);
1542
+ }
1543
+ }
1544
+ }
1545
+ }
1546
+ }
1547
+ return entries;
1548
+ }
1549
+ getFileSystemProvider() {
1550
+ if (this.hasFileSystemProvider) {
1551
+ const host = this._ctx.host;
1552
+ return {
1553
+ readDirectory: (uri) => {
1554
+ return Promise.resolve(this.readDir(uri));
1555
+ },
1556
+ stat: (uri) => {
1557
+ return host.fs_stat(uri);
1558
+ },
1559
+ getContent: (uri, encoding) => {
1560
+ return host.fs_getContent(uri);
1561
+ }
1562
+ };
1563
+ }
1564
+ return void 0;
1565
+ }
1566
+ // resolveReference implementes the `DocumentContext` interface
1567
+ resolveReference(ref, baseUrl) {
1568
+ const url = new URL(ref, baseUrl);
1569
+ const href = url.href;
1570
+ if (url.protocol === "file:" && this._fsEntries) {
1571
+ if (!this._fsEntries.has(href)) {
1572
+ return void 0;
1573
+ }
1574
+ }
1575
+ return href;
1576
+ }
1577
+ // #region methods used by the host
1578
+ async removeDocumentCache(uri) {
1579
+ this._documentCache.delete(uri);
1580
+ }
1581
+ async syncFSEntries(entries) {
1582
+ this._fsEntries = new Map(entries);
1583
+ }
1584
+ async fsNotify(kind, path, type) {
1585
+ const url = "file://" + path;
1586
+ const entries = this._fsEntries ?? (this._fsEntries = /* @__PURE__ */ new Map());
1587
+ if (kind === "create") {
1588
+ if (type) {
1589
+ entries.set(url, type);
1590
+ }
1591
+ } else if (kind === "remove") {
1592
+ if (entries.get(url) === 1 /* File */) {
1593
+ this._documentCache.delete(url);
1594
+ }
1595
+ entries.delete(url);
1596
+ }
1597
+ }
1598
+ // #endregion
1599
+ };
1600
+
1601
+ // src/lsp/typescript/worker.ts
1602
+ import libs from "./libs.js";
1603
+ import { cache } from "../../cache.js";
1604
+ import { initializeWorker } from "../../editor-worker.js";
1605
+ var TypeScriptWorker = class extends WorkerBase {
1606
+ _compilerOptions;
1607
+ _importMap;
1608
+ _importMapVersion;
1609
+ _isBlankImportMap;
1610
+ _types;
1611
+ _formatOptions;
1612
+ _languageService = ts.createLanguageService(this);
1613
+ _urlMappings = /* @__PURE__ */ new Map();
1614
+ _typesMappings = /* @__PURE__ */ new Map();
1615
+ _httpLibs = /* @__PURE__ */ new Map();
1616
+ _httpModules = /* @__PURE__ */ new Map();
1617
+ _httpTsModules = /* @__PURE__ */ new Map();
1618
+ _redirectedImports = [];
1619
+ _unknownImports = /* @__PURE__ */ new Set();
1620
+ _badImports = /* @__PURE__ */ new Set();
1621
+ _openPromises = /* @__PURE__ */ new Map();
1622
+ _fetchPromises = /* @__PURE__ */ new Map();
1623
+ _httpDocumentCache = /* @__PURE__ */ new Map();
1624
+ constructor(ctx, createData) {
1625
+ super(ctx);
1626
+ this._compilerOptions = ts.convertCompilerOptionsFromJson(createData.compilerOptions, ".").options;
1627
+ this._importMap = createData.importMap;
1628
+ this._importMapVersion = 0;
1629
+ this._isBlankImportMap = isBlankImportMap(createData.importMap);
1630
+ this._types = createData.types;
1631
+ this._formatOptions = createData.formatOptions;
1632
+ this._updateJsxImportSource();
1633
+ }
1634
+ // #region language service host
1635
+ getCurrentDirectory() {
1636
+ return "/";
1637
+ }
1638
+ getDirectories(path) {
1639
+ if (path === "/node_modules/@types") {
1640
+ return [];
1641
+ }
1642
+ if (path.startsWith("file:///node_modules/")) {
1643
+ const dirname = path.slice("file:///node_modules/".length);
1644
+ return Object.keys(this._importMap.imports).filter((key) => key !== "@jsxRuntime" && (dirname.length === 0 || key.startsWith(dirname))).map((key) => dirname.length > 0 ? key.slice(dirname.length) : key).filter((key) => key !== "/" && key.includes("/")).map((key) => key.split("/")[0]);
1645
+ }
1646
+ return this.readDir(path).filter(([_, type]) => type === 2 /* Directory */).map(([name, _]) => name);
1647
+ }
1648
+ readDirectory(path, extensions, exclude, include, depth) {
1649
+ if (path.startsWith("file:///node_modules/")) {
1650
+ const dirname = path.slice("file:///node_modules/".length);
1651
+ return Object.keys(this._importMap.imports).filter((key) => key !== "@jsxRuntime" && (dirname.length === 0 || key.startsWith(dirname))).map((key) => dirname.length > 0 ? key.slice(dirname.length) : key).filter((key) => !key.includes("/"));
1652
+ }
1653
+ return this.readDir(path, extensions).filter(([_, type]) => type === 1 /* File */).map(([name, _]) => name);
1654
+ }
1655
+ fileExists(filename) {
1656
+ if (filename.startsWith("/node_modules/")) return false;
1657
+ return filename in libs || `lib.${filename}.d.ts` in libs || filename in this._types || this._httpLibs.has(filename) || this._httpModules.has(filename) || this._httpTsModules.has(filename) || this.hasModel(filename);
1658
+ }
1659
+ readFile(filename) {
1660
+ return this._getScriptText(filename);
1661
+ }
1662
+ getScriptFileNames() {
1663
+ const models = this.getMirrorModels();
1664
+ const types = Object.keys(this._types);
1665
+ const libNames = Object.keys(libs);
1666
+ const filenames = new Array(
1667
+ models.length + types.length + libNames.length + this._httpLibs.size + this._httpModules.size + this._httpTsModules.size
1668
+ );
1669
+ let i = 0;
1670
+ for (const model of models) {
1671
+ filenames[i++] = model.uri.toString();
1672
+ }
1673
+ for (const filename of types) {
1674
+ filenames[i++] = filename;
1675
+ }
1676
+ for (const filename of libNames) {
1677
+ filenames[i++] = filename;
1678
+ }
1679
+ for (const filename of this._httpLibs.keys()) {
1680
+ filenames[i++] = filename;
1681
+ }
1682
+ for (const filename of this._httpModules.keys()) {
1683
+ filenames[i++] = filename;
1684
+ }
1685
+ for (const filename of this._httpTsModules.keys()) {
1686
+ filenames[i++] = filename;
1687
+ }
1688
+ return filenames;
1689
+ }
1690
+ getScriptVersion(fileName) {
1691
+ if (fileName in this._types) {
1692
+ return String(this._types[fileName].version);
1693
+ }
1694
+ if (fileName in libs || fileName in this._types || this._httpLibs.has(fileName) || this._httpModules.has(fileName) || this._httpTsModules.has(fileName)) {
1695
+ return "1";
1696
+ }
1697
+ const model = this.getModel(fileName);
1698
+ if (model) {
1699
+ return this._importMapVersion + "." + model.version;
1700
+ }
1701
+ return "0";
1702
+ }
1703
+ getScriptSnapshot(fileName) {
1704
+ const text = this._getScriptText(fileName);
1705
+ if (text === void 0) {
1706
+ return void 0;
1707
+ }
1708
+ return ts.ScriptSnapshot.fromString(text);
1709
+ }
1710
+ getCompilationSettings() {
1711
+ return this._compilerOptions;
1712
+ }
1713
+ getDefaultLibFileName(options) {
1714
+ switch (options.target) {
1715
+ case 0:
1716
+ case 1:
1717
+ return "lib.d.ts";
1718
+ case 2:
1719
+ return "lib.es6.d.ts";
1720
+ case 3:
1721
+ case 4:
1722
+ case 5:
1723
+ case 6:
1724
+ case 7:
1725
+ case 8:
1726
+ case 9:
1727
+ case 10:
1728
+ return `lib.es${2013 + options.target}.full.d.ts`;
1729
+ case 99:
1730
+ return "lib.esnext.full.d.ts";
1731
+ default:
1732
+ return "lib.es6.d.ts";
1733
+ }
1734
+ }
1735
+ resolveModuleNameLiterals(moduleLiterals, containingFile, _redirectedReference, _options, _containingSourceFile, _reusedNames) {
1736
+ this._redirectedImports = this._redirectedImports.filter(([modelUrl]) => modelUrl !== containingFile);
1737
+ return moduleLiterals.map((literal) => {
1738
+ let specifier = literal.text;
1739
+ let importMapResolved = false;
1740
+ if (!this._isBlankImportMap) {
1741
+ const [url, resolved] = resolve(this._importMap, specifier, containingFile);
1742
+ importMapResolved = resolved;
1743
+ if (importMapResolved) {
1744
+ specifier = url;
1745
+ }
1746
+ }
1747
+ if (!importMapResolved && !isHttpUrl(specifier) && !isRelativePath(specifier)) {
1748
+ return void 0;
1749
+ }
1750
+ let moduleUrl;
1751
+ try {
1752
+ moduleUrl = new URL(specifier, pathToUrl(containingFile));
1753
+ } catch (error) {
1754
+ return void 0;
1755
+ }
1756
+ if (getScriptExtension(moduleUrl.pathname) === null) {
1757
+ const ext = getScriptExtension(containingFile);
1758
+ if (ext === ".d.ts" || ext === ".d.mts" || ext === ".d.cts") {
1759
+ moduleUrl.pathname += ext;
1760
+ }
1761
+ }
1762
+ if (this._httpModules.has(containingFile)) {
1763
+ return {
1764
+ resolvedFileName: moduleUrl.href,
1765
+ extension: ".js"
1766
+ };
1767
+ }
1768
+ if (moduleUrl.protocol === "file:") {
1769
+ const moduleHref = moduleUrl.href;
1770
+ if (this._badImports.has(moduleHref)) {
1771
+ return void 0;
1772
+ }
1773
+ for (const model of this.getMirrorModels()) {
1774
+ if (moduleHref === model.uri.toString()) {
1775
+ return {
1776
+ resolvedFileName: moduleHref,
1777
+ extension: getScriptExtension(moduleUrl.pathname) ?? ".js"
1778
+ };
1779
+ }
1780
+ }
1781
+ if (!this.hasFileSystemProvider) {
1782
+ return void 0;
1783
+ }
1784
+ if (!this._openPromises.has(moduleHref)) {
1785
+ this._openPromises.set(
1786
+ moduleHref,
1787
+ this.host.openModel(moduleHref).then((ok) => {
1788
+ if (!ok) {
1789
+ this._badImports.add(moduleHref);
1790
+ this._rollbackVersion(containingFile);
1791
+ }
1792
+ }).finally(() => {
1793
+ this._openPromises.delete(moduleHref);
1794
+ this.host.refreshDiagnostics(containingFile);
1795
+ })
1796
+ );
1797
+ }
1798
+ } else {
1799
+ const moduleHref = moduleUrl.href;
1800
+ if (this._badImports.has(moduleHref) || this._unknownImports.has(moduleHref)) {
1801
+ return void 0;
1802
+ }
1803
+ if (!importMapResolved && this._urlMappings.has(moduleHref)) {
1804
+ const redirectUrl = this._urlMappings.get(moduleHref);
1805
+ this._redirectedImports.push([containingFile, literal, redirectUrl]);
1806
+ }
1807
+ if (this._httpModules.has(moduleHref)) {
1808
+ return {
1809
+ resolvedFileName: moduleHref,
1810
+ extension: getScriptExtension(moduleUrl.pathname) ?? ".js"
1811
+ };
1812
+ }
1813
+ if (this._httpTsModules.has(moduleHref)) {
1814
+ return {
1815
+ resolvedFileName: moduleHref,
1816
+ extension: getScriptExtension(moduleUrl.pathname) ?? ".ts"
1817
+ };
1818
+ }
1819
+ if (this._typesMappings.has(moduleHref)) {
1820
+ return {
1821
+ resolvedFileName: this._typesMappings.get(moduleHref),
1822
+ extension: ".d.ts"
1823
+ };
1824
+ }
1825
+ if (this._httpLibs.has(moduleHref)) {
1826
+ return {
1827
+ resolvedFileName: moduleHref,
1828
+ extension: ".d.ts"
1829
+ };
1830
+ }
1831
+ if (!this._fetchPromises.has(moduleHref)) {
1832
+ const autoFetch = importMapResolved || this._isJsxImportUrl(specifier) || isHttpUrl(containingFile) || isWellKnownCDNURL(moduleUrl);
1833
+ const promise = autoFetch ? cache.fetch(moduleUrl) : cache.query(moduleUrl);
1834
+ this._fetchPromises.set(
1835
+ moduleHref,
1836
+ promise.then(async (res) => {
1837
+ if (!res) {
1838
+ this._unknownImports.add(moduleHref);
1839
+ return;
1840
+ }
1841
+ if (res.ok) {
1842
+ const contentType = res.headers.get("content-type");
1843
+ const dts = res.headers.get("x-typescript-types");
1844
+ if (res.redirected) {
1845
+ this._urlMappings.set(moduleHref, res.url);
1846
+ } else if (dts) {
1847
+ res.body?.cancel();
1848
+ const dtsRes = await cache.fetch(new URL(dts, res.url));
1849
+ if (dtsRes.ok) {
1850
+ this._typesMappings.set(moduleHref, dtsRes.url);
1851
+ this._markHttpLib(dtsRes.url, await dtsRes.text());
1852
+ }
1853
+ } else if (/\.(c|m)?jsx?$/.test(moduleUrl.pathname) || contentType && /^(application|text)\/(javascript|jsx)/.test(contentType)) {
1854
+ this._httpModules.set(moduleHref, await res.text());
1855
+ } else if (/\.(c|m)?tsx?$/.test(moduleUrl.pathname) || contentType && /^(application|text)\/(typescript|tsx)/.test(contentType)) {
1856
+ if (/\.d\.(c|m)?ts$/.test(moduleUrl.pathname)) {
1857
+ this._markHttpLib(moduleHref, await res.text());
1858
+ } else {
1859
+ this._httpTsModules.set(moduleHref, await res.text());
1860
+ }
1861
+ } else {
1862
+ res.body?.cancel();
1863
+ this._badImports.add(moduleHref);
1864
+ }
1865
+ } else {
1866
+ res.body?.cancel();
1867
+ this._badImports.add(moduleHref);
1868
+ }
1869
+ }).catch((err) => {
1870
+ console.error(`Failed to fetch module: ${moduleHref}`, err);
1871
+ }).finally(() => {
1872
+ this._rollbackVersion(containingFile);
1873
+ this._fetchPromises.delete(moduleHref);
1874
+ this.host.refreshDiagnostics(containingFile);
1875
+ })
1876
+ );
1877
+ }
1878
+ }
1879
+ return { resolvedFileName: specifier, extension: ".js" };
1880
+ }).map((resolvedModule) => {
1881
+ return { resolvedModule };
1882
+ });
1883
+ }
1884
+ // #endregion
1885
+ // #region language features
1886
+ async doValidation(uri) {
1887
+ const document2 = this._getTextDocument(uri);
1888
+ if (!document2) {
1889
+ return null;
1890
+ }
1891
+ const ext = getScriptExtension(uri);
1892
+ const diagnostics = [];
1893
+ for (const diagnostic of this._languageService.getSyntacticDiagnostics(uri)) {
1894
+ diagnostics.push(this._convertDiagnostic(document2, diagnostic));
1895
+ }
1896
+ for (const diagnostic of this._languageService.getSuggestionDiagnostics(uri)) {
1897
+ diagnostics.push(this._convertDiagnostic(document2, diagnostic));
1898
+ }
1899
+ if (ext === ".tsx" || ext?.endsWith("ts")) {
1900
+ for (const diagnostic of this._languageService.getSemanticDiagnostics(uri)) {
1901
+ diagnostics.push(this._convertDiagnostic(document2, diagnostic));
1902
+ }
1903
+ }
1904
+ if (this._redirectedImports.length > 0) {
1905
+ this._redirectedImports.forEach(([modelUrl, node, url]) => {
1906
+ if (modelUrl === uri) {
1907
+ diagnostics.push(this._convertDiagnostic(document2, {
1908
+ file: void 0,
1909
+ start: node.getStart(),
1910
+ length: node.getWidth(),
1911
+ code: 7e3,
1912
+ category: ts.DiagnosticCategory.Message,
1913
+ messageText: `The module was redirected to ${url}`
1914
+ }));
1915
+ }
1916
+ });
1917
+ }
1918
+ return diagnostics;
1919
+ }
1920
+ async doAutoComplete(uri, position, ch) {
1921
+ const document2 = this._getTextDocument(uri);
1922
+ if (!document2) {
1923
+ return null;
1924
+ }
1925
+ const info = this._languageService.getJsxClosingTagAtPosition(uri, document2.offsetAt(position));
1926
+ if (info) {
1927
+ return "$0" + info.newText;
1928
+ }
1929
+ return null;
1930
+ }
1931
+ async doComplete(uri, position) {
1932
+ const document2 = this._getTextDocument(uri);
1933
+ if (!document2) {
1934
+ return null;
1935
+ }
1936
+ const offset = document2.offsetAt(position);
1937
+ const completions = this._getCompletionsAtPosition(uri, offset);
1938
+ if (!completions) {
1939
+ return { isIncomplete: false, items: [] };
1940
+ }
1941
+ const items = [];
1942
+ for (const entry of completions.entries) {
1943
+ if (entry.name === "") {
1944
+ continue;
1945
+ }
1946
+ if (entry.kind === "script" && entry.name in this._importMap.imports || entry.name + "/" in this._importMap.imports) {
1947
+ const { replacementSpan } = entry;
1948
+ if (replacementSpan?.length) {
1949
+ const replacementText = document2.getText({
1950
+ start: document2.positionAt(replacementSpan.start),
1951
+ end: document2.positionAt(replacementSpan.start + replacementSpan.length)
1952
+ });
1953
+ if (replacementText.startsWith(".")) {
1954
+ continue;
1955
+ }
1956
+ }
1957
+ }
1958
+ const data = { entryData: entry.data, context: { uri, offset } };
1959
+ const tags = [];
1960
+ if (entry.kindModifiers?.includes("deprecated")) {
1961
+ tags.push(CompletionItemTag.Deprecated);
1962
+ }
1963
+ items.push({
1964
+ label: entry.name,
1965
+ insertText: entry.name,
1966
+ filterText: entry.filterText,
1967
+ sortText: entry.sortText,
1968
+ kind: convertTsCompletionItemKind(entry.kind),
1969
+ tags,
1970
+ data
1971
+ });
1972
+ }
1973
+ return {
1974
+ isIncomplete: !!completions.isIncomplete,
1975
+ items
1976
+ };
1977
+ }
1978
+ async doResolveCompletionItem(item) {
1979
+ if (!item.data?.context) {
1980
+ return null;
1981
+ }
1982
+ const { uri, offset } = item.data.context;
1983
+ const document2 = this._getTextDocument(uri);
1984
+ if (!document2) {
1985
+ return null;
1986
+ }
1987
+ const details = this._getCompletionEntryDetails(uri, offset, item.label, item.data.entryData);
1988
+ if (!details) {
1989
+ return null;
1990
+ }
1991
+ const detail = ts.displayPartsToString(details.displayParts);
1992
+ const documentation = ts.displayPartsToString(details.documentation);
1993
+ const additionalTextEdits = [];
1994
+ if (details.codeActions) {
1995
+ details.codeActions.forEach(
1996
+ (action) => action.changes.forEach(
1997
+ (change) => change.textChanges.forEach(({ span, newText }) => {
1998
+ additionalTextEdits.push({
1999
+ range: createRangeFromDocumentSpan(document2, span),
2000
+ newText
2001
+ });
2002
+ })
2003
+ )
2004
+ );
2005
+ }
2006
+ return { label: item.label, detail, documentation, additionalTextEdits };
2007
+ }
2008
+ async doHover(uri, position) {
2009
+ const document2 = this._getTextDocument(uri);
2010
+ if (!document2) {
2011
+ return null;
2012
+ }
2013
+ const info = this._getQuickInfoAtPosition(uri, document2.offsetAt(position));
2014
+ if (info) {
2015
+ const contents = ts.displayPartsToString(info.displayParts);
2016
+ const documentation = ts.displayPartsToString(info.documentation);
2017
+ const tags = info.tags?.map((tag) => tagStringify(tag)).join(" \n\n") ?? null;
2018
+ return {
2019
+ range: createRangeFromDocumentSpan(document2, info.textSpan),
2020
+ contents: [
2021
+ { language: "typescript", value: contents },
2022
+ documentation + (tags ? "\n\n" + tags : "")
2023
+ ]
2024
+ };
2025
+ }
2026
+ return null;
2027
+ }
2028
+ async doSignatureHelp(uri, position, context) {
2029
+ const triggerReason = toTsSignatureHelpTriggerReason(context);
2030
+ const items = this._languageService.getSignatureHelpItems(uri, position, { triggerReason });
2031
+ if (!items) {
2032
+ return null;
2033
+ }
2034
+ const activeSignature = items.selectedItemIndex;
2035
+ const activeParameter = items.argumentIndex;
2036
+ const signatures = items.items.map((item) => {
2037
+ const signature = { label: "", parameters: [] };
2038
+ signature.documentation = ts.displayPartsToString(item.documentation);
2039
+ signature.label += ts.displayPartsToString(item.prefixDisplayParts);
2040
+ item.parameters.forEach((p, i, a) => {
2041
+ const label = ts.displayPartsToString(p.displayParts);
2042
+ const parameter = {
2043
+ label,
2044
+ documentation: ts.displayPartsToString(p.documentation)
2045
+ };
2046
+ signature.label += label;
2047
+ if (signature.parameters) {
2048
+ signature.parameters.push(parameter);
2049
+ } else {
2050
+ signature.parameters = [parameter];
2051
+ }
2052
+ if (i < a.length - 1) {
2053
+ signature.label += ts.displayPartsToString(item.separatorDisplayParts);
2054
+ }
2055
+ });
2056
+ signature.label += ts.displayPartsToString(item.suffixDisplayParts);
2057
+ return signature;
2058
+ });
2059
+ return { signatures, activeSignature, activeParameter };
2060
+ }
2061
+ async doCodeAction(uri, range, context, formatOptions) {
2062
+ const document2 = this._getTextDocument(uri);
2063
+ if (!document2) {
2064
+ return null;
2065
+ }
2066
+ const start = document2.offsetAt(range.start);
2067
+ const end = document2.offsetAt(range.end);
2068
+ const errorCodes = context.diagnostics.map((diagnostic) => diagnostic.code).filter(Boolean).map(Number);
2069
+ const codeFixes = await this._getCodeFixesAtPosition(uri, start, end, errorCodes, toTsFormatOptions(formatOptions));
2070
+ return codeFixes.map((codeFix) => {
2071
+ const action = {
2072
+ title: codeFix.description,
2073
+ kind: "quickfix"
2074
+ };
2075
+ if (codeFix.changes.length > 0) {
2076
+ const edits = [];
2077
+ for (const change of codeFix.changes) {
2078
+ for (const { span, newText } of change.textChanges) {
2079
+ edits.push({ range: createRangeFromDocumentSpan(document2, span), newText });
2080
+ }
2081
+ }
2082
+ action.edit = { changes: { [uri]: edits } };
2083
+ }
2084
+ if (codeFix.commands?.length) {
2085
+ const command = codeFix.commands[0];
2086
+ action.command = {
2087
+ title: command.title,
2088
+ command: command.id,
2089
+ arguments: command.arguments
2090
+ };
2091
+ }
2092
+ return action;
2093
+ });
2094
+ }
2095
+ async doRename(uri, position, newName) {
2096
+ const document2 = this._getTextDocument(uri);
2097
+ if (!document2) {
2098
+ return null;
2099
+ }
2100
+ const documentPosition = document2.offsetAt(position);
2101
+ const renameInfo = this._languageService.getRenameInfo(uri, documentPosition, { allowRenameOfImportPath: true });
2102
+ if (!renameInfo.canRename) {
2103
+ return null;
2104
+ }
2105
+ const locations = this._languageService.findRenameLocations(uri, documentPosition, false, false, {
2106
+ providePrefixAndSuffixTextForRename: false
2107
+ });
2108
+ if (!locations) {
2109
+ return null;
2110
+ }
2111
+ const changes = {};
2112
+ locations.map((loc) => {
2113
+ const edits = changes[loc.fileName] || (changes[loc.fileName] = []);
2114
+ const locDocument = this._getTextDocument(loc.fileName);
2115
+ if (locDocument) {
2116
+ edits.push({
2117
+ range: createRangeFromDocumentSpan(locDocument, loc.textSpan),
2118
+ newText: newName
2119
+ });
2120
+ }
2121
+ });
2122
+ return { changes };
2123
+ }
2124
+ async doFormat(uri, range, formatOptions, docText) {
2125
+ const document2 = docText ? TextDocument2.create(uri, "typescript", 0, docText) : this._getTextDocument(uri);
2126
+ if (!document2) {
2127
+ return null;
2128
+ }
2129
+ const formattingOptions = this._mergeFormatOptions(toTsFormatOptions(formatOptions));
2130
+ let edits;
2131
+ if (range) {
2132
+ const start = document2.offsetAt(range.start);
2133
+ const end = document2.offsetAt(range.end);
2134
+ edits = this._languageService.getFormattingEditsForRange(uri, start, end, formattingOptions);
2135
+ } else {
2136
+ edits = this._languageService.getFormattingEditsForDocument(uri, formattingOptions);
2137
+ }
2138
+ return edits.map(({ span, newText }) => ({
2139
+ range: createRangeFromDocumentSpan(document2, span),
2140
+ newText
2141
+ }));
2142
+ }
2143
+ async findDocumentSymbols(uri) {
2144
+ const document2 = this._getTextDocument(uri);
2145
+ if (!document2) {
2146
+ return null;
2147
+ }
2148
+ const toSymbol = (item, containerLabel) => {
2149
+ const result = {
2150
+ name: item.text,
2151
+ kind: convertTsSymbolKind(item.kind),
2152
+ range: createRangeFromDocumentSpan(document2, item.spans[0]),
2153
+ selectionRange: createRangeFromDocumentSpan(document2, item.spans[0]),
2154
+ children: item.childItems?.map((child) => toSymbol(child, item.text))
2155
+ };
2156
+ if (containerLabel) {
2157
+ Reflect.set(result, "containerName", containerLabel);
2158
+ }
2159
+ return result;
2160
+ };
2161
+ const root = this._languageService.getNavigationTree(uri);
2162
+ return root.childItems?.map((item) => toSymbol(item)) ?? null;
2163
+ }
2164
+ async findDefinition(uri, position) {
2165
+ const document2 = this._getTextDocument(uri);
2166
+ if (!document2) {
2167
+ return null;
2168
+ }
2169
+ const res = this._languageService.getDefinitionAndBoundSpan(uri, document2.offsetAt(position));
2170
+ if (res) {
2171
+ const { definitions, textSpan } = res;
2172
+ if (definitions) {
2173
+ return definitions.map((d) => {
2174
+ const targetDocument = d.fileName === uri ? document2 : this._getTextDocument(d.fileName);
2175
+ if (targetDocument) {
2176
+ const range = createRangeFromDocumentSpan(targetDocument, d.textSpan);
2177
+ const link = {
2178
+ targetUri: d.fileName,
2179
+ targetRange: range,
2180
+ targetSelectionRange: void 0
2181
+ };
2182
+ if (d.contextSpan) {
2183
+ link.targetRange = createRangeFromDocumentSpan(targetDocument, d.contextSpan);
2184
+ link.targetSelectionRange = range;
2185
+ }
2186
+ if (d.kind === "script" || d.kind === "module") {
2187
+ link.originSelectionRange = createRangeFromDocumentSpan(document2, {
2188
+ start: textSpan.start + 1,
2189
+ length: textSpan.length - 2
2190
+ });
2191
+ } else {
2192
+ link.originSelectionRange = createRangeFromDocumentSpan(document2, textSpan);
2193
+ }
2194
+ return link;
2195
+ }
2196
+ return void 0;
2197
+ }).filter((d) => d !== void 0);
2198
+ }
2199
+ }
2200
+ return null;
2201
+ }
2202
+ async findReferences(uri, position) {
2203
+ const document2 = this._getTextDocument(uri);
2204
+ if (!document2) {
2205
+ return null;
2206
+ }
2207
+ const references = this._languageService.getReferencesAtPosition(uri, document2.offsetAt(position));
2208
+ const result = [];
2209
+ if (references) {
2210
+ for (let entry of references) {
2211
+ const entryDocument = this._getTextDocument(entry.fileName);
2212
+ if (entryDocument) {
2213
+ result.push({
2214
+ uri: entryDocument.uri,
2215
+ range: createRangeFromDocumentSpan(entryDocument, entry.textSpan)
2216
+ });
2217
+ }
2218
+ }
2219
+ }
2220
+ return result;
2221
+ }
2222
+ async findDocumentHighlights(uri, position) {
2223
+ const document2 = this._getTextDocument(uri);
2224
+ if (!document2) {
2225
+ return null;
2226
+ }
2227
+ const highlights = this._languageService.getDocumentHighlights(uri, document2.offsetAt(position), [uri]);
2228
+ const out = [];
2229
+ for (const entry of highlights || []) {
2230
+ for (const highlight of entry.highlightSpans) {
2231
+ out.push({
2232
+ range: createRangeFromDocumentSpan(document2, highlight.textSpan),
2233
+ kind: highlight.kind === "writtenReference" ? DocumentHighlightKind.Write : DocumentHighlightKind.Text
2234
+ });
2235
+ }
2236
+ }
2237
+ return out;
2238
+ }
2239
+ async getFoldingRanges(uri) {
2240
+ const document2 = this._getTextDocument(uri);
2241
+ if (!document2) {
2242
+ return null;
2243
+ }
2244
+ const spans = this._languageService.getOutliningSpans(uri);
2245
+ const ranges = [];
2246
+ for (const span of spans) {
2247
+ const curr = createRangeFromDocumentSpan(document2, span.textSpan);
2248
+ const startLine = curr.start.line;
2249
+ const endLine = curr.end.line;
2250
+ if (startLine < endLine) {
2251
+ const foldingRange = { startLine, endLine };
2252
+ const match = document2.getText(curr).match(/^\s*\/(?:(\/\s*#(?:end)?region\b)|(\*|\/))/);
2253
+ if (match) {
2254
+ foldingRange.kind = match[1] ? FoldingRangeKind.Region : FoldingRangeKind.Comment;
2255
+ }
2256
+ ranges.push(foldingRange);
2257
+ }
2258
+ }
2259
+ return ranges;
2260
+ }
2261
+ async getSelectionRanges(uri, positions) {
2262
+ const document2 = this._getTextDocument(uri);
2263
+ if (!document2) {
2264
+ return null;
2265
+ }
2266
+ function convertSelectionRange(selectionRange) {
2267
+ const parent = selectionRange.parent ? convertSelectionRange(selectionRange.parent) : void 0;
2268
+ return SelectionRange.create(createRangeFromDocumentSpan(document2, selectionRange.textSpan), parent);
2269
+ }
2270
+ return positions.map((position) => {
2271
+ const range = this._languageService.getSmartSelectionRange(uri, document2.offsetAt(position));
2272
+ return convertSelectionRange(range);
2273
+ });
2274
+ }
2275
+ // #endregion
2276
+ // #region public methods used by the host
2277
+ async fetchHttpModule(specifier, containingFile) {
2278
+ if (this._unknownImports.has(specifier)) {
2279
+ const res = await cache.fetch(specifier);
2280
+ res.body?.cancel();
2281
+ this._unknownImports.delete(specifier);
2282
+ if (!res.ok) {
2283
+ this._badImports.add(specifier);
2284
+ }
2285
+ this._rollbackVersion(containingFile);
2286
+ this.host.refreshDiagnostics(containingFile);
2287
+ }
2288
+ }
2289
+ async updateCompilerOptions(options) {
2290
+ const { compilerOptions, importMap, types } = options;
2291
+ if (compilerOptions) {
2292
+ this._compilerOptions = ts.convertCompilerOptionsFromJson(compilerOptions, ".").options;
2293
+ this._updateJsxImportSource();
2294
+ }
2295
+ if (importMap) {
2296
+ this._importMap = importMap;
2297
+ this._importMapVersion++;
2298
+ this._isBlankImportMap = isBlankImportMap(importMap);
2299
+ this._updateJsxImportSource();
2300
+ }
2301
+ if (types) {
2302
+ for (const uri of Object.keys(this._types)) {
2303
+ if (!(uri in types)) {
2304
+ this.removeDocumentCache(uri);
2305
+ }
2306
+ }
2307
+ this._types = types;
2308
+ }
2309
+ }
2310
+ // #endregion
2311
+ // #region private methods
2312
+ _getCompletionsAtPosition(fileName, position) {
2313
+ const completions = this._languageService.getCompletionsAtPosition(
2314
+ fileName,
2315
+ position,
2316
+ {
2317
+ quotePreference: this._formatOptions?.quotePreference,
2318
+ allowRenameOfImportPath: true,
2319
+ importModuleSpecifierEnding: "js",
2320
+ importModuleSpecifierPreference: "shortest",
2321
+ includeCompletionsForModuleExports: true,
2322
+ includeCompletionsForImportStatements: true,
2323
+ includePackageJsonAutoImports: "off",
2324
+ organizeImportsIgnoreCase: false
2325
+ }
2326
+ );
2327
+ if (completions) {
2328
+ const autoImports = /* @__PURE__ */ new Set();
2329
+ completions.entries = completions.entries.filter((entry) => {
2330
+ const { data } = entry;
2331
+ if (!data || !data.fileName || !isDts(data.fileName)) {
2332
+ return true;
2333
+ }
2334
+ const { moduleSpecifier, exportName } = data;
2335
+ if (moduleSpecifier && (moduleSpecifier in this._importMap.imports || this._typesMappings.has(moduleSpecifier))) {
2336
+ autoImports.add(exportName + " " + moduleSpecifier);
2337
+ return true;
2338
+ }
2339
+ const specifier = this._getSpecifierFromDts(data.fileName);
2340
+ if (specifier && !autoImports.has(exportName + " " + specifier)) {
2341
+ autoImports.add(exportName + " " + specifier);
2342
+ return true;
2343
+ }
2344
+ return false;
2345
+ });
2346
+ return completions;
2347
+ }
2348
+ return void 0;
2349
+ }
2350
+ _getCompletionEntryDetails(fileName, position, entryName, data) {
2351
+ try {
2352
+ const detail = this._languageService.getCompletionEntryDetails(
2353
+ fileName,
2354
+ position,
2355
+ entryName,
2356
+ {
2357
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: true,
2358
+ semicolons: ts.SemicolonPreference.Insert
2359
+ },
2360
+ void 0,
2361
+ void 0,
2362
+ data
2363
+ );
2364
+ detail?.codeActions?.forEach((action) => {
2365
+ if (action.description.startsWith("Add import from ")) {
2366
+ const specifier = action.description.slice(17, -1);
2367
+ const newSpecifier = this._getSpecifierFromDts(isDts(specifier) ? specifier : specifier + ".d.ts");
2368
+ if (newSpecifier) {
2369
+ action.description = `Add type import from "${newSpecifier}"`;
2370
+ action.changes.forEach((change) => {
2371
+ change.textChanges.forEach((textChange) => {
2372
+ textChange.newText = textChange.newText.replace(
2373
+ specifier,
2374
+ newSpecifier
2375
+ );
2376
+ });
2377
+ });
2378
+ }
2379
+ }
2380
+ });
2381
+ return detail;
2382
+ } catch (error) {
2383
+ return;
2384
+ }
2385
+ }
2386
+ _getQuickInfoAtPosition(fileName, position) {
2387
+ const info = this._languageService.getQuickInfoAtPosition(fileName, position);
2388
+ if (!info) {
2389
+ return;
2390
+ }
2391
+ const { kind, kindModifiers, displayParts, textSpan } = info;
2392
+ if (kind === ts.ScriptElementKind.moduleElement && displayParts?.length === 3) {
2393
+ const moduleName = displayParts[2].text;
2394
+ if (moduleName.startsWith('"file:') && fileName.startsWith("file:")) {
2395
+ const literalText = this.getModel(fileName)?.getValue().substring(
2396
+ textSpan.start,
2397
+ textSpan.start + textSpan.length
2398
+ );
2399
+ if (literalText) {
2400
+ try {
2401
+ const specifier = JSON.parse(literalText);
2402
+ displayParts[2].text = '"' + new URL(specifier, fileName).pathname + '"';
2403
+ } catch (error) {
2404
+ }
2405
+ }
2406
+ } else if (
2407
+ // show module url for `http:` specifiers instead of the types url
2408
+ kindModifiers === "declare" && moduleName.startsWith('"http')
2409
+ ) {
2410
+ const specifier = JSON.parse(moduleName);
2411
+ for (const [url, dts] of this._typesMappings) {
2412
+ if (specifier + ".d.ts" === dts) {
2413
+ displayParts[2].text = '"' + url + '"';
2414
+ info.tags = [{
2415
+ name: "types",
2416
+ text: [{ kind: "text", text: dts }]
2417
+ }];
2418
+ const { pathname, hostname } = new URL(url);
2419
+ if (isEsmshHost(hostname)) {
2420
+ const pathSegments = pathname.split("/").slice(1);
2421
+ if (/^v\d+$/.test(pathSegments[0])) {
2422
+ pathSegments.shift();
2423
+ }
2424
+ let scope = "";
2425
+ let pkgName = pathSegments.shift();
2426
+ if (pkgName?.startsWith("@")) {
2427
+ scope = pkgName;
2428
+ pkgName = pathSegments.shift();
2429
+ }
2430
+ if (!pkgName) {
2431
+ continue;
2432
+ }
2433
+ const npmPkgId = [scope, pkgName.split("@")[0]].filter(Boolean).join("/");
2434
+ const npmPkgUrl = `https://www.npmjs.com/package/${npmPkgId}`;
2435
+ info.tags.unshift({
2436
+ name: "npm",
2437
+ text: [{ kind: "text", text: `[${npmPkgId}](${npmPkgUrl})` }]
2438
+ });
2439
+ }
2440
+ break;
2441
+ }
2442
+ }
2443
+ }
2444
+ }
2445
+ return info;
2446
+ }
2447
+ async _getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions) {
2448
+ let span = [start + 1, end - 1];
2449
+ if (start === end && (this._redirectedImports.length > 0 || errorCodes.includes(2307))) {
2450
+ const a = this._languageService.getReferencesAtPosition(fileName, start);
2451
+ if (a && a.length > 0) {
2452
+ const b = a[0];
2453
+ span = [b.textSpan.start, b.textSpan.start + b.textSpan.length];
2454
+ }
2455
+ }
2456
+ const fixes = [];
2457
+ if (this._redirectedImports.length > 0) {
2458
+ const i = this._redirectedImports.findIndex(([modelUrl, node]) => {
2459
+ return fileName === modelUrl && node.getStart() === span[0] - 1 && node.getEnd() === span[1] + 1;
2460
+ });
2461
+ if (i >= 0) {
2462
+ const [_, node, url] = this._redirectedImports[i];
2463
+ const fixName = `Update module specifier to ${url}`;
2464
+ fixes.push({
2465
+ fixName,
2466
+ description: fixName,
2467
+ changes: [{
2468
+ fileName,
2469
+ textChanges: [{
2470
+ span: { start: node.getStart(), length: node.getWidth() },
2471
+ newText: JSON.stringify(url)
2472
+ }]
2473
+ }]
2474
+ });
2475
+ }
2476
+ }
2477
+ if (errorCodes.includes(2307)) {
2478
+ const specifier = this.getModel(fileName)?.getValue().slice(...span);
2479
+ if (specifier) {
2480
+ if (this._unknownImports.has(specifier)) {
2481
+ const fixName = `Fetch module from '${specifier}'`;
2482
+ fixes.push({
2483
+ fixName,
2484
+ description: fixName,
2485
+ changes: [],
2486
+ commands: [{
2487
+ id: "ts:fetch_http_module",
2488
+ title: "Fetch the module from internet",
2489
+ arguments: [specifier, fileName]
2490
+ }]
2491
+ });
2492
+ }
2493
+ }
2494
+ }
2495
+ try {
2496
+ const tsFixes = this._languageService.getCodeFixesAtPosition(
2497
+ fileName,
2498
+ start,
2499
+ end,
2500
+ errorCodes,
2501
+ this._mergeFormatOptions(formatOptions),
2502
+ {}
2503
+ );
2504
+ return fixes.concat(tsFixes);
2505
+ } catch (err) {
2506
+ return fixes;
2507
+ }
2508
+ }
2509
+ /** rollback the version to force reinvoke `resolveModuleNameLiterals` method. */
2510
+ _rollbackVersion(fileName) {
2511
+ const model = this.getModel(fileName);
2512
+ if (model) {
2513
+ model._versionId--;
2514
+ }
2515
+ }
2516
+ _getScriptText(fileName) {
2517
+ return libs[fileName] ?? libs[`lib.${fileName}.d.ts`] ?? this._types[fileName]?.content ?? this._httpLibs.get(fileName) ?? this._httpModules.get(fileName) ?? this._httpTsModules.get(fileName) ?? this.getModel(fileName)?.getValue();
2518
+ }
2519
+ _getTextDocument(uri) {
2520
+ const doc = this.getTextDocument(uri);
2521
+ if (doc) {
2522
+ return doc;
2523
+ }
2524
+ if (uri.startsWith("http://") || uri.startsWith("https://")) {
2525
+ const docCache = this._httpDocumentCache;
2526
+ if (docCache.has(uri)) {
2527
+ return docCache.get(uri);
2528
+ }
2529
+ const scriptText = this._getScriptText(uri);
2530
+ if (scriptText) {
2531
+ const doc2 = TextDocument2.create(uri, "typescript", 1, scriptText);
2532
+ docCache.set(uri, doc2);
2533
+ return doc2;
2534
+ }
2535
+ }
2536
+ return null;
2537
+ }
2538
+ _markHttpLib(url, dtsContent) {
2539
+ this._httpLibs.set(url, dtsContent);
2540
+ setTimeout(() => {
2541
+ const referencedFiles = this._languageService.getProgram()?.getSourceFile(url)?.referencedFiles ?? [];
2542
+ referencedFiles.forEach((ref) => {
2543
+ const refUrl = new URL(ref.fileName, url).href;
2544
+ if (isDts(refUrl) && !this._fetchPromises.has(refUrl) && !this._httpLibs.has(refUrl) && !this._badImports.has(refUrl)) {
2545
+ this._fetchPromises.set(
2546
+ refUrl,
2547
+ cache.fetch(refUrl).then(async (res) => {
2548
+ if (res.ok) {
2549
+ this._httpLibs.set(refUrl, await res.text());
2550
+ } else {
2551
+ this._badImports.add(refUrl);
2552
+ }
2553
+ }).catch((err) => {
2554
+ console.error(`Failed to fetch types: ${refUrl}`, err);
2555
+ }).finally(() => {
2556
+ this._fetchPromises.delete(refUrl);
2557
+ })
2558
+ );
2559
+ }
2560
+ });
2561
+ });
2562
+ }
2563
+ _getSpecifierFromDts(filename) {
2564
+ for (const [specifier, dts] of this._typesMappings) {
2565
+ if (filename === dts) {
2566
+ if (!this._isBlankImportMap) {
2567
+ for (const [key, value] of Object.entries(this._importMap.imports)) {
2568
+ if (value === specifier && key !== "@jsxRuntime") {
2569
+ return key;
2570
+ }
2571
+ }
2572
+ }
2573
+ return specifier;
2574
+ }
2575
+ }
2576
+ }
2577
+ _convertDiagnostic(document2, diagnostic) {
2578
+ const tags = [];
2579
+ if (diagnostic.reportsUnnecessary) {
2580
+ tags.push(DiagnosticTag.Unnecessary);
2581
+ }
2582
+ if (diagnostic.reportsDeprecated) {
2583
+ tags.push(DiagnosticTag.Deprecated);
2584
+ }
2585
+ return {
2586
+ range: createRangeFromDocumentSpan(document2, diagnostic),
2587
+ code: diagnostic.code,
2588
+ severity: convertTsDiagnosticCategory(diagnostic.category),
2589
+ message: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
2590
+ source: diagnostic.source,
2591
+ tags,
2592
+ relatedInformation: this._convertRelatedInformation(document2, diagnostic.relatedInformation)
2593
+ };
2594
+ }
2595
+ _convertRelatedInformation(document2, relatedInformation) {
2596
+ if (!relatedInformation) {
2597
+ return [];
2598
+ }
2599
+ const result = [];
2600
+ relatedInformation.forEach((info) => {
2601
+ const doc = info.file ? this._getTextDocument(info.file.fileName) : document2;
2602
+ if (!doc) {
2603
+ return;
2604
+ }
2605
+ const start = doc.positionAt(info.start ?? 0);
2606
+ const end = doc.positionAt((info.start ?? 0) + (info.length ?? 1));
2607
+ result.push({
2608
+ location: {
2609
+ uri: document2.uri,
2610
+ range: Range.create(start, end)
2611
+ },
2612
+ message: ts.flattenDiagnosticMessageText(info.messageText, "\n")
2613
+ });
2614
+ });
2615
+ return result;
2616
+ }
2617
+ _getJsxImportSource() {
2618
+ const { imports } = this._importMap;
2619
+ for (const specifier of ["@jsxRuntime", "@jsxImportSource", "preact", "react"]) {
2620
+ if (specifier in imports) {
2621
+ return imports[specifier];
2622
+ }
2623
+ }
2624
+ return void 0;
2625
+ }
2626
+ _updateJsxImportSource() {
2627
+ if (!this._compilerOptions.jsxImportSource) {
2628
+ const jsxImportSource = this._getJsxImportSource();
2629
+ if (jsxImportSource) {
2630
+ this._compilerOptions.jsx = ts.JsxEmit.React;
2631
+ this._compilerOptions.jsxImportSource = jsxImportSource;
2632
+ }
2633
+ }
2634
+ }
2635
+ _mergeFormatOptions(formatOptions) {
2636
+ return { ...this._formatOptions, ...formatOptions };
2637
+ }
2638
+ _isJsxImportUrl(url) {
2639
+ const jsxImportUrl = this._getJsxImportSource();
2640
+ if (jsxImportUrl) {
2641
+ return url === jsxImportUrl + "/jsx-runtime" || url === jsxImportUrl + "/jsx-dev-runtime";
2642
+ }
2643
+ return false;
2644
+ }
2645
+ // #endregion
2646
+ };
2647
+ function getScriptExtension(url) {
2648
+ const pathname = typeof url === "string" ? pathToUrl(url).pathname : url.pathname;
2649
+ const basename = pathname.substring(pathname.lastIndexOf("/") + 1);
2650
+ const dotIndex = basename.lastIndexOf(".");
2651
+ if (dotIndex === -1) {
2652
+ return null;
2653
+ }
2654
+ const ext = basename.substring(dotIndex + 1);
2655
+ switch (ext) {
2656
+ case "ts":
2657
+ return basename.endsWith(".d.ts") ? ".d.ts" : ".ts";
2658
+ case "mts":
2659
+ return basename.endsWith(".d.mts") ? ".d.mts" : ".mts";
2660
+ case "cts":
2661
+ return basename.endsWith(".d.cts") ? ".d.cts" : ".cts";
2662
+ case "tsx":
2663
+ return ".tsx";
2664
+ case "js":
2665
+ return ".js";
2666
+ case "mjs":
2667
+ return ".js";
2668
+ case "cjs":
2669
+ return ".cjs";
2670
+ case "jsx":
2671
+ return ".jsx";
2672
+ case "json":
2673
+ return ".json";
2674
+ default:
2675
+ return ".js";
2676
+ }
2677
+ }
2678
+ function isHttpUrl(url) {
2679
+ return url.startsWith("http://") || url.startsWith("https://");
2680
+ }
2681
+ function isRelativePath(path) {
2682
+ return path.startsWith("./") || path.startsWith("../");
2683
+ }
2684
+ function isEsmshHost(hostname) {
2685
+ return hostname === "esm.sh" || hostname.endsWith(".esm.sh");
2686
+ }
2687
+ var regexpPackagePath = /\/((@|gh\/|pr\/|jsr\/@)[\w\.\-]+\/)?[\w\.\-]+@(\d+(\.\d+){0,2}(\-[\w\.]+)?|next|canary|rc|beta|latest)$/;
2688
+ function isWellKnownCDNURL(url) {
2689
+ const { pathname } = url;
2690
+ return regexpPackagePath.test(pathname);
2691
+ }
2692
+ function isDts(fileName) {
2693
+ return fileName.endsWith(".d.ts") || fileName.endsWith(".d.mts") || fileName.endsWith(".d.cts");
2694
+ }
2695
+ function pathToUrl(path) {
2696
+ return new URL(path, "file:///");
2697
+ }
2698
+ function createRangeFromDocumentSpan(document2, span) {
2699
+ if (typeof span.start === "undefined") {
2700
+ const pos = document2.positionAt(0);
2701
+ return Range.create(pos, pos);
2702
+ }
2703
+ const start = document2.positionAt(span.start);
2704
+ const end = document2.positionAt(span.start + (span.length ?? 0));
2705
+ return Range.create(start, end);
2706
+ }
2707
+ function convertTsCompletionItemKind(kind) {
2708
+ const ScriptElementKind = ts.ScriptElementKind;
2709
+ switch (kind) {
2710
+ case ScriptElementKind.primitiveType:
2711
+ case ScriptElementKind.keyword:
2712
+ return CompletionItemKind.Keyword;
2713
+ case ScriptElementKind.constElement:
2714
+ case ScriptElementKind.letElement:
2715
+ case ScriptElementKind.variableElement:
2716
+ case ScriptElementKind.localVariableElement:
2717
+ case ScriptElementKind.alias:
2718
+ case ScriptElementKind.parameterElement:
2719
+ return CompletionItemKind.Variable;
2720
+ case ScriptElementKind.memberVariableElement:
2721
+ case ScriptElementKind.memberGetAccessorElement:
2722
+ case ScriptElementKind.memberSetAccessorElement:
2723
+ return CompletionItemKind.Field;
2724
+ case ScriptElementKind.functionElement:
2725
+ case ScriptElementKind.localFunctionElement:
2726
+ return CompletionItemKind.Function;
2727
+ case ScriptElementKind.memberFunctionElement:
2728
+ case ScriptElementKind.constructSignatureElement:
2729
+ case ScriptElementKind.callSignatureElement:
2730
+ case ScriptElementKind.indexSignatureElement:
2731
+ return CompletionItemKind.Method;
2732
+ case ScriptElementKind.enumElement:
2733
+ return CompletionItemKind.Enum;
2734
+ case ScriptElementKind.enumMemberElement:
2735
+ return CompletionItemKind.EnumMember;
2736
+ case ScriptElementKind.moduleElement:
2737
+ case ScriptElementKind.externalModuleName:
2738
+ return CompletionItemKind.Module;
2739
+ case ScriptElementKind.classElement:
2740
+ case ScriptElementKind.typeElement:
2741
+ return CompletionItemKind.Class;
2742
+ case ScriptElementKind.interfaceElement:
2743
+ return CompletionItemKind.Interface;
2744
+ case ScriptElementKind.warning:
2745
+ return CompletionItemKind.Text;
2746
+ case ScriptElementKind.scriptElement:
2747
+ return CompletionItemKind.File;
2748
+ case ScriptElementKind.directory:
2749
+ return CompletionItemKind.Folder;
2750
+ case ScriptElementKind.string:
2751
+ return CompletionItemKind.Constant;
2752
+ default:
2753
+ return CompletionItemKind.Property;
2754
+ }
2755
+ }
2756
+ function convertTsSymbolKind(kind) {
2757
+ const Kind = ts.ScriptElementKind;
2758
+ switch (kind) {
2759
+ case Kind.memberVariableElement:
2760
+ case Kind.memberGetAccessorElement:
2761
+ case Kind.memberSetAccessorElement:
2762
+ return SymbolKind.Field;
2763
+ case Kind.functionElement:
2764
+ case Kind.localFunctionElement:
2765
+ return SymbolKind.Function;
2766
+ case Kind.memberFunctionElement:
2767
+ case Kind.constructSignatureElement:
2768
+ case Kind.callSignatureElement:
2769
+ case Kind.indexSignatureElement:
2770
+ return SymbolKind.Method;
2771
+ case Kind.enumElement:
2772
+ return SymbolKind.Enum;
2773
+ case Kind.enumMemberElement:
2774
+ return SymbolKind.EnumMember;
2775
+ case Kind.moduleElement:
2776
+ case Kind.externalModuleName:
2777
+ return SymbolKind.Module;
2778
+ case Kind.classElement:
2779
+ case Kind.typeElement:
2780
+ return SymbolKind.Class;
2781
+ case Kind.interfaceElement:
2782
+ return SymbolKind.Interface;
2783
+ case Kind.scriptElement:
2784
+ return SymbolKind.File;
2785
+ case Kind.string:
2786
+ return SymbolKind.Constant;
2787
+ default:
2788
+ return SymbolKind.Variable;
2789
+ }
2790
+ }
2791
+ function convertTsDiagnosticCategory(category) {
2792
+ switch (category) {
2793
+ case ts.DiagnosticCategory.Error:
2794
+ return DiagnosticSeverity.Error;
2795
+ case ts.DiagnosticCategory.Message:
2796
+ return DiagnosticSeverity.Information;
2797
+ case ts.DiagnosticCategory.Warning:
2798
+ return DiagnosticSeverity.Warning;
2799
+ case ts.DiagnosticCategory.Suggestion:
2800
+ return DiagnosticSeverity.Hint;
2801
+ }
2802
+ return DiagnosticSeverity.Information;
2803
+ }
2804
+ function tagStringify(tag) {
2805
+ let tagLabel = `*@${tag.name}*`;
2806
+ if (tag.name === "param" && tag.text) {
2807
+ const [paramName, ...rest] = tag.text;
2808
+ tagLabel += `\`${paramName.text}\``;
2809
+ if (rest.length > 0) tagLabel += ` \u2014 ${rest.map((r) => r.text).join(" ")}`;
2810
+ } else if (Array.isArray(tag.text)) {
2811
+ tagLabel += ` \u2014 ${tag.text.map((r) => r.text).join("")}`;
2812
+ } else if (tag.text) {
2813
+ tagLabel += ` \u2014 ${tag.text}`;
2814
+ }
2815
+ return tagLabel;
2816
+ }
2817
+ function toTsSignatureHelpTriggerReason(context) {
2818
+ switch (context.triggerKind) {
2819
+ case 3:
2820
+ return context.isRetrigger ? { kind: "retrigger" } : { kind: "invoked" };
2821
+ case 2:
2822
+ if (context.triggerCharacter) {
2823
+ if (context.isRetrigger) {
2824
+ return {
2825
+ kind: "retrigger",
2826
+ triggerCharacter: context.triggerCharacter
2827
+ };
2828
+ } else {
2829
+ return {
2830
+ kind: "characterTyped",
2831
+ triggerCharacter: context.triggerCharacter
2832
+ };
2833
+ }
2834
+ } else {
2835
+ return { kind: "invoked" };
2836
+ }
2837
+ case 1:
2838
+ default:
2839
+ return { kind: "invoked" };
2840
+ }
2841
+ }
2842
+ function toTsFormatOptions({ tabSize, trimTrailingWhitespace, insertSpaces }) {
2843
+ return {
2844
+ tabSize,
2845
+ trimTrailingWhitespace,
2846
+ indentSize: tabSize,
2847
+ convertTabsToSpaces: insertSpaces,
2848
+ insertSpaceAfterCommaDelimiter: insertSpaces,
2849
+ insertSpaceAfterSemicolonInForStatements: insertSpaces,
2850
+ insertSpaceBeforeAndAfterBinaryOperators: insertSpaces,
2851
+ insertSpaceAfterKeywordsInControlFlowStatements: insertSpaces,
2852
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: insertSpaces
2853
+ };
2854
+ }
2855
+ initializeWorker(TypeScriptWorker);
2856
+ export {
2857
+ TypeScriptWorker
2858
+ };