monaco-languageclient 2.0.0-dev.0 → 2.0.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +313 -0
  2. package/License.txt +11 -0
  3. package/dist/amd/console-window.d.ts.map +1 -1
  4. package/dist/amd/console-window.js.map +1 -1
  5. package/dist/amd/disposable.d.ts +2 -2
  6. package/dist/amd/disposable.d.ts.map +1 -1
  7. package/dist/amd/disposable.js +1 -1
  8. package/dist/amd/disposable.js.map +1 -1
  9. package/dist/amd/index.d.ts +1 -0
  10. package/dist/amd/index.d.ts.map +1 -1
  11. package/dist/amd/index.js +2 -1
  12. package/dist/amd/index.js.map +1 -1
  13. package/dist/amd/monaco-converter.d.ts +234 -0
  14. package/dist/amd/monaco-converter.d.ts.map +1 -0
  15. package/dist/amd/monaco-converter.js +1195 -0
  16. package/dist/amd/monaco-converter.js.map +1 -0
  17. package/dist/amd/monaco-language-client.d.ts +3 -2
  18. package/dist/amd/monaco-language-client.d.ts.map +1 -1
  19. package/dist/amd/monaco-language-client.js +22 -4
  20. package/dist/amd/monaco-language-client.js.map +1 -1
  21. package/dist/amd/monaco-services.d.ts +3 -3
  22. package/dist/amd/monaco-services.d.ts.map +1 -1
  23. package/dist/amd/monaco-services.js.map +1 -1
  24. package/dist/amd/monaco-workspace.d.ts.map +1 -1
  25. package/dist/cjs/console-window.d.ts +8 -0
  26. package/dist/cjs/console-window.d.ts.map +1 -0
  27. package/dist/cjs/console-window.js +62 -0
  28. package/dist/cjs/console-window.js.map +1 -0
  29. package/dist/cjs/disposable.d.ts +8 -0
  30. package/dist/cjs/disposable.d.ts.map +1 -0
  31. package/dist/cjs/disposable.js +33 -0
  32. package/dist/cjs/disposable.js.map +1 -0
  33. package/dist/cjs/index.d.ts +9 -0
  34. package/dist/cjs/index.d.ts.map +1 -0
  35. package/dist/cjs/index.js +21 -0
  36. package/dist/cjs/index.js.map +1 -0
  37. package/dist/cjs/monaco-converter.d.ts +234 -0
  38. package/dist/cjs/monaco-converter.d.ts.map +1 -0
  39. package/dist/cjs/monaco-converter.js +1195 -0
  40. package/dist/cjs/monaco-converter.js.map +1 -0
  41. package/dist/cjs/monaco-language-client.d.ts +27 -0
  42. package/dist/cjs/monaco-language-client.d.ts.map +1 -0
  43. package/dist/cjs/monaco-language-client.js +123 -0
  44. package/dist/cjs/monaco-language-client.js.map +1 -0
  45. package/dist/cjs/monaco-services.d.ts +19 -0
  46. package/dist/cjs/monaco-services.d.ts.map +1 -0
  47. package/dist/cjs/monaco-services.js +30 -0
  48. package/dist/cjs/monaco-services.js.map +1 -0
  49. package/dist/cjs/monaco-workspace.d.ts +8 -0
  50. package/dist/cjs/monaco-workspace.d.ts.map +1 -0
  51. package/dist/cjs/monaco-workspace.js +11 -0
  52. package/dist/cjs/monaco-workspace.js.map +1 -0
  53. package/lib/console-window.d.ts.map +1 -1
  54. package/lib/console-window.js +6 -10
  55. package/lib/console-window.js.map +1 -1
  56. package/lib/disposable.d.ts +2 -2
  57. package/lib/disposable.d.ts.map +1 -1
  58. package/lib/disposable.js +3 -7
  59. package/lib/disposable.js.map +1 -1
  60. package/lib/index.d.ts +1 -0
  61. package/lib/index.d.ts.map +1 -1
  62. package/lib/index.js +8 -15
  63. package/lib/index.js.map +1 -1
  64. package/lib/monaco-converter.d.ts +234 -0
  65. package/lib/monaco-converter.d.ts.map +1 -0
  66. package/lib/monaco-converter.js +1189 -0
  67. package/lib/monaco-converter.js.map +1 -0
  68. package/lib/monaco-language-client.d.ts +3 -2
  69. package/lib/monaco-language-client.d.ts.map +1 -1
  70. package/lib/monaco-language-client.js +80 -72
  71. package/lib/monaco-language-client.js.map +1 -1
  72. package/lib/monaco-services.d.ts +3 -3
  73. package/lib/monaco-services.d.ts.map +1 -1
  74. package/lib/monaco-services.js +9 -12
  75. package/lib/monaco-services.js.map +1 -1
  76. package/lib/monaco-workspace.d.ts.map +1 -1
  77. package/lib/monaco-workspace.js +1 -5
  78. package/lib/monaco-workspace.js.map +1 -1
  79. package/package.json +22 -7
  80. package/src/console-window.ts +11 -10
  81. package/src/disposable.ts +7 -9
  82. package/src/index.ts +1 -0
  83. package/src/monaco-converter.ts +1346 -0
  84. package/src/monaco-language-client.ts +54 -46
  85. package/src/monaco-services.ts +9 -8
  86. package/src/monaco-workspace.ts +2 -2
@@ -0,0 +1,1195 @@
1
+ define(["require", "exports", "tslib", "vscode-languageserver-protocol", "vscode-languageserver-protocol/lib/common/utils/is", "vscode-languageserver-protocol/lib/common/api"], function (require, exports, tslib_1, ls, Is, api_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ProtocolToMonacoConverter = exports.MonacoToProtocolConverter = exports.ProtocolInlayHint = exports.ProtocolCodeAction = exports.ProtocolCompletionItem = exports.ProtocolCodeLens = exports.ProtocolDocumentLink = void 0;
5
+ ls = tslib_1.__importStar(ls);
6
+ Is = tslib_1.__importStar(Is);
7
+ var ProtocolDocumentLink;
8
+ (function (ProtocolDocumentLink) {
9
+ function is(item) {
10
+ return !!item && 'data' in item;
11
+ }
12
+ ProtocolDocumentLink.is = is;
13
+ })(ProtocolDocumentLink = exports.ProtocolDocumentLink || (exports.ProtocolDocumentLink = {}));
14
+ var ProtocolCodeLens;
15
+ (function (ProtocolCodeLens) {
16
+ function is(item) {
17
+ return !!item && 'data' in item;
18
+ }
19
+ ProtocolCodeLens.is = is;
20
+ })(ProtocolCodeLens = exports.ProtocolCodeLens || (exports.ProtocolCodeLens = {}));
21
+ var ProtocolCompletionItem;
22
+ (function (ProtocolCompletionItem) {
23
+ function is(item) {
24
+ return !!item && 'data' in item;
25
+ }
26
+ ProtocolCompletionItem.is = is;
27
+ })(ProtocolCompletionItem = exports.ProtocolCompletionItem || (exports.ProtocolCompletionItem = {}));
28
+ var ProtocolCodeAction;
29
+ (function (ProtocolCodeAction) {
30
+ function is(item) {
31
+ return !!item && 'data' in item;
32
+ }
33
+ ProtocolCodeAction.is = is;
34
+ })(ProtocolCodeAction = exports.ProtocolCodeAction || (exports.ProtocolCodeAction = {}));
35
+ var ProtocolInlayHint;
36
+ (function (ProtocolInlayHint) {
37
+ function is(item) {
38
+ return !!item && 'data' in item;
39
+ }
40
+ ProtocolInlayHint.is = is;
41
+ })(ProtocolInlayHint = exports.ProtocolInlayHint || (exports.ProtocolInlayHint = {}));
42
+ function isRangeReplace(v) {
43
+ return v.insert !== undefined;
44
+ }
45
+ /**
46
+ * @deprecated use @CodinGame/monaco-vscode-api and vscode-languageclient/lib/common/codeConverter (see browser example)
47
+ */
48
+ class MonacoToProtocolConverter {
49
+ constructor(_monaco) {
50
+ this._monaco = _monaco;
51
+ }
52
+ asPosition(lineNumber, column) {
53
+ const line = lineNumber === undefined || lineNumber === null ? undefined : lineNumber - 1;
54
+ const character = column === undefined || column === null ? undefined : column - 1;
55
+ return {
56
+ line, character
57
+ };
58
+ }
59
+ asRange(range) {
60
+ if (range === undefined) {
61
+ return undefined;
62
+ }
63
+ if (range === null) {
64
+ return null;
65
+ }
66
+ if (isRangeReplace(range)) {
67
+ return this.asRange(range.insert);
68
+ }
69
+ else {
70
+ const start = this.asPosition(range.startLineNumber, range.startColumn);
71
+ const end = this.asPosition(range.endLineNumber, range.endColumn);
72
+ return {
73
+ start, end
74
+ };
75
+ }
76
+ }
77
+ asLocation(item) {
78
+ if (!item) {
79
+ return undefined;
80
+ }
81
+ const uri = item.uri.toString();
82
+ const range = this.asRange(item.range);
83
+ return {
84
+ uri,
85
+ range
86
+ };
87
+ }
88
+ asTextDocumentIdentifier(model) {
89
+ return {
90
+ uri: model.uri.toString()
91
+ };
92
+ }
93
+ asTextDocumentPositionParams(model, position) {
94
+ return {
95
+ textDocument: this.asTextDocumentIdentifier(model),
96
+ position: this.asPosition(position.lineNumber, position.column)
97
+ };
98
+ }
99
+ asCompletionParams(model, position, context) {
100
+ return Object.assign(this.asTextDocumentPositionParams(model, position), {
101
+ context: this.asCompletionContext(context)
102
+ });
103
+ }
104
+ asCompletionContext(context) {
105
+ return {
106
+ triggerKind: this.asCompletionTriggerKind(context.triggerKind),
107
+ triggerCharacter: context.triggerCharacter
108
+ };
109
+ }
110
+ asSignatureHelpContext(context) {
111
+ return {
112
+ triggerKind: this.asSignatureHelpTriggerKind(context.triggerKind),
113
+ triggerCharacter: context.triggerCharacter,
114
+ isRetrigger: context.isRetrigger,
115
+ activeSignatureHelp: this.asSignatureHelp(context.activeSignatureHelp)
116
+ };
117
+ }
118
+ asSignatureHelp(signatureHelp) {
119
+ if (signatureHelp === undefined) {
120
+ return undefined;
121
+ }
122
+ return {
123
+ signatures: signatureHelp.signatures.map(signatureInfo => this.asSignatureInformation(signatureInfo)),
124
+ activeParameter: signatureHelp.activeParameter,
125
+ activeSignature: signatureHelp.activeSignature
126
+ };
127
+ }
128
+ asSignatureInformation(signatureInformation) {
129
+ return {
130
+ documentation: this.asMarkupContent(signatureInformation.documentation),
131
+ label: signatureInformation.label,
132
+ parameters: signatureInformation.parameters.map(paramInfo => this.asParameterInformation(paramInfo)),
133
+ activeParameter: signatureInformation.activeParameter
134
+ };
135
+ }
136
+ asParameterInformation(parameterInformation) {
137
+ return {
138
+ documentation: this.asMarkupContent(parameterInformation.documentation),
139
+ label: parameterInformation.label
140
+ };
141
+ }
142
+ asMarkupContent(markupContent) {
143
+ if (markupContent === undefined) {
144
+ return undefined;
145
+ }
146
+ if (typeof markupContent === 'string') {
147
+ return markupContent;
148
+ }
149
+ return {
150
+ kind: api_1.MarkupKind.Markdown,
151
+ value: markupContent.value
152
+ };
153
+ }
154
+ asSignatureHelpTriggerKind(triggerKind) {
155
+ switch (triggerKind) {
156
+ case this._monaco.languages.SignatureHelpTriggerKind.ContentChange:
157
+ return api_1.SignatureHelpTriggerKind.ContentChange;
158
+ case this._monaco.languages.SignatureHelpTriggerKind.TriggerCharacter:
159
+ return api_1.SignatureHelpTriggerKind.TriggerCharacter;
160
+ default:
161
+ return api_1.SignatureHelpTriggerKind.Invoked;
162
+ }
163
+ }
164
+ asCompletionTriggerKind(triggerKind) {
165
+ switch (triggerKind) {
166
+ case this._monaco.languages.CompletionTriggerKind.TriggerCharacter:
167
+ return api_1.CompletionTriggerKind.TriggerCharacter;
168
+ case this._monaco.languages.CompletionTriggerKind.TriggerForIncompleteCompletions:
169
+ return api_1.CompletionTriggerKind.TriggerForIncompleteCompletions;
170
+ default:
171
+ return api_1.CompletionTriggerKind.Invoked;
172
+ }
173
+ }
174
+ asCompletionItem(item) {
175
+ const result = { label: item.label };
176
+ const protocolItem = ProtocolCompletionItem.is(item) ? item : undefined;
177
+ if (item.detail) {
178
+ result.detail = item.detail;
179
+ }
180
+ if (item.documentation) {
181
+ if (typeof item.documentation === 'string') {
182
+ result.documentation = item.documentation;
183
+ }
184
+ else {
185
+ result.documentation = this.asDocumentation(protocolItem?.documentationFormat ?? api_1.MarkupKind.Markdown, item.documentation);
186
+ }
187
+ }
188
+ if (item.filterText) {
189
+ result.filterText = item.filterText;
190
+ }
191
+ this.fillPrimaryInsertText(result, item);
192
+ if (Is.number(item.kind)) {
193
+ result.kind = this.asCompletionItemKind(item.kind, protocolItem && protocolItem.originalItemKind);
194
+ }
195
+ if (item.sortText) {
196
+ result.sortText = item.sortText;
197
+ }
198
+ if (item.additionalTextEdits) {
199
+ result.additionalTextEdits = this.asTextEdits(item.additionalTextEdits);
200
+ }
201
+ if (item.command) {
202
+ result.command = this.asCommand(item.command);
203
+ }
204
+ if (item.commitCharacters) {
205
+ result.commitCharacters = item.commitCharacters.slice();
206
+ }
207
+ if (item.command) {
208
+ result.command = this.asCommand(item.command);
209
+ }
210
+ if (item.preselect === true || item.preselect === false) {
211
+ result.preselect = item.preselect;
212
+ }
213
+ if (protocolItem) {
214
+ if (protocolItem.data !== undefined) {
215
+ result.data = protocolItem.data;
216
+ }
217
+ if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
218
+ result.deprecated = protocolItem.deprecated;
219
+ }
220
+ }
221
+ if (item.tags) {
222
+ result.tags = item.tags?.slice();
223
+ }
224
+ return result;
225
+ }
226
+ asCompletionItemKind(value, original) {
227
+ if (original !== undefined) {
228
+ return original;
229
+ }
230
+ switch (value) {
231
+ case this._monaco.languages.CompletionItemKind.Method: return api_1.CompletionItemKind.Method;
232
+ case this._monaco.languages.CompletionItemKind.Function: return api_1.CompletionItemKind.Function;
233
+ case this._monaco.languages.CompletionItemKind.Constructor: return api_1.CompletionItemKind.Constructor;
234
+ case this._monaco.languages.CompletionItemKind.Field: return api_1.CompletionItemKind.Field;
235
+ case this._monaco.languages.CompletionItemKind.Variable: return api_1.CompletionItemKind.Variable;
236
+ case this._monaco.languages.CompletionItemKind.Class: return api_1.CompletionItemKind.Class;
237
+ case this._monaco.languages.CompletionItemKind.Struct: return api_1.CompletionItemKind.Struct;
238
+ case this._monaco.languages.CompletionItemKind.Interface: return api_1.CompletionItemKind.Interface;
239
+ case this._monaco.languages.CompletionItemKind.Module: return api_1.CompletionItemKind.Module;
240
+ case this._monaco.languages.CompletionItemKind.Property: return api_1.CompletionItemKind.Property;
241
+ case this._monaco.languages.CompletionItemKind.Event: return api_1.CompletionItemKind.Event;
242
+ case this._monaco.languages.CompletionItemKind.Operator: return api_1.CompletionItemKind.Operator;
243
+ case this._monaco.languages.CompletionItemKind.Unit: return api_1.CompletionItemKind.Unit;
244
+ case this._monaco.languages.CompletionItemKind.Value: return api_1.CompletionItemKind.Value;
245
+ case this._monaco.languages.CompletionItemKind.Constant: return api_1.CompletionItemKind.Constant;
246
+ case this._monaco.languages.CompletionItemKind.Enum: return api_1.CompletionItemKind.Enum;
247
+ case this._monaco.languages.CompletionItemKind.EnumMember: return api_1.CompletionItemKind.EnumMember;
248
+ case this._monaco.languages.CompletionItemKind.Keyword: return api_1.CompletionItemKind.Keyword;
249
+ case this._monaco.languages.CompletionItemKind.Text: return api_1.CompletionItemKind.Text;
250
+ case this._monaco.languages.CompletionItemKind.Color: return api_1.CompletionItemKind.Color;
251
+ case this._monaco.languages.CompletionItemKind.File: return api_1.CompletionItemKind.File;
252
+ case this._monaco.languages.CompletionItemKind.Reference: return api_1.CompletionItemKind.Reference;
253
+ case this._monaco.languages.CompletionItemKind.Customcolor: return api_1.CompletionItemKind.Color;
254
+ case this._monaco.languages.CompletionItemKind.Folder: return api_1.CompletionItemKind.Folder;
255
+ case this._monaco.languages.CompletionItemKind.TypeParameter: return api_1.CompletionItemKind.TypeParameter;
256
+ case this._monaco.languages.CompletionItemKind.Snippet: return api_1.CompletionItemKind.Snippet;
257
+ default: return value + 1;
258
+ }
259
+ }
260
+ asDocumentation(format, documentation) {
261
+ switch (format) {
262
+ case api_1.MarkupKind.PlainText:
263
+ return { kind: format, value: documentation };
264
+ case api_1.MarkupKind.Markdown:
265
+ return { kind: format, value: documentation.value };
266
+ default:
267
+ return `Unsupported Markup content received. Kind is: ${format}`;
268
+ }
269
+ }
270
+ fillPrimaryInsertText(target, source) {
271
+ let format = api_1.InsertTextFormat.PlainText;
272
+ let text;
273
+ let range;
274
+ if (source.insertTextRules !== undefined && (source.insertTextRules & this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet) === 0) {
275
+ format = api_1.InsertTextFormat.Snippet;
276
+ text = source.insertText;
277
+ }
278
+ target.insertTextFormat = format;
279
+ text = source.insertText;
280
+ if (source.range) {
281
+ range = this.asRange(source.range);
282
+ }
283
+ target.insertTextFormat = format;
284
+ if (source.fromEdit && text && range) {
285
+ target.textEdit = { newText: text, range };
286
+ }
287
+ else {
288
+ target.insertText = text;
289
+ }
290
+ target.insertTextMode = source.insertTextMode;
291
+ }
292
+ asTextEdit(edit) {
293
+ const range = this.asRange(edit.range);
294
+ return {
295
+ range,
296
+ newText: edit.text || ''
297
+ };
298
+ }
299
+ asTextEdits(items) {
300
+ if (!items) {
301
+ return undefined;
302
+ }
303
+ return items.map(item => this.asTextEdit(item));
304
+ }
305
+ asReferenceParams(model, position, options) {
306
+ return {
307
+ textDocument: this.asTextDocumentIdentifier(model),
308
+ position: this.asPosition(position.lineNumber, position.column),
309
+ context: { includeDeclaration: options.includeDeclaration }
310
+ };
311
+ }
312
+ asDocumentSymbolParams(model) {
313
+ return {
314
+ textDocument: this.asTextDocumentIdentifier(model)
315
+ };
316
+ }
317
+ asCodeLensParams(model) {
318
+ return {
319
+ textDocument: this.asTextDocumentIdentifier(model)
320
+ };
321
+ }
322
+ asDiagnosticSeverity(value) {
323
+ switch (value) {
324
+ case this._monaco.MarkerSeverity.Error:
325
+ return api_1.DiagnosticSeverity.Error;
326
+ case this._monaco.MarkerSeverity.Warning:
327
+ return api_1.DiagnosticSeverity.Warning;
328
+ case this._monaco.MarkerSeverity.Info:
329
+ return api_1.DiagnosticSeverity.Information;
330
+ case this._monaco.MarkerSeverity.Hint:
331
+ return api_1.DiagnosticSeverity.Hint;
332
+ }
333
+ return undefined;
334
+ }
335
+ asDiagnostic(marker) {
336
+ const range = this.asRange(new this._monaco.Range(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn));
337
+ const severity = this.asDiagnosticSeverity(marker.severity);
338
+ const diag = api_1.Diagnostic.create(range, marker.message, severity, marker.code, marker.source);
339
+ return diag;
340
+ }
341
+ asDiagnostics(markers) {
342
+ if (markers === void 0 || markers === null) {
343
+ return markers;
344
+ }
345
+ return markers.map(marker => this.asDiagnostic(marker));
346
+ }
347
+ asCodeActionContext(context, diagnostics) {
348
+ if (context === void 0 || context === null) {
349
+ return context;
350
+ }
351
+ // FIXME: CodeActionTriggerKind is missing
352
+ return api_1.CodeActionContext.create(diagnostics, Is.string(context.only) ? [context.only] : undefined, undefined);
353
+ }
354
+ asCodeActionParams(model, range, context, diagnostics) {
355
+ return {
356
+ textDocument: this.asTextDocumentIdentifier(model),
357
+ range: this.asRange(range),
358
+ context: this.asCodeActionContext(context, diagnostics)
359
+ };
360
+ }
361
+ asCommand(item) {
362
+ if (item) {
363
+ const args = item.arguments || [];
364
+ return api_1.Command.create(item.title, item.id, ...args);
365
+ }
366
+ return undefined;
367
+ }
368
+ asCodeLens(item) {
369
+ const result = api_1.CodeLens.create(this.asRange(item.range));
370
+ if (item.command) {
371
+ result.command = this.asCommand(item.command);
372
+ }
373
+ if (ProtocolCodeLens.is(item)) {
374
+ if (item.data) {
375
+ result.data = item.data;
376
+ }
377
+ }
378
+ return result;
379
+ }
380
+ asFormattingOptions(options) {
381
+ return { tabSize: options.tabSize, insertSpaces: options.insertSpaces };
382
+ }
383
+ asDocumentFormattingParams(model, options) {
384
+ return {
385
+ textDocument: this.asTextDocumentIdentifier(model),
386
+ options: this.asFormattingOptions(options)
387
+ };
388
+ }
389
+ asDocumentRangeFormattingParams(model, range, options) {
390
+ return {
391
+ textDocument: this.asTextDocumentIdentifier(model),
392
+ range: this.asRange(range),
393
+ options: this.asFormattingOptions(options)
394
+ };
395
+ }
396
+ asDocumentOnTypeFormattingParams(model, position, ch, options) {
397
+ return {
398
+ textDocument: this.asTextDocumentIdentifier(model),
399
+ position: this.asPosition(position.lineNumber, position.column),
400
+ ch,
401
+ options: this.asFormattingOptions(options)
402
+ };
403
+ }
404
+ asRenameParams(model, position, newName) {
405
+ return {
406
+ textDocument: this.asTextDocumentIdentifier(model),
407
+ position: this.asPosition(position.lineNumber, position.column),
408
+ newName
409
+ };
410
+ }
411
+ asDocumentLinkParams(model) {
412
+ return {
413
+ textDocument: this.asTextDocumentIdentifier(model)
414
+ };
415
+ }
416
+ asDocumentLink(item) {
417
+ const result = api_1.DocumentLink.create(this.asRange(item.range));
418
+ if (item.url) {
419
+ result.target = typeof item.url === 'string' ? item.url : item.url.toString();
420
+ }
421
+ if (ProtocolDocumentLink.is(item) && item.data) {
422
+ result.data = item.data;
423
+ }
424
+ if (item.tooltip) {
425
+ result.tooltip = item.tooltip;
426
+ }
427
+ return result;
428
+ }
429
+ asCodeAction(item) {
430
+ const result = { title: item.title };
431
+ const protocolCodeAction = ProtocolCodeAction.is(item) ? item : undefined;
432
+ if (Is.number(item.kind)) {
433
+ result.kind = item.kind;
434
+ }
435
+ if (item.diagnostics) {
436
+ result.diagnostics = this.asDiagnostics(item.diagnostics);
437
+ }
438
+ if (item.edit) {
439
+ throw new Error('VS Code code actions can only be converted to a protocol code action without an edit.');
440
+ }
441
+ if (item.command) {
442
+ result.command = this.asCommand(item.command);
443
+ }
444
+ if (item.isPreferred !== undefined) {
445
+ result.isPreferred = item.isPreferred;
446
+ }
447
+ if (item.disabled) {
448
+ result.disabled = { reason: item.disabled };
449
+ }
450
+ if (protocolCodeAction) {
451
+ if (protocolCodeAction.data !== undefined) {
452
+ result.data = protocolCodeAction.data;
453
+ }
454
+ }
455
+ return result;
456
+ }
457
+ asInlayHintLabelPart(part) {
458
+ return {
459
+ value: part.label,
460
+ command: this.asCommand(part.command),
461
+ location: this.asLocation(part.location),
462
+ tooltip: this.asMarkupContent(part.tooltip)
463
+ };
464
+ }
465
+ asInlayHintLabel(label) {
466
+ if (Array.isArray(label)) {
467
+ return label.map(part => this.asInlayHintLabelPart(part));
468
+ }
469
+ return label;
470
+ }
471
+ asInlayHint(item) {
472
+ const result = api_1.InlayHint.create(this.asPosition(item.position.lineNumber, item.position.column), this.asInlayHintLabel(item.label), item.kind);
473
+ if (ProtocolInlayHint.is(item)) {
474
+ if (item.data) {
475
+ result.data = item.data;
476
+ }
477
+ }
478
+ return result;
479
+ }
480
+ }
481
+ exports.MonacoToProtocolConverter = MonacoToProtocolConverter;
482
+ /**
483
+ * @deprecated use @CodinGame/monaco-vscode-api and vscode-languageclient/lib/common/protocolConverter (see browser example)
484
+ */
485
+ class ProtocolToMonacoConverter {
486
+ constructor(_monaco) {
487
+ this._monaco = _monaco;
488
+ }
489
+ asResourceEdits(resource, edits, asMetadata, modelVersionId) {
490
+ return edits.map(edit => ({
491
+ resource,
492
+ edit: this.asTextEdit(edit),
493
+ modelVersionId,
494
+ metadata: api_1.AnnotatedTextEdit.is(edit) ? asMetadata(edit.annotationId) : undefined
495
+ }));
496
+ }
497
+ asWorkspaceEditMetadata(changeAnnotation) {
498
+ return {
499
+ needsConfirmation: changeAnnotation.needsConfirmation === true,
500
+ label: changeAnnotation.label,
501
+ description: changeAnnotation.description
502
+ };
503
+ }
504
+ asWorkspaceEdit(item) {
505
+ if (!item) {
506
+ return undefined;
507
+ }
508
+ const sharedMetadata = new Map();
509
+ if (item.changeAnnotations !== undefined) {
510
+ for (const key of Object.keys(item.changeAnnotations)) {
511
+ const metaData = this.asWorkspaceEditMetadata(item.changeAnnotations[key]);
512
+ sharedMetadata.set(key, metaData);
513
+ }
514
+ }
515
+ const asMetadata = (annotation) => {
516
+ if (annotation === undefined) {
517
+ return undefined;
518
+ }
519
+ else {
520
+ return sharedMetadata.get(annotation);
521
+ }
522
+ };
523
+ const edits = [];
524
+ if (item.documentChanges) {
525
+ item.documentChanges.forEach(change => {
526
+ if (ls.CreateFile.is(change)) {
527
+ edits.push({
528
+ newUri: this._monaco.Uri.parse(change.uri),
529
+ options: change.options,
530
+ metadata: asMetadata(change.annotationId)
531
+ });
532
+ }
533
+ else if (ls.RenameFile.is(change)) {
534
+ edits.push({
535
+ oldUri: this._monaco.Uri.parse(change.oldUri),
536
+ newUri: this._monaco.Uri.parse(change.newUri),
537
+ options: change.options,
538
+ metadata: asMetadata(change.annotationId)
539
+ });
540
+ }
541
+ else if (ls.DeleteFile.is(change)) {
542
+ edits.push({
543
+ oldUri: this._monaco.Uri.parse(change.uri),
544
+ options: change.options,
545
+ metadata: asMetadata(change.annotationId)
546
+ });
547
+ }
548
+ else if (ls.TextDocumentEdit.is(change)) {
549
+ const resource = this._monaco.Uri.parse(change.textDocument.uri);
550
+ const version = typeof change.textDocument.version === 'number' ? change.textDocument.version : undefined;
551
+ edits.push(...this.asResourceEdits(resource, change.edits, asMetadata, version));
552
+ }
553
+ else {
554
+ console.error(`Unknown workspace edit change received:\n${JSON.stringify(change, undefined, 4)}`);
555
+ }
556
+ });
557
+ }
558
+ else if (item.changes) {
559
+ for (const key of Object.keys(item.changes)) {
560
+ const resource = this._monaco.Uri.parse(key);
561
+ edits.push(...this.asResourceEdits(resource, item.changes[key], asMetadata));
562
+ }
563
+ }
564
+ return {
565
+ edits
566
+ };
567
+ }
568
+ asTextEdit(edit) {
569
+ if (!edit) {
570
+ return undefined;
571
+ }
572
+ const range = this.asRange(edit.range);
573
+ return {
574
+ range,
575
+ text: edit.newText
576
+ };
577
+ }
578
+ asTextEdits(items) {
579
+ if (!items) {
580
+ return undefined;
581
+ }
582
+ return items.map(item => this.asTextEdit(item));
583
+ }
584
+ asCodeLens(item) {
585
+ if (!item) {
586
+ return undefined;
587
+ }
588
+ const range = this.asRange(item.range);
589
+ const result = { range };
590
+ if (item.command) {
591
+ result.command = this.asCommand(item.command);
592
+ }
593
+ if (item.data !== void 0 && item.data !== null) {
594
+ result.data = item.data;
595
+ }
596
+ return result;
597
+ }
598
+ asCodeLensList(items) {
599
+ if (!items) {
600
+ return undefined;
601
+ }
602
+ return {
603
+ lenses: items.map((codeLens) => this.asCodeLens(codeLens)),
604
+ dispose: () => { }
605
+ };
606
+ }
607
+ asCodeActionList(actions) {
608
+ return {
609
+ actions: actions.map(action => this.asCodeAction(action)),
610
+ dispose: () => { }
611
+ };
612
+ }
613
+ asCodeAction(item) {
614
+ if (api_1.Command.is(item)) {
615
+ return {
616
+ command: {
617
+ id: item.command,
618
+ title: item.title,
619
+ arguments: item.arguments
620
+ },
621
+ title: item.title
622
+ };
623
+ }
624
+ return {
625
+ title: item.title,
626
+ command: this.asCommand(item.command),
627
+ edit: this.asWorkspaceEdit(item.edit),
628
+ diagnostics: this.asDiagnostics(item.diagnostics),
629
+ kind: item.kind,
630
+ disabled: item.disabled ? item.disabled.reason : undefined,
631
+ isPreferred: item.isPreferred,
632
+ data: item.data
633
+ };
634
+ }
635
+ asCommand(command) {
636
+ if (!command) {
637
+ return undefined;
638
+ }
639
+ return {
640
+ id: command.command,
641
+ title: command.title,
642
+ arguments: command.arguments
643
+ };
644
+ }
645
+ asDocumentSymbol(value) {
646
+ const children = value.children && value.children.map(c => this.asDocumentSymbol(c));
647
+ return {
648
+ name: value.name,
649
+ detail: value.detail || '',
650
+ kind: this.asSymbolKind(value.kind),
651
+ tags: value.tags || [],
652
+ range: this.asRange(value.range),
653
+ selectionRange: this.asRange(value.selectionRange),
654
+ children
655
+ };
656
+ }
657
+ asDocumentSymbols(values) {
658
+ if (api_1.DocumentSymbol.is(values[0])) {
659
+ return values.map(s => this.asDocumentSymbol(s));
660
+ }
661
+ return this.asSymbolInformations(values);
662
+ }
663
+ asSymbolInformations(values, uri) {
664
+ if (!values) {
665
+ return undefined;
666
+ }
667
+ return values.map(information => this.asSymbolInformation(information, uri));
668
+ }
669
+ asSymbolInformation(item, uri) {
670
+ const location = this.asLocation(uri ? { ...item.location, uri: uri.toString() } : item.location);
671
+ return {
672
+ name: item.name,
673
+ detail: '',
674
+ containerName: item.containerName,
675
+ kind: this.asSymbolKind(item.kind),
676
+ tags: item.tags || [],
677
+ range: location.range,
678
+ selectionRange: location.range
679
+ };
680
+ }
681
+ asSymbolKind(item) {
682
+ if (item <= api_1.SymbolKind.TypeParameter) {
683
+ // Symbol kind is one based in the protocol and zero based in code.
684
+ return item - 1;
685
+ }
686
+ return this._monaco.languages.SymbolKind.Property;
687
+ }
688
+ asDocumentHighlights(values) {
689
+ if (!values) {
690
+ return undefined;
691
+ }
692
+ return values.map(item => this.asDocumentHighlight(item));
693
+ }
694
+ asDocumentHighlight(item) {
695
+ const range = this.asRange(item.range);
696
+ const kind = Is.number(item.kind) ? this.asDocumentHighlightKind(item.kind) : undefined;
697
+ return { range, kind };
698
+ }
699
+ asDocumentHighlightKind(item) {
700
+ switch (item) {
701
+ case api_1.DocumentHighlightKind.Text:
702
+ return this._monaco.languages.DocumentHighlightKind.Text;
703
+ case api_1.DocumentHighlightKind.Read:
704
+ return this._monaco.languages.DocumentHighlightKind.Read;
705
+ case api_1.DocumentHighlightKind.Write:
706
+ return this._monaco.languages.DocumentHighlightKind.Write;
707
+ }
708
+ return this._monaco.languages.DocumentHighlightKind.Text;
709
+ }
710
+ asReferences(values) {
711
+ if (!values) {
712
+ return undefined;
713
+ }
714
+ return values.map(location => this.asLocation(location));
715
+ }
716
+ asDefinitionResult(item) {
717
+ if (!item) {
718
+ return undefined;
719
+ }
720
+ if (Is.array(item)) {
721
+ if (item.length === 0) {
722
+ return undefined;
723
+ }
724
+ else if (api_1.LocationLink.is(item[0])) {
725
+ const links = item;
726
+ return links.map((location) => this.asLocationLink(location));
727
+ }
728
+ else {
729
+ const locations = item;
730
+ return locations.map((location) => this.asLocation(location));
731
+ }
732
+ }
733
+ else {
734
+ return this.asLocation(item);
735
+ }
736
+ }
737
+ asLocation(item) {
738
+ if (!item) {
739
+ return undefined;
740
+ }
741
+ const uri = this._monaco.Uri.parse(item.uri);
742
+ const range = this.asRange(item.range);
743
+ return {
744
+ uri, range
745
+ };
746
+ }
747
+ asLocationLink(item) {
748
+ if (!item) {
749
+ return undefined;
750
+ }
751
+ const result = {
752
+ uri: this._monaco.Uri.parse(item.targetUri),
753
+ range: this.asRange(item.targetSelectionRange),
754
+ originSelectionRange: this.asRange(item.originSelectionRange),
755
+ targetSelectionRange: this.asRange(item.targetSelectionRange)
756
+ };
757
+ if (!result.targetSelectionRange) {
758
+ throw new Error('targetSelectionRange must not be undefined or null');
759
+ }
760
+ return result;
761
+ }
762
+ asSignatureHelpResult(item) {
763
+ if (!item) {
764
+ return undefined;
765
+ }
766
+ const result = {};
767
+ if (Is.number(item.activeSignature)) {
768
+ result.activeSignature = item.activeSignature;
769
+ }
770
+ else {
771
+ // activeSignature was optional in the past
772
+ result.activeSignature = 0;
773
+ }
774
+ if (Is.number(item.activeParameter)) {
775
+ result.activeParameter = item.activeParameter;
776
+ }
777
+ else {
778
+ // activeParameter was optional in the past
779
+ result.activeParameter = 0;
780
+ }
781
+ if (item.signatures) {
782
+ result.signatures = this.asSignatureInformations(item.signatures);
783
+ }
784
+ else {
785
+ result.signatures = [];
786
+ }
787
+ return {
788
+ value: result,
789
+ dispose: () => { }
790
+ };
791
+ }
792
+ asSignatureInformations(items) {
793
+ return items.map(item => this.asSignatureInformation(item));
794
+ }
795
+ asSignatureInformation(item) {
796
+ const result = { label: item.label };
797
+ if (item.documentation) {
798
+ result.documentation = this.asDocumentation(item.documentation);
799
+ }
800
+ if (item.parameters) {
801
+ result.parameters = this.asParameterInformations(item.parameters);
802
+ }
803
+ else {
804
+ result.parameters = [];
805
+ }
806
+ if (item.activeParameter) {
807
+ result.activeParameter = item.activeParameter;
808
+ }
809
+ return result;
810
+ }
811
+ asParameterInformations(item) {
812
+ return item.map(item => this.asParameterInformation(item));
813
+ }
814
+ asParameterInformation(item) {
815
+ const result = { label: item.label };
816
+ if (item.documentation) {
817
+ result.documentation = this.asDocumentation(item.documentation);
818
+ }
819
+ return result;
820
+ }
821
+ asHover(hover) {
822
+ if (!hover) {
823
+ return undefined;
824
+ }
825
+ return {
826
+ contents: this.asHoverContent(hover.contents),
827
+ range: this.asRange(hover.range)
828
+ };
829
+ }
830
+ asHoverContent(contents) {
831
+ if (Array.isArray(contents)) {
832
+ return contents.map(content => this.asMarkdownString(content));
833
+ }
834
+ return [this.asMarkdownString(contents)];
835
+ }
836
+ asDocumentation(value) {
837
+ if (Is.string(value)) {
838
+ return value;
839
+ }
840
+ if (value.kind === api_1.MarkupKind.PlainText) {
841
+ return value.value;
842
+ }
843
+ return this.asMarkdownString(value);
844
+ }
845
+ asMarkdownString(content) {
846
+ if (api_1.MarkupContent.is(content)) {
847
+ return {
848
+ value: content.value
849
+ };
850
+ }
851
+ if (Is.string(content)) {
852
+ return { value: content };
853
+ }
854
+ const { language, value } = content;
855
+ return {
856
+ value: '```' + language + '\n' + value + '\n```'
857
+ };
858
+ }
859
+ asSeverity(severity) {
860
+ if (severity === 1) {
861
+ return this._monaco.MarkerSeverity.Error;
862
+ }
863
+ if (severity === 2) {
864
+ return this._monaco.MarkerSeverity.Warning;
865
+ }
866
+ if (severity === 3) {
867
+ return this._monaco.MarkerSeverity.Info;
868
+ }
869
+ return this._monaco.MarkerSeverity.Hint;
870
+ }
871
+ asDiagnostics(diagnostics) {
872
+ if (!diagnostics) {
873
+ return undefined;
874
+ }
875
+ return diagnostics.map(diagnostic => this.asDiagnostic(diagnostic));
876
+ }
877
+ asDiagnostic(diagnostic) {
878
+ return {
879
+ code: typeof diagnostic.code === 'number' ? diagnostic.code.toString() : diagnostic.code,
880
+ severity: this.asSeverity(diagnostic.severity),
881
+ message: diagnostic.message,
882
+ source: diagnostic.source,
883
+ startLineNumber: diagnostic.range.start.line + 1,
884
+ startColumn: diagnostic.range.start.character + 1,
885
+ endLineNumber: diagnostic.range.end.line + 1,
886
+ endColumn: diagnostic.range.end.character + 1,
887
+ relatedInformation: this.asRelatedInformations(diagnostic.relatedInformation),
888
+ tags: diagnostic.tags
889
+ };
890
+ }
891
+ asRelatedInformations(relatedInformation) {
892
+ if (!relatedInformation) {
893
+ return undefined;
894
+ }
895
+ return relatedInformation.map(item => this.asRelatedInformation(item));
896
+ }
897
+ asRelatedInformation(relatedInformation) {
898
+ return {
899
+ resource: this._monaco.Uri.parse(relatedInformation.location.uri),
900
+ startLineNumber: relatedInformation.location.range.start.line + 1,
901
+ startColumn: relatedInformation.location.range.start.character + 1,
902
+ endLineNumber: relatedInformation.location.range.end.line + 1,
903
+ endColumn: relatedInformation.location.range.end.character + 1,
904
+ message: relatedInformation.message
905
+ };
906
+ }
907
+ asCompletionResult(result, defaultMonacoRange) {
908
+ if (!result) {
909
+ return {
910
+ incomplete: false,
911
+ suggestions: []
912
+ };
913
+ }
914
+ if (Array.isArray(result)) {
915
+ const suggestions = result.map(item => this.asCompletionItem(item, defaultMonacoRange, defaultRange));
916
+ return {
917
+ incomplete: false,
918
+ suggestions
919
+ };
920
+ }
921
+ const defaultRange = this.getCompletionItemDefaultRange(result);
922
+ return {
923
+ incomplete: result.isIncomplete,
924
+ suggestions: result.items.map(item => this.asCompletionItem(item, defaultMonacoRange, defaultRange, result.itemDefaults))
925
+ };
926
+ }
927
+ asCompletionItem(item, defaultMonacoRange, defaultRange, itemDefaults) {
928
+ const result = { label: this.asCompletionItemLabel(item) };
929
+ if (item.detail) {
930
+ result.detail = item.detail;
931
+ }
932
+ if (item.documentation) {
933
+ result.documentation = this.asDocumentation(item.documentation);
934
+ result.documentationFormat = Is.string(item.documentation) ? undefined : item.documentation.kind;
935
+ }
936
+ if (item.filterText) {
937
+ result.filterText = item.filterText;
938
+ }
939
+ const insertText = this.asCompletionInsertText(item, defaultRange, itemDefaults?.insertTextFormat);
940
+ result.insertText = insertText.insertText;
941
+ result.range = insertText.range ?? defaultMonacoRange;
942
+ result.fromEdit = insertText.fromEdit;
943
+ if (insertText.isSnippet) {
944
+ result.insertTextRules = this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
945
+ }
946
+ if (Is.number(item.kind)) {
947
+ const [itemKind, original] = this.asCompletionItemKind(item.kind);
948
+ result.kind = itemKind;
949
+ if (original) {
950
+ result.originalItemKind = original;
951
+ }
952
+ }
953
+ if (item.sortText) {
954
+ result.sortText = item.sortText;
955
+ }
956
+ if (item.additionalTextEdits) {
957
+ result.additionalTextEdits = this.asTextEdits(item.additionalTextEdits);
958
+ }
959
+ if (Is.stringArray(item.commitCharacters)) {
960
+ result.commitCharacters = item.commitCharacters.slice();
961
+ }
962
+ if (item.command) {
963
+ result.command = this.asCommand(item.command);
964
+ }
965
+ if (item.deprecated === true || item.deprecated === false) {
966
+ result.deprecated = item.deprecated;
967
+ }
968
+ if (item.preselect === true || item.preselect === false) {
969
+ result.preselect = item.preselect;
970
+ }
971
+ const data = item.data ?? itemDefaults?.data;
972
+ if (data !== undefined) {
973
+ result.data = data;
974
+ }
975
+ if (item.deprecated === true || item.deprecated === false) {
976
+ result.deprecated = item.deprecated;
977
+ }
978
+ const insertTextMode = item.insertTextMode ?? itemDefaults?.insertTextMode;
979
+ if (insertTextMode) {
980
+ result.insertTextMode = insertTextMode;
981
+ }
982
+ if (item.tags) {
983
+ result.tags = item.tags;
984
+ }
985
+ return result;
986
+ }
987
+ getCompletionItemDefaultRange(list) {
988
+ const rangeDefaults = list.itemDefaults?.editRange;
989
+ return ls.Range.is(rangeDefaults)
990
+ ? this.asRange(rangeDefaults)
991
+ : rangeDefaults !== undefined
992
+ ? { insert: this.asRange(rangeDefaults.insert), replace: this.asRange(rangeDefaults.replace) }
993
+ : undefined;
994
+ }
995
+ asCompletionItemLabel(item) {
996
+ if (ls.CompletionItemLabelDetails.is(item.labelDetails)) {
997
+ return {
998
+ label: item.label,
999
+ detail: item.labelDetails.detail,
1000
+ description: item.labelDetails.description
1001
+ };
1002
+ }
1003
+ else {
1004
+ return item.label;
1005
+ }
1006
+ }
1007
+ asCompletionItemKind(value) {
1008
+ if (api_1.CompletionItemKind.Text <= value && value <= api_1.CompletionItemKind.TypeParameter) {
1009
+ switch (value) {
1010
+ case api_1.CompletionItemKind.Text: return [this._monaco.languages.CompletionItemKind.Text, undefined];
1011
+ case api_1.CompletionItemKind.Method: return [this._monaco.languages.CompletionItemKind.Method, undefined];
1012
+ case api_1.CompletionItemKind.Function: return [this._monaco.languages.CompletionItemKind.Function, undefined];
1013
+ case api_1.CompletionItemKind.Constructor: return [this._monaco.languages.CompletionItemKind.Constructor, undefined];
1014
+ case api_1.CompletionItemKind.Field: return [this._monaco.languages.CompletionItemKind.Field, undefined];
1015
+ case api_1.CompletionItemKind.Variable: return [this._monaco.languages.CompletionItemKind.Variable, undefined];
1016
+ case api_1.CompletionItemKind.Class: return [this._monaco.languages.CompletionItemKind.Class, undefined];
1017
+ case api_1.CompletionItemKind.Interface: return [this._monaco.languages.CompletionItemKind.Interface, undefined];
1018
+ case api_1.CompletionItemKind.Module: return [this._monaco.languages.CompletionItemKind.Module, undefined];
1019
+ case api_1.CompletionItemKind.Property: return [this._monaco.languages.CompletionItemKind.Property, undefined];
1020
+ case api_1.CompletionItemKind.Unit: return [this._monaco.languages.CompletionItemKind.Unit, undefined];
1021
+ case api_1.CompletionItemKind.Value: return [this._monaco.languages.CompletionItemKind.Value, undefined];
1022
+ case api_1.CompletionItemKind.Enum: return [this._monaco.languages.CompletionItemKind.Enum, undefined];
1023
+ case api_1.CompletionItemKind.Keyword: return [this._monaco.languages.CompletionItemKind.Keyword, undefined];
1024
+ case api_1.CompletionItemKind.Snippet: return [this._monaco.languages.CompletionItemKind.Snippet, undefined];
1025
+ case api_1.CompletionItemKind.Color: return [this._monaco.languages.CompletionItemKind.Color, undefined];
1026
+ case api_1.CompletionItemKind.File: return [this._monaco.languages.CompletionItemKind.File, undefined];
1027
+ case api_1.CompletionItemKind.Reference: return [this._monaco.languages.CompletionItemKind.Reference, undefined];
1028
+ case api_1.CompletionItemKind.Folder: return [this._monaco.languages.CompletionItemKind.Folder, undefined];
1029
+ case api_1.CompletionItemKind.EnumMember: return [this._monaco.languages.CompletionItemKind.EnumMember, undefined];
1030
+ case api_1.CompletionItemKind.Constant: return [this._monaco.languages.CompletionItemKind.Constant, undefined];
1031
+ case api_1.CompletionItemKind.Struct: return [this._monaco.languages.CompletionItemKind.Struct, undefined];
1032
+ case api_1.CompletionItemKind.Event: return [this._monaco.languages.CompletionItemKind.Event, undefined];
1033
+ case api_1.CompletionItemKind.Operator: return [this._monaco.languages.CompletionItemKind.Operator, undefined];
1034
+ case api_1.CompletionItemKind.TypeParameter: return [this._monaco.languages.CompletionItemKind.TypeParameter, undefined];
1035
+ default: return [value - 1, undefined];
1036
+ }
1037
+ }
1038
+ return [api_1.CompletionItemKind.Text, value];
1039
+ }
1040
+ asCompletionInsertText(item, defaultRange, defaultInsertTextFormat) {
1041
+ const insertTextFormat = item.insertTextFormat ?? defaultInsertTextFormat;
1042
+ const isSnippet = insertTextFormat === api_1.InsertTextFormat.Snippet;
1043
+ if (item.textEdit !== undefined || defaultRange !== undefined) {
1044
+ const [range, newText] = item.textEdit !== undefined
1045
+ ? this.getCompletionRangeAndText(item.textEdit)
1046
+ : [defaultRange, item.textEditText ?? item.label];
1047
+ return { insertText: newText, range, fromEdit: true, isSnippet };
1048
+ }
1049
+ else if (item.insertText) {
1050
+ return { isSnippet, insertText: item.insertText, fromEdit: false, range: defaultRange };
1051
+ }
1052
+ return { insertText: item.label, range: defaultRange, fromEdit: false, isSnippet: false };
1053
+ }
1054
+ getCompletionRangeAndText(value) {
1055
+ if (ls.InsertReplaceEdit.is(value)) {
1056
+ return [{ insert: this.asRange(value.insert), replace: this.asRange(value.replace) }, value.newText];
1057
+ }
1058
+ else {
1059
+ return [this.asRange(value.range), value.newText];
1060
+ }
1061
+ }
1062
+ asDocumentLinks(documentLinks) {
1063
+ const links = documentLinks.map(link => this.asDocumentLink(link));
1064
+ return { links };
1065
+ }
1066
+ asDocumentLink(documentLink) {
1067
+ return {
1068
+ range: this.asRange(documentLink.range),
1069
+ url: documentLink.target,
1070
+ data: documentLink.data,
1071
+ tooltip: documentLink.tooltip
1072
+ };
1073
+ }
1074
+ asRange(range) {
1075
+ if (range === undefined) {
1076
+ return undefined;
1077
+ }
1078
+ if (range === null) {
1079
+ return null;
1080
+ }
1081
+ const start = this.asPosition(range.start);
1082
+ const end = this.asPosition(range.end);
1083
+ if (start instanceof this._monaco.Position && end instanceof this._monaco.Position) {
1084
+ return new this._monaco.Range(start.lineNumber, start.column, end.lineNumber, end.column);
1085
+ }
1086
+ const startLineNumber = !start || start.lineNumber === undefined ? undefined : start.lineNumber;
1087
+ const startColumn = !start || start.column === undefined ? undefined : start.column;
1088
+ const endLineNumber = !end || end.lineNumber === undefined ? undefined : end.lineNumber;
1089
+ const endColumn = !end || end.column === undefined ? undefined : end.column;
1090
+ return { startLineNumber, startColumn, endLineNumber, endColumn };
1091
+ }
1092
+ asPosition(position) {
1093
+ if (position === undefined) {
1094
+ return undefined;
1095
+ }
1096
+ if (position === null) {
1097
+ return null;
1098
+ }
1099
+ const { line, character } = position;
1100
+ const lineNumber = line === undefined ? undefined : line + 1;
1101
+ const column = character === undefined ? undefined : character + 1;
1102
+ if (lineNumber !== undefined && column !== undefined) {
1103
+ return new this._monaco.Position(lineNumber, column);
1104
+ }
1105
+ return { lineNumber, column };
1106
+ }
1107
+ asColorInformations(items) {
1108
+ return items.map(item => this.asColorInformation(item));
1109
+ }
1110
+ asColorInformation(item) {
1111
+ return {
1112
+ range: this.asRange(item.range),
1113
+ color: item.color
1114
+ };
1115
+ }
1116
+ asColorPresentations(items) {
1117
+ return items.map(item => this.asColorPresentation(item));
1118
+ }
1119
+ asColorPresentation(item) {
1120
+ return {
1121
+ label: item.label,
1122
+ textEdit: this.asTextEdit(item.textEdit),
1123
+ additionalTextEdits: this.asTextEdits(item.additionalTextEdits)
1124
+ };
1125
+ }
1126
+ asFoldingRanges(items) {
1127
+ if (!items) {
1128
+ return items;
1129
+ }
1130
+ return items.map(item => this.asFoldingRange(item));
1131
+ }
1132
+ asFoldingRange(item) {
1133
+ return {
1134
+ start: item.startLine + 1,
1135
+ end: item.endLine + 1,
1136
+ kind: this.asFoldingRangeKind(item.kind)
1137
+ };
1138
+ }
1139
+ asFoldingRangeKind(kind) {
1140
+ if (kind) {
1141
+ switch (kind) {
1142
+ case api_1.FoldingRangeKind.Comment:
1143
+ return this._monaco.languages.FoldingRangeKind.Comment;
1144
+ case api_1.FoldingRangeKind.Imports:
1145
+ return this._monaco.languages.FoldingRangeKind.Imports;
1146
+ case api_1.FoldingRangeKind.Region:
1147
+ return this._monaco.languages.FoldingRangeKind.Region;
1148
+ }
1149
+ }
1150
+ return undefined;
1151
+ }
1152
+ asSemanticTokens(semanticTokens) {
1153
+ return {
1154
+ resultId: semanticTokens.resultId,
1155
+ data: Uint32Array.from(semanticTokens.data)
1156
+ };
1157
+ }
1158
+ asInlayHintLabelPart(part) {
1159
+ return {
1160
+ label: part.value,
1161
+ command: this.asCommand(part.command),
1162
+ location: this.asLocation(part.location),
1163
+ tooltip: part.tooltip && this.asMarkdownString(part.tooltip)
1164
+ };
1165
+ }
1166
+ asInlayHintLabel(label) {
1167
+ if (Array.isArray(label)) {
1168
+ return label.map(part => this.asInlayHintLabelPart(part));
1169
+ }
1170
+ return label;
1171
+ }
1172
+ asInlayHint(inlayHint) {
1173
+ return {
1174
+ data: inlayHint.data,
1175
+ label: this.asInlayHintLabel(inlayHint.label),
1176
+ position: this.asPosition(inlayHint.position),
1177
+ kind: inlayHint.kind,
1178
+ paddingLeft: inlayHint.paddingLeft,
1179
+ paddingRight: inlayHint.paddingRight,
1180
+ tooltip: inlayHint.tooltip && this.asMarkdownString(inlayHint.tooltip)
1181
+ };
1182
+ }
1183
+ asInlayHintList(items) {
1184
+ if (!items) {
1185
+ return undefined;
1186
+ }
1187
+ return {
1188
+ hints: items.map((hint) => this.asInlayHint(hint)),
1189
+ dispose: () => { }
1190
+ };
1191
+ }
1192
+ }
1193
+ exports.ProtocolToMonacoConverter = ProtocolToMonacoConverter;
1194
+ });
1195
+ //# sourceMappingURL=monaco-converter.js.map