@codingame/monaco-vscode-standalone-html-language-features 23.1.1 → 23.2.1

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,644 @@
1
+ import { InsertTextFormat, CompletionItemKind, DocumentHighlightKind, SymbolKind, FoldingRangeKind, DiagnosticSeverity } from 'vscode-languageserver-types';
2
+ import { Range, languages, editor, Uri, MarkerSeverity } from 'monaco-editor';
3
+
4
+ class DiagnosticsAdapter {
5
+ constructor(_languageId, _worker, configChangeEvent) {
6
+ this._languageId = _languageId;
7
+ this._worker = _worker;
8
+ this._disposables = [];
9
+ this._listener = /* @__PURE__ */ Object.create(null);
10
+ const onModelAdd = (model) => {
11
+ let modeId = model.getLanguageId();
12
+ if (modeId !== this._languageId) {
13
+ return;
14
+ }
15
+ let handle;
16
+ this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
17
+ window.clearTimeout(handle);
18
+ handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
19
+ });
20
+ this._doValidate(model.uri, modeId);
21
+ };
22
+ const onModelRemoved = (model) => {
23
+ editor.setModelMarkers(model, this._languageId, []);
24
+ let uriStr = model.uri.toString();
25
+ let listener = this._listener[uriStr];
26
+ if (listener) {
27
+ listener.dispose();
28
+ delete this._listener[uriStr];
29
+ }
30
+ };
31
+ this._disposables.push(editor.onDidCreateModel(onModelAdd));
32
+ this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
33
+ this._disposables.push(
34
+ editor.onDidChangeModelLanguage((event) => {
35
+ onModelRemoved(event.model);
36
+ onModelAdd(event.model);
37
+ })
38
+ );
39
+ this._disposables.push(
40
+ configChangeEvent((_) => {
41
+ editor.getModels().forEach((model) => {
42
+ if (model.getLanguageId() === this._languageId) {
43
+ onModelRemoved(model);
44
+ onModelAdd(model);
45
+ }
46
+ });
47
+ })
48
+ );
49
+ this._disposables.push({
50
+ dispose: () => {
51
+ editor.getModels().forEach(onModelRemoved);
52
+ for (let key in this._listener) {
53
+ this._listener[key].dispose();
54
+ }
55
+ }
56
+ });
57
+ editor.getModels().forEach(onModelAdd);
58
+ }
59
+ dispose() {
60
+ this._disposables.forEach((d) => d && d.dispose());
61
+ this._disposables.length = 0;
62
+ }
63
+ _doValidate(resource, languageId) {
64
+ this._worker(resource).then((worker) => {
65
+ return worker.doValidation(resource.toString());
66
+ }).then((diagnostics) => {
67
+ const markers = diagnostics.map((d) => toDiagnostics(resource, d));
68
+ let model = editor.getModel(resource);
69
+ if (model && model.getLanguageId() === languageId) {
70
+ editor.setModelMarkers(model, languageId, markers);
71
+ }
72
+ }).then(void 0, (err) => {
73
+ console.error(err);
74
+ });
75
+ }
76
+ }
77
+ function toSeverity(lsSeverity) {
78
+ switch (lsSeverity) {
79
+ case DiagnosticSeverity.Error:
80
+ return MarkerSeverity.Error;
81
+ case DiagnosticSeverity.Warning:
82
+ return MarkerSeverity.Warning;
83
+ case DiagnosticSeverity.Information:
84
+ return MarkerSeverity.Info;
85
+ case DiagnosticSeverity.Hint:
86
+ return MarkerSeverity.Hint;
87
+ default:
88
+ return MarkerSeverity.Info;
89
+ }
90
+ }
91
+ function toDiagnostics(resource, diag) {
92
+ let code = typeof diag.code === "number" ? String(diag.code) : diag.code;
93
+ return {
94
+ severity: toSeverity(diag.severity),
95
+ startLineNumber: diag.range.start.line + 1,
96
+ startColumn: diag.range.start.character + 1,
97
+ endLineNumber: diag.range.end.line + 1,
98
+ endColumn: diag.range.end.character + 1,
99
+ message: diag.message,
100
+ code,
101
+ source: diag.source
102
+ };
103
+ }
104
+ class CompletionAdapter {
105
+ constructor(_worker, _triggerCharacters) {
106
+ this._worker = _worker;
107
+ this._triggerCharacters = _triggerCharacters;
108
+ }
109
+ get triggerCharacters() {
110
+ return this._triggerCharacters;
111
+ }
112
+ provideCompletionItems(model, position, context, token) {
113
+ const resource = model.uri;
114
+ return this._worker(resource).then((worker) => {
115
+ return worker.doComplete(resource.toString(), fromPosition(position));
116
+ }).then((info) => {
117
+ if (!info) {
118
+ return;
119
+ }
120
+ const wordInfo = model.getWordUntilPosition(position);
121
+ const wordRange = new Range(
122
+ position.lineNumber,
123
+ wordInfo.startColumn,
124
+ position.lineNumber,
125
+ wordInfo.endColumn
126
+ );
127
+ const items = info.items.map((entry) => {
128
+ const item = {
129
+ label: entry.label,
130
+ insertText: entry.insertText || entry.label,
131
+ sortText: entry.sortText,
132
+ filterText: entry.filterText,
133
+ documentation: entry.documentation,
134
+ detail: entry.detail,
135
+ command: toCommand(entry.command),
136
+ range: wordRange,
137
+ kind: toCompletionItemKind(entry.kind)
138
+ };
139
+ if (entry.textEdit) {
140
+ if (isInsertReplaceEdit(entry.textEdit)) {
141
+ item.range = {
142
+ insert: toRange(entry.textEdit.insert),
143
+ replace: toRange(entry.textEdit.replace)
144
+ };
145
+ } else {
146
+ item.range = toRange(entry.textEdit.range);
147
+ }
148
+ item.insertText = entry.textEdit.newText;
149
+ }
150
+ if (entry.additionalTextEdits) {
151
+ item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
152
+ }
153
+ if (entry.insertTextFormat === InsertTextFormat.Snippet) {
154
+ item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
155
+ }
156
+ return item;
157
+ });
158
+ return {
159
+ isIncomplete: info.isIncomplete,
160
+ suggestions: items
161
+ };
162
+ });
163
+ }
164
+ }
165
+ function fromPosition(position) {
166
+ if (!position) {
167
+ return void 0;
168
+ }
169
+ return { character: position.column - 1, line: position.lineNumber - 1 };
170
+ }
171
+ function fromRange(range) {
172
+ if (!range) {
173
+ return void 0;
174
+ }
175
+ return {
176
+ start: {
177
+ line: range.startLineNumber - 1,
178
+ character: range.startColumn - 1
179
+ },
180
+ end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
181
+ };
182
+ }
183
+ function toRange(range) {
184
+ if (!range) {
185
+ return void 0;
186
+ }
187
+ return new Range(
188
+ range.start.line + 1,
189
+ range.start.character + 1,
190
+ range.end.line + 1,
191
+ range.end.character + 1
192
+ );
193
+ }
194
+ function isInsertReplaceEdit(edit) {
195
+ return typeof edit.insert !== "undefined" && typeof edit.replace !== "undefined";
196
+ }
197
+ function toCompletionItemKind(kind) {
198
+ const mItemKind = languages.CompletionItemKind;
199
+ switch (kind) {
200
+ case CompletionItemKind.Text:
201
+ return mItemKind.Text;
202
+ case CompletionItemKind.Method:
203
+ return mItemKind.Method;
204
+ case CompletionItemKind.Function:
205
+ return mItemKind.Function;
206
+ case CompletionItemKind.Constructor:
207
+ return mItemKind.Constructor;
208
+ case CompletionItemKind.Field:
209
+ return mItemKind.Field;
210
+ case CompletionItemKind.Variable:
211
+ return mItemKind.Variable;
212
+ case CompletionItemKind.Class:
213
+ return mItemKind.Class;
214
+ case CompletionItemKind.Interface:
215
+ return mItemKind.Interface;
216
+ case CompletionItemKind.Module:
217
+ return mItemKind.Module;
218
+ case CompletionItemKind.Property:
219
+ return mItemKind.Property;
220
+ case CompletionItemKind.Unit:
221
+ return mItemKind.Unit;
222
+ case CompletionItemKind.Value:
223
+ return mItemKind.Value;
224
+ case CompletionItemKind.Enum:
225
+ return mItemKind.Enum;
226
+ case CompletionItemKind.Keyword:
227
+ return mItemKind.Keyword;
228
+ case CompletionItemKind.Snippet:
229
+ return mItemKind.Snippet;
230
+ case CompletionItemKind.Color:
231
+ return mItemKind.Color;
232
+ case CompletionItemKind.File:
233
+ return mItemKind.File;
234
+ case CompletionItemKind.Reference:
235
+ return mItemKind.Reference;
236
+ }
237
+ return mItemKind.Property;
238
+ }
239
+ function toTextEdit(textEdit) {
240
+ if (!textEdit) {
241
+ return void 0;
242
+ }
243
+ return {
244
+ range: toRange(textEdit.range),
245
+ text: textEdit.newText
246
+ };
247
+ }
248
+ function toCommand(c) {
249
+ return c && c.command === "editor.action.triggerSuggest" ? { id: c.command, title: c.title, arguments: c.arguments } : void 0;
250
+ }
251
+ class HoverAdapter {
252
+ constructor(_worker) {
253
+ this._worker = _worker;
254
+ }
255
+ provideHover(model, position, token) {
256
+ let resource = model.uri;
257
+ return this._worker(resource).then((worker) => {
258
+ return worker.doHover(resource.toString(), fromPosition(position));
259
+ }).then((info) => {
260
+ if (!info) {
261
+ return;
262
+ }
263
+ return {
264
+ range: toRange(info.range),
265
+ contents: toMarkedStringArray(info.contents)
266
+ };
267
+ });
268
+ }
269
+ }
270
+ function isMarkupContent(thing) {
271
+ return thing && typeof thing === "object" && typeof thing.kind === "string";
272
+ }
273
+ function toMarkdownString(entry) {
274
+ if (typeof entry === "string") {
275
+ return {
276
+ value: entry
277
+ };
278
+ }
279
+ if (isMarkupContent(entry)) {
280
+ if (entry.kind === "plaintext") {
281
+ return {
282
+ value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
283
+ };
284
+ }
285
+ return {
286
+ value: entry.value
287
+ };
288
+ }
289
+ return { value: "```" + entry.language + "\n" + entry.value + "\n```\n" };
290
+ }
291
+ function toMarkedStringArray(contents) {
292
+ if (!contents) {
293
+ return void 0;
294
+ }
295
+ if (Array.isArray(contents)) {
296
+ return contents.map(toMarkdownString);
297
+ }
298
+ return [toMarkdownString(contents)];
299
+ }
300
+ class DocumentHighlightAdapter {
301
+ constructor(_worker) {
302
+ this._worker = _worker;
303
+ }
304
+ provideDocumentHighlights(model, position, token) {
305
+ const resource = model.uri;
306
+ return this._worker(resource).then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then((entries) => {
307
+ if (!entries) {
308
+ return;
309
+ }
310
+ return entries.map((entry) => {
311
+ return {
312
+ range: toRange(entry.range),
313
+ kind: toDocumentHighlightKind(entry.kind)
314
+ };
315
+ });
316
+ });
317
+ }
318
+ }
319
+ function toDocumentHighlightKind(kind) {
320
+ switch (kind) {
321
+ case DocumentHighlightKind.Read:
322
+ return languages.DocumentHighlightKind.Read;
323
+ case DocumentHighlightKind.Write:
324
+ return languages.DocumentHighlightKind.Write;
325
+ case DocumentHighlightKind.Text:
326
+ return languages.DocumentHighlightKind.Text;
327
+ }
328
+ return languages.DocumentHighlightKind.Text;
329
+ }
330
+ class DefinitionAdapter {
331
+ constructor(_worker) {
332
+ this._worker = _worker;
333
+ }
334
+ provideDefinition(model, position, token) {
335
+ const resource = model.uri;
336
+ return this._worker(resource).then((worker) => {
337
+ return worker.findDefinition(resource.toString(), fromPosition(position));
338
+ }).then((definition) => {
339
+ if (!definition) {
340
+ return;
341
+ }
342
+ return [toLocation(definition)];
343
+ });
344
+ }
345
+ }
346
+ function toLocation(location) {
347
+ return {
348
+ uri: Uri.parse(location.uri),
349
+ range: toRange(location.range)
350
+ };
351
+ }
352
+ class ReferenceAdapter {
353
+ constructor(_worker) {
354
+ this._worker = _worker;
355
+ }
356
+ provideReferences(model, position, context, token) {
357
+ const resource = model.uri;
358
+ return this._worker(resource).then((worker) => {
359
+ return worker.findReferences(resource.toString(), fromPosition(position));
360
+ }).then((entries) => {
361
+ if (!entries) {
362
+ return;
363
+ }
364
+ return entries.map(toLocation);
365
+ });
366
+ }
367
+ }
368
+ class RenameAdapter {
369
+ constructor(_worker) {
370
+ this._worker = _worker;
371
+ }
372
+ provideRenameEdits(model, position, newName, token) {
373
+ const resource = model.uri;
374
+ return this._worker(resource).then((worker) => {
375
+ return worker.doRename(resource.toString(), fromPosition(position), newName);
376
+ }).then((edit) => {
377
+ return toWorkspaceEdit(edit);
378
+ });
379
+ }
380
+ }
381
+ function toWorkspaceEdit(edit) {
382
+ if (!edit || !edit.changes) {
383
+ return void 0;
384
+ }
385
+ let resourceEdits = [];
386
+ for (let uri in edit.changes) {
387
+ const _uri = Uri.parse(uri);
388
+ for (let e of edit.changes[uri]) {
389
+ resourceEdits.push({
390
+ resource: _uri,
391
+ versionId: void 0,
392
+ textEdit: {
393
+ range: toRange(e.range),
394
+ text: e.newText
395
+ }
396
+ });
397
+ }
398
+ }
399
+ return {
400
+ edits: resourceEdits
401
+ };
402
+ }
403
+ class DocumentSymbolAdapter {
404
+ constructor(_worker) {
405
+ this._worker = _worker;
406
+ }
407
+ provideDocumentSymbols(model, token) {
408
+ const resource = model.uri;
409
+ return this._worker(resource).then((worker) => worker.findDocumentSymbols(resource.toString())).then((items) => {
410
+ if (!items) {
411
+ return;
412
+ }
413
+ return items.map((item) => {
414
+ if (isDocumentSymbol(item)) {
415
+ return toDocumentSymbol(item);
416
+ }
417
+ return {
418
+ name: item.name,
419
+ detail: "",
420
+ containerName: item.containerName,
421
+ kind: toSymbolKind(item.kind),
422
+ range: toRange(item.location.range),
423
+ selectionRange: toRange(item.location.range),
424
+ tags: []
425
+ };
426
+ });
427
+ });
428
+ }
429
+ }
430
+ function isDocumentSymbol(symbol) {
431
+ return "children" in symbol;
432
+ }
433
+ function toDocumentSymbol(symbol) {
434
+ return {
435
+ name: symbol.name,
436
+ detail: symbol.detail ?? "",
437
+ kind: toSymbolKind(symbol.kind),
438
+ range: toRange(symbol.range),
439
+ selectionRange: toRange(symbol.selectionRange),
440
+ tags: symbol.tags ?? [],
441
+ children: (symbol.children ?? []).map((item) => toDocumentSymbol(item))
442
+ };
443
+ }
444
+ function toSymbolKind(kind) {
445
+ let mKind = languages.SymbolKind;
446
+ switch (kind) {
447
+ case SymbolKind.File:
448
+ return mKind.File;
449
+ case SymbolKind.Module:
450
+ return mKind.Module;
451
+ case SymbolKind.Namespace:
452
+ return mKind.Namespace;
453
+ case SymbolKind.Package:
454
+ return mKind.Package;
455
+ case SymbolKind.Class:
456
+ return mKind.Class;
457
+ case SymbolKind.Method:
458
+ return mKind.Method;
459
+ case SymbolKind.Property:
460
+ return mKind.Property;
461
+ case SymbolKind.Field:
462
+ return mKind.Field;
463
+ case SymbolKind.Constructor:
464
+ return mKind.Constructor;
465
+ case SymbolKind.Enum:
466
+ return mKind.Enum;
467
+ case SymbolKind.Interface:
468
+ return mKind.Interface;
469
+ case SymbolKind.Function:
470
+ return mKind.Function;
471
+ case SymbolKind.Variable:
472
+ return mKind.Variable;
473
+ case SymbolKind.Constant:
474
+ return mKind.Constant;
475
+ case SymbolKind.String:
476
+ return mKind.String;
477
+ case SymbolKind.Number:
478
+ return mKind.Number;
479
+ case SymbolKind.Boolean:
480
+ return mKind.Boolean;
481
+ case SymbolKind.Array:
482
+ return mKind.Array;
483
+ }
484
+ return mKind.Function;
485
+ }
486
+ class DocumentLinkAdapter {
487
+ constructor(_worker) {
488
+ this._worker = _worker;
489
+ }
490
+ provideLinks(model, token) {
491
+ const resource = model.uri;
492
+ return this._worker(resource).then((worker) => worker.findDocumentLinks(resource.toString())).then((items) => {
493
+ if (!items) {
494
+ return;
495
+ }
496
+ return {
497
+ links: items.map((item) => ({
498
+ range: toRange(item.range),
499
+ url: item.target
500
+ }))
501
+ };
502
+ });
503
+ }
504
+ }
505
+ class DocumentFormattingEditProvider {
506
+ constructor(_worker) {
507
+ this._worker = _worker;
508
+ }
509
+ provideDocumentFormattingEdits(model, options, token) {
510
+ const resource = model.uri;
511
+ return this._worker(resource).then((worker) => {
512
+ return worker.format(resource.toString(), null, fromFormattingOptions(options)).then((edits) => {
513
+ if (!edits || edits.length === 0) {
514
+ return;
515
+ }
516
+ return edits.map(toTextEdit);
517
+ });
518
+ });
519
+ }
520
+ }
521
+ class DocumentRangeFormattingEditProvider {
522
+ constructor(_worker) {
523
+ this._worker = _worker;
524
+ this.canFormatMultipleRanges = false;
525
+ }
526
+ provideDocumentRangeFormattingEdits(model, range, options, token) {
527
+ const resource = model.uri;
528
+ return this._worker(resource).then((worker) => {
529
+ return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
530
+ if (!edits || edits.length === 0) {
531
+ return;
532
+ }
533
+ return edits.map(toTextEdit);
534
+ });
535
+ });
536
+ }
537
+ }
538
+ function fromFormattingOptions(options) {
539
+ return {
540
+ tabSize: options.tabSize,
541
+ insertSpaces: options.insertSpaces
542
+ };
543
+ }
544
+ class DocumentColorAdapter {
545
+ constructor(_worker) {
546
+ this._worker = _worker;
547
+ }
548
+ provideDocumentColors(model, token) {
549
+ const resource = model.uri;
550
+ return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
551
+ if (!infos) {
552
+ return;
553
+ }
554
+ return infos.map((item) => ({
555
+ color: item.color,
556
+ range: toRange(item.range)
557
+ }));
558
+ });
559
+ }
560
+ provideColorPresentations(model, info, token) {
561
+ const resource = model.uri;
562
+ return this._worker(resource).then(
563
+ (worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))
564
+ ).then((presentations) => {
565
+ if (!presentations) {
566
+ return;
567
+ }
568
+ return presentations.map((presentation) => {
569
+ let item = {
570
+ label: presentation.label
571
+ };
572
+ if (presentation.textEdit) {
573
+ item.textEdit = toTextEdit(presentation.textEdit);
574
+ }
575
+ if (presentation.additionalTextEdits) {
576
+ item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
577
+ }
578
+ return item;
579
+ });
580
+ });
581
+ }
582
+ }
583
+ class FoldingRangeAdapter {
584
+ constructor(_worker) {
585
+ this._worker = _worker;
586
+ }
587
+ provideFoldingRanges(model, context, token) {
588
+ const resource = model.uri;
589
+ return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
590
+ if (!ranges) {
591
+ return;
592
+ }
593
+ return ranges.map((range) => {
594
+ const result = {
595
+ start: range.startLine + 1,
596
+ end: range.endLine + 1
597
+ };
598
+ if (typeof range.kind !== "undefined") {
599
+ result.kind = toFoldingRangeKind(range.kind);
600
+ }
601
+ return result;
602
+ });
603
+ });
604
+ }
605
+ }
606
+ function toFoldingRangeKind(kind) {
607
+ switch (kind) {
608
+ case FoldingRangeKind.Comment:
609
+ return languages.FoldingRangeKind.Comment;
610
+ case FoldingRangeKind.Imports:
611
+ return languages.FoldingRangeKind.Imports;
612
+ case FoldingRangeKind.Region:
613
+ return languages.FoldingRangeKind.Region;
614
+ }
615
+ return void 0;
616
+ }
617
+ class SelectionRangeAdapter {
618
+ constructor(_worker) {
619
+ this._worker = _worker;
620
+ }
621
+ provideSelectionRanges(model, positions, token) {
622
+ const resource = model.uri;
623
+ return this._worker(resource).then(
624
+ (worker) => worker.getSelectionRanges(
625
+ resource.toString(),
626
+ positions.map(fromPosition)
627
+ )
628
+ ).then((selectionRanges) => {
629
+ if (!selectionRanges) {
630
+ return;
631
+ }
632
+ return selectionRanges.map((selectionRange) => {
633
+ const result = [];
634
+ while (selectionRange) {
635
+ result.push({ range: toRange(selectionRange.range) });
636
+ selectionRange = selectionRange.parent;
637
+ }
638
+ return result;
639
+ });
640
+ });
641
+ }
642
+ }
643
+
644
+ export { CompletionAdapter, DefinitionAdapter, DiagnosticsAdapter, DocumentColorAdapter, DocumentFormattingEditProvider, DocumentHighlightAdapter, DocumentLinkAdapter, DocumentRangeFormattingEditProvider, DocumentSymbolAdapter, FoldingRangeAdapter, HoverAdapter, ReferenceAdapter, RenameAdapter, SelectionRangeAdapter, fromPosition, fromRange, toRange, toTextEdit };
@@ -0,0 +1,8 @@
1
+ import { initialize } from '../../common/initialize.js';
2
+ import { HTMLWorker } from './htmlWorker.js';
3
+
4
+ self.onmessage = () => {
5
+ initialize((ctx, createData) => {
6
+ return new HTMLWorker(ctx, createData);
7
+ });
8
+ };