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