@kusto/monaco-kusto 3.2.4 → 3.2.7
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/package.json +88 -88
- package/release/dev/kustoMode.js +1070 -1070
- package/release/dev/kustoWorker.js +1856 -1833
- package/release/dev/monaco.contribution.js +310 -306
- package/release/esm/commandFormatter.js +32 -32
- package/release/esm/commandHighlighter.js +44 -44
- package/release/esm/extendedEditor.js +38 -38
- package/release/esm/kusto.worker.js +8 -8
- package/release/esm/kustoMode.js +98 -98
- package/release/esm/kustoWorker.js +199 -199
- package/release/esm/languageFeatures.js +778 -778
- package/release/esm/languageService/kustoLanguageService.js +1585 -1562
- package/release/esm/languageService/kustoMonarchLanguageDefinition.js +76 -76
- package/release/esm/languageService/schema.js +64 -64
- package/release/esm/monaco.contribution.d.ts +12 -12
- package/release/esm/monaco.contribution.js +180 -176
- package/release/esm/monaco.d.ts +232 -224
- package/release/esm/workerManager.js +101 -101
- package/release/min/kustoMode.js +1 -1
- package/release/min/kustoWorker.js +2 -2
- package/release/min/monaco.contribution.d.ts +12 -12
- package/release/min/monaco.contribution.js +2 -2
- package/release/min/monaco.d.ts +232 -224
- package/scripts/bundle.js +65 -65
- package/scripts/release.js +25 -25
|
@@ -1,778 +1,778 @@
|
|
|
1
|
-
import * as ls from './_deps/vscode-languageserver-types/main';
|
|
2
|
-
import * as _ from './_deps/lodash/lodash';
|
|
3
|
-
var Uri = monaco.Uri;
|
|
4
|
-
var Range = monaco.Range;
|
|
5
|
-
var ClassificationKind = Kusto.Language.Editor.ClassificationKind;
|
|
6
|
-
// --- diagnostics ---
|
|
7
|
-
var DiagnosticsAdapter = /** @class */ (function () {
|
|
8
|
-
function DiagnosticsAdapter(_languageId, _worker, defaults, onSchemaChange) {
|
|
9
|
-
var _this = this;
|
|
10
|
-
this._languageId = _languageId;
|
|
11
|
-
this._worker = _worker;
|
|
12
|
-
this._disposables = [];
|
|
13
|
-
this._contentListener = Object.create(null);
|
|
14
|
-
this._configurationListener = Object.create(null);
|
|
15
|
-
this._schemaListener = Object.create(null);
|
|
16
|
-
var onModelAdd = function (model) {
|
|
17
|
-
var modeId = model.getModeId();
|
|
18
|
-
if (modeId !== _this._languageId) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
var debouncedValidation = _.debounce(function (intervals) { return _this._doValidate(model, modeId, intervals); }, 500);
|
|
22
|
-
_this._contentListener[model.uri.toString()] = model.onDidChangeContent(function (e) {
|
|
23
|
-
var intervalsToValidate = changeEventToIntervals(e);
|
|
24
|
-
debouncedValidation(intervalsToValidate);
|
|
25
|
-
});
|
|
26
|
-
_this._configurationListener[model.uri.toString()] = defaults.onDidChange(function () {
|
|
27
|
-
self.setTimeout(function () { return _this._doValidate(model, modeId, []); }, 0);
|
|
28
|
-
});
|
|
29
|
-
_this._schemaListener[model.uri.toString()] = onSchemaChange(function () {
|
|
30
|
-
self.setTimeout(function () { return _this._doValidate(model, modeId, []); }, 0);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var onModelRemoved = function (model) {
|
|
34
|
-
monaco.editor.setModelMarkers(model, _this._languageId, []);
|
|
35
|
-
var uriStr = model.uri.toString();
|
|
36
|
-
var contentListener = _this._contentListener[uriStr];
|
|
37
|
-
if (contentListener) {
|
|
38
|
-
contentListener.dispose();
|
|
39
|
-
delete _this._contentListener[uriStr];
|
|
40
|
-
}
|
|
41
|
-
var configurationListener = _this._configurationListener[uriStr];
|
|
42
|
-
if (configurationListener) {
|
|
43
|
-
configurationListener.dispose();
|
|
44
|
-
delete _this._configurationListener[uriStr];
|
|
45
|
-
}
|
|
46
|
-
var schemaListener = _this._schemaListener[uriStr];
|
|
47
|
-
if (schemaListener) {
|
|
48
|
-
schemaListener.dispose();
|
|
49
|
-
delete _this._schemaListener[uriStr];
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
|
|
53
|
-
this._disposables.push(monaco.editor.onWillDisposeModel(onModelRemoved));
|
|
54
|
-
this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
|
|
55
|
-
onModelRemoved(event.model);
|
|
56
|
-
onModelAdd(event.model);
|
|
57
|
-
}));
|
|
58
|
-
this._disposables.push({
|
|
59
|
-
dispose: function () {
|
|
60
|
-
for (var key in _this._contentListener) {
|
|
61
|
-
_this._contentListener[key].dispose();
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
monaco.editor.getModels().forEach(onModelAdd);
|
|
66
|
-
}
|
|
67
|
-
DiagnosticsAdapter.prototype.dispose = function () {
|
|
68
|
-
this._disposables.forEach(function (d) { return d && d.dispose(); });
|
|
69
|
-
this._disposables = [];
|
|
70
|
-
};
|
|
71
|
-
DiagnosticsAdapter.prototype._doValidate = function (model, languageId, intervals) {
|
|
72
|
-
if (model.isDisposed()) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
var resource = model.uri;
|
|
76
|
-
var versionNumberBefore = model.getVersionId();
|
|
77
|
-
this._worker(resource)
|
|
78
|
-
.then(function (worker) {
|
|
79
|
-
return worker.doValidation(resource.toString(), intervals);
|
|
80
|
-
})
|
|
81
|
-
.then(function (diagnostics) {
|
|
82
|
-
var newModel = monaco.editor.getModel(resource);
|
|
83
|
-
var versionId = newModel.getVersionId();
|
|
84
|
-
if (versionId !== versionNumberBefore) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
var markers = diagnostics.map(function (d) { return toDiagnostics(resource, d); });
|
|
88
|
-
var model = monaco.editor.getModel(resource);
|
|
89
|
-
if (model && model.getModeId() === languageId) {
|
|
90
|
-
monaco.editor.setModelMarkers(model, languageId, markers);
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
.then(undefined, function (err) {
|
|
94
|
-
console.error(err);
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
return DiagnosticsAdapter;
|
|
98
|
-
}());
|
|
99
|
-
export { DiagnosticsAdapter };
|
|
100
|
-
function changeEventToIntervals(e) {
|
|
101
|
-
return e.changes.map(function (change) { return ({
|
|
102
|
-
start: change.rangeOffset,
|
|
103
|
-
end: change.rangeOffset + change.text.length,
|
|
104
|
-
}); });
|
|
105
|
-
}
|
|
106
|
-
function toSeverity(lsSeverity) {
|
|
107
|
-
switch (lsSeverity) {
|
|
108
|
-
case ls.DiagnosticSeverity.Error:
|
|
109
|
-
return monaco.MarkerSeverity.Error;
|
|
110
|
-
case ls.DiagnosticSeverity.Warning:
|
|
111
|
-
return monaco.MarkerSeverity.Warning;
|
|
112
|
-
case ls.DiagnosticSeverity.Information:
|
|
113
|
-
return monaco.MarkerSeverity.Info;
|
|
114
|
-
case ls.DiagnosticSeverity.Hint:
|
|
115
|
-
return monaco.MarkerSeverity.Hint;
|
|
116
|
-
default:
|
|
117
|
-
return monaco.MarkerSeverity.Info;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function toDiagnostics(resource, diag) {
|
|
121
|
-
var code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
|
|
122
|
-
return {
|
|
123
|
-
severity: toSeverity(diag.severity),
|
|
124
|
-
startLineNumber: diag.range.start.line + 1,
|
|
125
|
-
startColumn: diag.range.start.character + 1,
|
|
126
|
-
endLineNumber: diag.range.end.line + 1,
|
|
127
|
-
endColumn: diag.range.end.character + 1,
|
|
128
|
-
message: diag.message,
|
|
129
|
-
code: code,
|
|
130
|
-
source: diag.source,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
// --- colorization ---
|
|
134
|
-
function fromIRange(range) {
|
|
135
|
-
if (!range) {
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
if (range instanceof monaco.Range) {
|
|
139
|
-
return { start: fromPosition(range.getStartPosition()), end: fromPosition(range.getEndPosition()) };
|
|
140
|
-
}
|
|
141
|
-
var startLineNumber = range.startLineNumber, startColumn = range.startColumn, endLineNumber = range.endLineNumber, endColumn = range.endColumn;
|
|
142
|
-
range = new monaco.Range(startLineNumber, startColumn, endLineNumber, endColumn);
|
|
143
|
-
}
|
|
144
|
-
// commented here is the color definitions are were defined by v1 intellisense terminology:
|
|
145
|
-
// { token: 'comment', foreground: '008000' }, // CommentToken Green
|
|
146
|
-
// { token: 'variable.predefined', foreground: '800080' }, // CalculatedColumnToken Purple
|
|
147
|
-
// { token: 'function', foreground: '0000FF' }, // FunctionNameToken Blue
|
|
148
|
-
// { token: 'operator.sql', foreground: 'FF4500' }, // OperatorToken OrangeRed (now changed to darker color CC3700 because wasn't accessible)
|
|
149
|
-
// { token: 'string', foreground: 'B22222' }, // StringLiteralToken Firebrick
|
|
150
|
-
// { token: 'operator.scss', foreground: '0000FF' }, // SubOperatorToken Blue
|
|
151
|
-
// { token: 'variable', foreground: 'C71585' }, // TableColumnToken MediumVioletRed
|
|
152
|
-
// { token: 'variable.parameter', foreground: '9932CC' }, // TableToken DarkOrchid
|
|
153
|
-
// { token: '', foreground: '000000' }, // UnknownToken, PlainTextToken Black
|
|
154
|
-
// { token: 'type', foreground: '0000FF' }, // DataTypeToken Blue
|
|
155
|
-
// { token: 'tag', foreground: '0000FF' }, // ControlCommandToken Blue
|
|
156
|
-
// { token: 'annotation', foreground: '2B91AF' }, // QueryParametersToken FF2B91AF
|
|
157
|
-
// { token: 'keyword', foreground: '0000FF' }, // CslCommandToken, PluginToken Blue
|
|
158
|
-
// { token: 'number', foreground: '191970' }, // LetVariablesToken MidnightBlue
|
|
159
|
-
// { token: 'annotation', foreground: '9400D3' }, // ClientDirectiveToken DarkViolet
|
|
160
|
-
// { token: 'invalid', background: 'cd3131' },
|
|
161
|
-
var classificationToColorLight = {
|
|
162
|
-
Column: 'C71585',
|
|
163
|
-
Comment: '008000',
|
|
164
|
-
Database: 'C71585',
|
|
165
|
-
Function: '0000FF',
|
|
166
|
-
Identifier: '000000',
|
|
167
|
-
Keyword: '0000FF',
|
|
168
|
-
Literal: 'B22222',
|
|
169
|
-
ScalarOperator: '000000',
|
|
170
|
-
MaterializedView: 'C71585',
|
|
171
|
-
MathOperator: '000000',
|
|
172
|
-
Command: '0000FF',
|
|
173
|
-
Parameter: '2B91AF',
|
|
174
|
-
PlainText: '000000',
|
|
175
|
-
Punctuation: '000000',
|
|
176
|
-
QueryOperator: 'CC3700',
|
|
177
|
-
QueryParameter: 'CC3700',
|
|
178
|
-
StringLiteral: 'B22222',
|
|
179
|
-
Table: 'C71585',
|
|
180
|
-
Type: '0000FF',
|
|
181
|
-
Variable: '191970',
|
|
182
|
-
Directive: '9400D3',
|
|
183
|
-
ClientParameter: 'b5cea8',
|
|
184
|
-
SchemaMember: 'C71585',
|
|
185
|
-
SignatureParameter: '2B91AF',
|
|
186
|
-
Option: '000000',
|
|
187
|
-
};
|
|
188
|
-
var classificationToColorDark = {
|
|
189
|
-
Column: '4ec9b0',
|
|
190
|
-
Comment: '608B4E',
|
|
191
|
-
Database: 'c586c0',
|
|
192
|
-
Function: 'dcdcaa',
|
|
193
|
-
Identifier: 'd4d4d4',
|
|
194
|
-
Keyword: '569cd6',
|
|
195
|
-
Literal: 'ce9178',
|
|
196
|
-
ScalarOperator: 'd4d4d4',
|
|
197
|
-
MaterializedView: 'c586c0',
|
|
198
|
-
MathOperator: 'd4d4d4',
|
|
199
|
-
Command: 'd4d4d4',
|
|
200
|
-
Parameter: '2B91AF',
|
|
201
|
-
PlainText: 'd4d4d4',
|
|
202
|
-
Punctuation: 'd4d4d4',
|
|
203
|
-
QueryOperator: '9cdcfe',
|
|
204
|
-
QueryParameter: '9cdcfe',
|
|
205
|
-
StringLiteral: 'ce9178',
|
|
206
|
-
Table: 'c586c0',
|
|
207
|
-
Type: '569cd6',
|
|
208
|
-
Variable: 'd7ba7d',
|
|
209
|
-
Directive: 'b5cea8',
|
|
210
|
-
ClientParameter: 'b5cea8',
|
|
211
|
-
SchemaMember: '4ec9b0',
|
|
212
|
-
SignatureParameter: '2B91AF',
|
|
213
|
-
Option: 'd4d4d4',
|
|
214
|
-
};
|
|
215
|
-
var ColorizationAdapter = /** @class */ (function () {
|
|
216
|
-
function ColorizationAdapter(_languageId, _worker, defaults, onSchemaChange) {
|
|
217
|
-
var _this = this;
|
|
218
|
-
this._languageId = _languageId;
|
|
219
|
-
this._worker = _worker;
|
|
220
|
-
this._disposables = [];
|
|
221
|
-
this._contentListener = Object.create(null);
|
|
222
|
-
this._configurationListener = Object.create(null);
|
|
223
|
-
this._schemaListener = Object.create(null);
|
|
224
|
-
this.decorations = [];
|
|
225
|
-
injectCss();
|
|
226
|
-
var onModelAdd = function (model) {
|
|
227
|
-
var modeId = model.getModeId();
|
|
228
|
-
if (modeId !== _this._languageId) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
var debouncedColorization = _.debounce(function (intervals) { return _this._doColorization(model, modeId, intervals); }, 500);
|
|
232
|
-
var handle;
|
|
233
|
-
_this._contentListener[model.uri.toString()] = model.onDidChangeContent(function (e) {
|
|
234
|
-
// Changes are represented as a range in doc before change, plus the text that it was replaced with.
|
|
235
|
-
// We are interested in the range _after_ the change (since that's what we need to colorize).
|
|
236
|
-
// folowing logic calculates that.
|
|
237
|
-
var intervalsToColorize = changeEventToIntervals(e);
|
|
238
|
-
debouncedColorization(intervalsToColorize);
|
|
239
|
-
});
|
|
240
|
-
_this._configurationListener[model.uri.toString()] = defaults.onDidChange(function () {
|
|
241
|
-
self.setTimeout(function () { return _this._doColorization(model, modeId, []); }, 0);
|
|
242
|
-
});
|
|
243
|
-
_this._schemaListener[model.uri.toString()] = onSchemaChange(function () {
|
|
244
|
-
self.setTimeout(function () { return _this._doColorization(model, modeId, []); }, 0);
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
var onModelRemoved = function (model) {
|
|
248
|
-
model.deltaDecorations(_this.decorations, []);
|
|
249
|
-
var uriStr = model.uri.toString();
|
|
250
|
-
var contentListener = _this._contentListener[uriStr];
|
|
251
|
-
if (contentListener) {
|
|
252
|
-
contentListener.dispose();
|
|
253
|
-
delete _this._contentListener[uriStr];
|
|
254
|
-
}
|
|
255
|
-
var configurationListener = _this._configurationListener[uriStr];
|
|
256
|
-
if (configurationListener) {
|
|
257
|
-
configurationListener.dispose();
|
|
258
|
-
delete _this._configurationListener[uriStr];
|
|
259
|
-
}
|
|
260
|
-
var schemaListener = _this._configurationListener[uriStr];
|
|
261
|
-
if (schemaListener) {
|
|
262
|
-
schemaListener.dispose();
|
|
263
|
-
delete _this._schemaListener[uriStr];
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
|
|
267
|
-
this._disposables.push(monaco.editor.onWillDisposeModel(onModelRemoved));
|
|
268
|
-
this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
|
|
269
|
-
onModelRemoved(event.model);
|
|
270
|
-
onModelAdd(event.model);
|
|
271
|
-
}));
|
|
272
|
-
this._disposables.push({
|
|
273
|
-
dispose: function () {
|
|
274
|
-
for (var key in _this._contentListener) {
|
|
275
|
-
_this._contentListener[key].dispose();
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
monaco.editor.getModels().forEach(onModelAdd);
|
|
280
|
-
}
|
|
281
|
-
ColorizationAdapter.prototype.dispose = function () {
|
|
282
|
-
this._disposables.forEach(function (d) { return d && d.dispose(); });
|
|
283
|
-
this._disposables = [];
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* Return true if the range doesn't intersect any of the line ranges.
|
|
287
|
-
* @param range Range
|
|
288
|
-
* @param impactedLineRanges an array of line ranges
|
|
289
|
-
*/
|
|
290
|
-
ColorizationAdapter.prototype._rangeDoesNotIntersectAny = function (range, impactedLineRanges) {
|
|
291
|
-
return impactedLineRanges.every(function (lineRange) {
|
|
292
|
-
return range.startLineNumber > lineRange.lastImpactedLine || range.endLineNumber < lineRange.firstImpactedLine;
|
|
293
|
-
});
|
|
294
|
-
};
|
|
295
|
-
ColorizationAdapter.prototype._doColorization = function (model, languageId, intervals) {
|
|
296
|
-
var _this = this;
|
|
297
|
-
if (model.isDisposed()) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
var resource = model.uri;
|
|
301
|
-
var versionNumberBeforeColorization = model.getVersionId();
|
|
302
|
-
this._worker(resource)
|
|
303
|
-
.then(function (worker) {
|
|
304
|
-
return worker.doColorization(resource.toString(), intervals);
|
|
305
|
-
})
|
|
306
|
-
.then(function (colorizationRanges) {
|
|
307
|
-
var newModel = monaco.editor.getModel(model.uri);
|
|
308
|
-
var versionId = newModel.getVersionId();
|
|
309
|
-
// don't colorize an older version of the document.
|
|
310
|
-
if (versionId !== versionNumberBeforeColorization) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
var decorationRanges = colorizationRanges.map(function (colorizationRange) {
|
|
314
|
-
var decorations = colorizationRange.classifications
|
|
315
|
-
.map(function (classification) { return toDecoration(model, classification); })
|
|
316
|
-
// The following line will prevent things that aren't going to be colorized anyway to get a CSS class.
|
|
317
|
-
// This will prevent the case where the non-semantic colorizer already figured out that a keyword needs
|
|
318
|
-
// to be colorized, but the outdated semantic colorizer still thinks it's a plain text and wants it colored
|
|
319
|
-
// in black.
|
|
320
|
-
.filter(function (d) {
|
|
321
|
-
return d.options.inlineClassName !== 'PlainText' && d.options.inlineClassName != 'Identifier';
|
|
322
|
-
});
|
|
323
|
-
var firstImpactedLine = model.getPositionAt(colorizationRange.absoluteStart).lineNumber;
|
|
324
|
-
var endPosition = model.getPositionAt(colorizationRange.absoluteEnd);
|
|
325
|
-
// A token that ends in the first column of the next line is not considered to be part of that line.
|
|
326
|
-
var lastImpactedLine = endPosition.column == 1 && endPosition.lineNumber > 1
|
|
327
|
-
? endPosition.lineNumber - 1
|
|
328
|
-
: endPosition.lineNumber;
|
|
329
|
-
return { decorations: decorations, firstImpactedLine: firstImpactedLine, lastImpactedLine: lastImpactedLine };
|
|
330
|
-
});
|
|
331
|
-
// Compute the previous decorations we want to replace with the new ones.
|
|
332
|
-
var oldDecorations = decorationRanges
|
|
333
|
-
.map(function (range) {
|
|
334
|
-
return model
|
|
335
|
-
.getLinesDecorations(range.firstImpactedLine, range.lastImpactedLine)
|
|
336
|
-
.filter(function (d) { return classificationToColorLight[d.options.inlineClassName]; }) // Don't delete any other decorations
|
|
337
|
-
.map(function (d) { return d.id; });
|
|
338
|
-
})
|
|
339
|
-
.reduce(function (prev, curr) { return prev.concat(curr); }, []);
|
|
340
|
-
// Flatten decoration groups to an array of decorations
|
|
341
|
-
var newDecorations = decorationRanges.reduce(function (prev, next) { return prev.concat(next.decorations); }, []);
|
|
342
|
-
if (model && model.getModeId() === languageId) {
|
|
343
|
-
_this.decorations = model.deltaDecorations(oldDecorations, newDecorations);
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
.then(undefined, function (err) {
|
|
347
|
-
console.error(err);
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
return ColorizationAdapter;
|
|
351
|
-
}());
|
|
352
|
-
export { ColorizationAdapter };
|
|
353
|
-
/**
|
|
354
|
-
* Gets all keys of an enum (the string keys not the numeric values).
|
|
355
|
-
* @param e Enum type
|
|
356
|
-
*/
|
|
357
|
-
function getEnumKeys(e) {
|
|
358
|
-
return Object.keys(e).filter(function (k) { return typeof e[k] === 'number'; });
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Generates a mapping between ClassificationKind and color.
|
|
362
|
-
*/
|
|
363
|
-
function getClassificationColorTriplets() {
|
|
364
|
-
var keys = getEnumKeys(ClassificationKind);
|
|
365
|
-
var result = keys.map(function (key) { return ({
|
|
366
|
-
classification: key,
|
|
367
|
-
colorLight: classificationToColorLight[key],
|
|
368
|
-
colorDark: classificationToColorDark[key],
|
|
369
|
-
}); });
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Returns a string which is a css describing all tokens and their colors.
|
|
374
|
-
* looks a little bit something like this:
|
|
375
|
-
*
|
|
376
|
-
* .vs .Literal {color: '#000000';} .vs-dark .Literal {color: '#FFFFFF';}
|
|
377
|
-
* .vs .Comment {color: '#111111';} .vs-dark .Comment {color: '#EEEEEE';}
|
|
378
|
-
*/
|
|
379
|
-
function getCssForClassification() {
|
|
380
|
-
var classificationColorTriplets = getClassificationColorTriplets();
|
|
381
|
-
var cssInnerHtml = classificationColorTriplets
|
|
382
|
-
.map(function (pair) {
|
|
383
|
-
return ".vs ." + pair.classification + " {color: #" + pair.colorLight + ";} .vs-dark ." + pair.classification + " {color: #" + pair.colorDark + ";}";
|
|
384
|
-
})
|
|
385
|
-
.join('\n');
|
|
386
|
-
return cssInnerHtml;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Inject a CSS sheet to the head of document, coloring kusto elements by classification.
|
|
390
|
-
* TODO: make idempotent
|
|
391
|
-
*/
|
|
392
|
-
function injectCss() {
|
|
393
|
-
var container = document.getElementsByTagName('head')[0];
|
|
394
|
-
var style = document.createElement('style');
|
|
395
|
-
style.type = 'text/css';
|
|
396
|
-
style.media = 'screen';
|
|
397
|
-
container.appendChild(style);
|
|
398
|
-
ClassificationKind;
|
|
399
|
-
style.innerHTML = getCssForClassification();
|
|
400
|
-
}
|
|
401
|
-
function toDecoration(model, classification) {
|
|
402
|
-
var start = model.getPositionAt(classification.start);
|
|
403
|
-
var end = model.getPositionAt(classification.start + classification.length);
|
|
404
|
-
var range = new Range(start.lineNumber, start.column, end.lineNumber, end.column);
|
|
405
|
-
var inlineClassName = ClassificationKind.$names[classification.kind];
|
|
406
|
-
return {
|
|
407
|
-
range: range,
|
|
408
|
-
options: {
|
|
409
|
-
inlineClassName: inlineClassName,
|
|
410
|
-
stickiness: monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
411
|
-
},
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
// --- completion ------
|
|
415
|
-
function fromPosition(position) {
|
|
416
|
-
if (!position) {
|
|
417
|
-
return void 0;
|
|
418
|
-
}
|
|
419
|
-
return { character: position.column - 1, line: position.lineNumber - 1 };
|
|
420
|
-
}
|
|
421
|
-
function fromRange(range) {
|
|
422
|
-
if (!range) {
|
|
423
|
-
return void 0;
|
|
424
|
-
}
|
|
425
|
-
return { start: fromPosition(range.getStartPosition()), end: fromPosition(range.getEndPosition()) };
|
|
426
|
-
}
|
|
427
|
-
function toRange(range) {
|
|
428
|
-
if (!range) {
|
|
429
|
-
return void 0;
|
|
430
|
-
}
|
|
431
|
-
return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
|
|
432
|
-
}
|
|
433
|
-
function toCompletionItemKind(kind) {
|
|
434
|
-
var mItemKind = monaco.languages.CompletionItemKind;
|
|
435
|
-
switch (kind) {
|
|
436
|
-
case ls.CompletionItemKind.Text:
|
|
437
|
-
return mItemKind.Text;
|
|
438
|
-
case ls.CompletionItemKind.Method:
|
|
439
|
-
return mItemKind.Method;
|
|
440
|
-
case ls.CompletionItemKind.Function:
|
|
441
|
-
return mItemKind.Function;
|
|
442
|
-
case ls.CompletionItemKind.Constructor:
|
|
443
|
-
return mItemKind.Constructor;
|
|
444
|
-
case ls.CompletionItemKind.Field:
|
|
445
|
-
return mItemKind.Field;
|
|
446
|
-
case ls.CompletionItemKind.Variable:
|
|
447
|
-
return mItemKind.Variable;
|
|
448
|
-
case ls.CompletionItemKind.Class:
|
|
449
|
-
return mItemKind.Class;
|
|
450
|
-
case ls.CompletionItemKind.Interface:
|
|
451
|
-
return mItemKind.Interface;
|
|
452
|
-
case ls.CompletionItemKind.Module:
|
|
453
|
-
return mItemKind.Module;
|
|
454
|
-
case ls.CompletionItemKind.Property:
|
|
455
|
-
return mItemKind.Property;
|
|
456
|
-
case ls.CompletionItemKind.Unit:
|
|
457
|
-
return mItemKind.Unit;
|
|
458
|
-
case ls.CompletionItemKind.Value:
|
|
459
|
-
return mItemKind.Value;
|
|
460
|
-
case ls.CompletionItemKind.Enum:
|
|
461
|
-
return mItemKind.Enum;
|
|
462
|
-
case ls.CompletionItemKind.Keyword:
|
|
463
|
-
return mItemKind.Keyword;
|
|
464
|
-
case ls.CompletionItemKind.Snippet:
|
|
465
|
-
return mItemKind.Snippet;
|
|
466
|
-
case ls.CompletionItemKind.Color:
|
|
467
|
-
return mItemKind.Color;
|
|
468
|
-
case ls.CompletionItemKind.File:
|
|
469
|
-
return mItemKind.File;
|
|
470
|
-
case ls.CompletionItemKind.Reference:
|
|
471
|
-
return mItemKind.Reference;
|
|
472
|
-
}
|
|
473
|
-
return mItemKind.Property;
|
|
474
|
-
}
|
|
475
|
-
function toTextEdit(textEdit) {
|
|
476
|
-
if (!textEdit) {
|
|
477
|
-
return void 0;
|
|
478
|
-
}
|
|
479
|
-
return {
|
|
480
|
-
range: toRange(textEdit.range),
|
|
481
|
-
text: textEdit.newText,
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
var CompletionAdapter = /** @class */ (function () {
|
|
485
|
-
function CompletionAdapter(_worker, languageSettings) {
|
|
486
|
-
this._worker = _worker;
|
|
487
|
-
this.languageSettings = languageSettings;
|
|
488
|
-
}
|
|
489
|
-
Object.defineProperty(CompletionAdapter.prototype, "triggerCharacters", {
|
|
490
|
-
get: function () {
|
|
491
|
-
return [' '];
|
|
492
|
-
},
|
|
493
|
-
enumerable: false,
|
|
494
|
-
configurable: true
|
|
495
|
-
});
|
|
496
|
-
CompletionAdapter.prototype.provideCompletionItems = function (model, position, context, token) {
|
|
497
|
-
var wordInfo = model.getWordUntilPosition(position);
|
|
498
|
-
var wordRange = new Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
|
|
499
|
-
var resource = model.uri;
|
|
500
|
-
var onDidProvideCompletionItems = this.languageSettings
|
|
501
|
-
.onDidProvideCompletionItems;
|
|
502
|
-
return this._worker(resource)
|
|
503
|
-
.then(function (worker) {
|
|
504
|
-
return worker.doComplete(resource.toString(), fromPosition(position));
|
|
505
|
-
})
|
|
506
|
-
.then(function (info) { return (onDidProvideCompletionItems ? onDidProvideCompletionItems(info) : info); })
|
|
507
|
-
.then(function (info) {
|
|
508
|
-
if (!info) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
var items = info.items.map(function (entry) {
|
|
512
|
-
var item = {
|
|
513
|
-
label: entry.label,
|
|
514
|
-
insertText: entry.insertText,
|
|
515
|
-
sortText: entry.sortText,
|
|
516
|
-
filterText: entry.filterText,
|
|
517
|
-
documentation: entry.documentation,
|
|
518
|
-
detail: entry.detail,
|
|
519
|
-
range: wordRange,
|
|
520
|
-
kind: toCompletionItemKind(entry.kind),
|
|
521
|
-
};
|
|
522
|
-
if (entry.textEdit) {
|
|
523
|
-
item.range = toRange(entry.textEdit.range);
|
|
524
|
-
item.insertText = entry.textEdit.newText;
|
|
525
|
-
}
|
|
526
|
-
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
527
|
-
item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
528
|
-
}
|
|
529
|
-
return item;
|
|
530
|
-
});
|
|
531
|
-
return {
|
|
532
|
-
isIncomplete: info.isIncomplete,
|
|
533
|
-
suggestions: items,
|
|
534
|
-
};
|
|
535
|
-
});
|
|
536
|
-
};
|
|
537
|
-
return CompletionAdapter;
|
|
538
|
-
}());
|
|
539
|
-
export { CompletionAdapter };
|
|
540
|
-
function isMarkupContent(thing) {
|
|
541
|
-
return thing && typeof thing === 'object' && typeof thing.kind === 'string';
|
|
542
|
-
}
|
|
543
|
-
function toMarkdownString(entry) {
|
|
544
|
-
if (typeof entry === 'string') {
|
|
545
|
-
return {
|
|
546
|
-
value: entry,
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
if (isMarkupContent(entry)) {
|
|
550
|
-
if (entry.kind === 'plaintext') {
|
|
551
|
-
return {
|
|
552
|
-
value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'),
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
return {
|
|
556
|
-
value: entry.value,
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
return { value: '```' + entry.value + '\n' + entry.value + '\n```\n' };
|
|
560
|
-
}
|
|
561
|
-
function toMarkedStringArray(contents) {
|
|
562
|
-
if (!contents) {
|
|
563
|
-
return void 0;
|
|
564
|
-
}
|
|
565
|
-
if (Array.isArray(contents)) {
|
|
566
|
-
return contents.map(toMarkdownString);
|
|
567
|
-
}
|
|
568
|
-
return [toMarkdownString(contents)];
|
|
569
|
-
}
|
|
570
|
-
// --- definition ------
|
|
571
|
-
function toLocation(location) {
|
|
572
|
-
return {
|
|
573
|
-
uri: Uri.parse(location.uri),
|
|
574
|
-
range: toRange(location.range),
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
var DefinitionAdapter = /** @class */ (function () {
|
|
578
|
-
function DefinitionAdapter(_worker) {
|
|
579
|
-
this._worker = _worker;
|
|
580
|
-
}
|
|
581
|
-
DefinitionAdapter.prototype.provideDefinition = function (model, position, token) {
|
|
582
|
-
var resource = model.uri;
|
|
583
|
-
return this._worker(resource)
|
|
584
|
-
.then(function (worker) {
|
|
585
|
-
return worker.findDefinition(resource.toString(), fromPosition(position));
|
|
586
|
-
})
|
|
587
|
-
.then(function (definition) {
|
|
588
|
-
if (!definition || definition.length == 0) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
return [toLocation(definition[0])];
|
|
592
|
-
});
|
|
593
|
-
};
|
|
594
|
-
return DefinitionAdapter;
|
|
595
|
-
}());
|
|
596
|
-
export { DefinitionAdapter };
|
|
597
|
-
// --- references ------
|
|
598
|
-
var ReferenceAdapter = /** @class */ (function () {
|
|
599
|
-
function ReferenceAdapter(_worker) {
|
|
600
|
-
this._worker = _worker;
|
|
601
|
-
}
|
|
602
|
-
ReferenceAdapter.prototype.provideReferences = function (model, position, context, token) {
|
|
603
|
-
var resource = model.uri;
|
|
604
|
-
return this._worker(resource)
|
|
605
|
-
.then(function (worker) {
|
|
606
|
-
return worker.findReferences(resource.toString(), fromPosition(position));
|
|
607
|
-
})
|
|
608
|
-
.then(function (entries) {
|
|
609
|
-
if (!entries) {
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
return entries.map(toLocation);
|
|
613
|
-
});
|
|
614
|
-
};
|
|
615
|
-
return ReferenceAdapter;
|
|
616
|
-
}());
|
|
617
|
-
export { ReferenceAdapter };
|
|
618
|
-
// --- rename ------
|
|
619
|
-
function toWorkspaceEdit(edit) {
|
|
620
|
-
if (!edit || !edit.changes) {
|
|
621
|
-
return void 0;
|
|
622
|
-
}
|
|
623
|
-
var resourceEdits = [];
|
|
624
|
-
for (var uri in edit.changes) {
|
|
625
|
-
var _uri = Uri.parse(uri);
|
|
626
|
-
for (var _i = 0, _a = edit.changes[uri]; _i < _a.length; _i++) {
|
|
627
|
-
var e = _a[_i];
|
|
628
|
-
resourceEdits.push({
|
|
629
|
-
resource: _uri,
|
|
630
|
-
edit: {
|
|
631
|
-
range: toRange(e.range),
|
|
632
|
-
text: e.newText,
|
|
633
|
-
},
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return {
|
|
638
|
-
edits: resourceEdits,
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
var RenameAdapter = /** @class */ (function () {
|
|
642
|
-
function RenameAdapter(_worker) {
|
|
643
|
-
this._worker = _worker;
|
|
644
|
-
}
|
|
645
|
-
RenameAdapter.prototype.provideRenameEdits = function (model, position, newName, token) {
|
|
646
|
-
var resource = model.uri;
|
|
647
|
-
return this._worker(resource)
|
|
648
|
-
.then(function (worker) {
|
|
649
|
-
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
650
|
-
})
|
|
651
|
-
.then(function (edit) {
|
|
652
|
-
return toWorkspaceEdit(edit);
|
|
653
|
-
});
|
|
654
|
-
};
|
|
655
|
-
return RenameAdapter;
|
|
656
|
-
}());
|
|
657
|
-
export { RenameAdapter };
|
|
658
|
-
// --- document symbols ------
|
|
659
|
-
function toSymbolKind(kind) {
|
|
660
|
-
var mKind = monaco.languages.SymbolKind;
|
|
661
|
-
switch (kind) {
|
|
662
|
-
case ls.SymbolKind.File:
|
|
663
|
-
return mKind.Array;
|
|
664
|
-
case ls.SymbolKind.Module:
|
|
665
|
-
return mKind.Module;
|
|
666
|
-
case ls.SymbolKind.Namespace:
|
|
667
|
-
return mKind.Namespace;
|
|
668
|
-
case ls.SymbolKind.Package:
|
|
669
|
-
return mKind.Package;
|
|
670
|
-
case ls.SymbolKind.Class:
|
|
671
|
-
return mKind.Class;
|
|
672
|
-
case ls.SymbolKind.Method:
|
|
673
|
-
return mKind.Method;
|
|
674
|
-
case ls.SymbolKind.Property:
|
|
675
|
-
return mKind.Property;
|
|
676
|
-
case ls.SymbolKind.Field:
|
|
677
|
-
return mKind.Field;
|
|
678
|
-
case ls.SymbolKind.Constructor:
|
|
679
|
-
return mKind.Constructor;
|
|
680
|
-
case ls.SymbolKind.Enum:
|
|
681
|
-
return mKind.Enum;
|
|
682
|
-
case ls.SymbolKind.Interface:
|
|
683
|
-
return mKind.Interface;
|
|
684
|
-
case ls.SymbolKind.Function:
|
|
685
|
-
return mKind.Function;
|
|
686
|
-
case ls.SymbolKind.Variable:
|
|
687
|
-
return mKind.Variable;
|
|
688
|
-
case ls.SymbolKind.Constant:
|
|
689
|
-
return mKind.Constant;
|
|
690
|
-
case ls.SymbolKind.String:
|
|
691
|
-
return mKind.String;
|
|
692
|
-
case ls.SymbolKind.Number:
|
|
693
|
-
return mKind.Number;
|
|
694
|
-
case ls.SymbolKind.Boolean:
|
|
695
|
-
return mKind.Boolean;
|
|
696
|
-
case ls.SymbolKind.Array:
|
|
697
|
-
return mKind.Array;
|
|
698
|
-
}
|
|
699
|
-
return mKind.Function;
|
|
700
|
-
}
|
|
701
|
-
// --- formatting -----
|
|
702
|
-
var DocumentFormatAdapter = /** @class */ (function () {
|
|
703
|
-
function DocumentFormatAdapter(_worker) {
|
|
704
|
-
this._worker = _worker;
|
|
705
|
-
}
|
|
706
|
-
DocumentFormatAdapter.prototype.provideDocumentFormattingEdits = function (model, options, token) {
|
|
707
|
-
var resource = model.uri;
|
|
708
|
-
return this._worker(resource).then(function (worker) {
|
|
709
|
-
return worker.doDocumentFormat(resource.toString()).then(function (edits) { return edits.map(function (edit) { return toTextEdit(edit); }); });
|
|
710
|
-
});
|
|
711
|
-
};
|
|
712
|
-
return DocumentFormatAdapter;
|
|
713
|
-
}());
|
|
714
|
-
export { DocumentFormatAdapter };
|
|
715
|
-
var FormatAdapter = /** @class */ (function () {
|
|
716
|
-
function FormatAdapter(_worker) {
|
|
717
|
-
this._worker = _worker;
|
|
718
|
-
}
|
|
719
|
-
FormatAdapter.prototype.provideDocumentRangeFormattingEdits = function (model, range, options, token) {
|
|
720
|
-
var resource = model.uri;
|
|
721
|
-
return this._worker(resource).then(function (worker) {
|
|
722
|
-
return worker
|
|
723
|
-
.doRangeFormat(resource.toString(), fromRange(range))
|
|
724
|
-
.then(function (edits) { return edits.map(function (edit) { return toTextEdit(edit); }); });
|
|
725
|
-
});
|
|
726
|
-
};
|
|
727
|
-
return FormatAdapter;
|
|
728
|
-
}());
|
|
729
|
-
export { FormatAdapter };
|
|
730
|
-
// --- Folding ---
|
|
731
|
-
var FoldingAdapter = /** @class */ (function () {
|
|
732
|
-
function FoldingAdapter(_worker) {
|
|
733
|
-
this._worker = _worker;
|
|
734
|
-
}
|
|
735
|
-
FoldingAdapter.prototype.provideFoldingRanges = function (model, context, token) {
|
|
736
|
-
var resource = model.uri;
|
|
737
|
-
return this._worker(resource).then(function (worker) {
|
|
738
|
-
return worker
|
|
739
|
-
.doFolding(resource.toString())
|
|
740
|
-
.then(function (foldingRanges) {
|
|
741
|
-
return foldingRanges.map(function (range) { return toFoldingRange(range); });
|
|
742
|
-
});
|
|
743
|
-
});
|
|
744
|
-
};
|
|
745
|
-
return FoldingAdapter;
|
|
746
|
-
}());
|
|
747
|
-
export { FoldingAdapter };
|
|
748
|
-
function toFoldingRange(range) {
|
|
749
|
-
return {
|
|
750
|
-
start: range.startLine + 1,
|
|
751
|
-
end: range.endLine + 1,
|
|
752
|
-
kind: monaco.languages.FoldingRangeKind.Region,
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
// --- hover ------
|
|
756
|
-
var HoverAdapter = /** @class */ (function () {
|
|
757
|
-
function HoverAdapter(_worker) {
|
|
758
|
-
this._worker = _worker;
|
|
759
|
-
}
|
|
760
|
-
HoverAdapter.prototype.provideHover = function (model, position, token) {
|
|
761
|
-
var resource = model.uri;
|
|
762
|
-
return this._worker(resource)
|
|
763
|
-
.then(function (worker) {
|
|
764
|
-
return worker.doHover(resource.toString(), fromPosition(position));
|
|
765
|
-
})
|
|
766
|
-
.then(function (info) {
|
|
767
|
-
if (!info) {
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
return {
|
|
771
|
-
range: toRange(info.range),
|
|
772
|
-
contents: toMarkedStringArray(info.contents),
|
|
773
|
-
};
|
|
774
|
-
});
|
|
775
|
-
};
|
|
776
|
-
return HoverAdapter;
|
|
777
|
-
}());
|
|
778
|
-
export { HoverAdapter };
|
|
1
|
+
import * as ls from './_deps/vscode-languageserver-types/main';
|
|
2
|
+
import * as _ from './_deps/lodash/lodash';
|
|
3
|
+
var Uri = monaco.Uri;
|
|
4
|
+
var Range = monaco.Range;
|
|
5
|
+
var ClassificationKind = Kusto.Language.Editor.ClassificationKind;
|
|
6
|
+
// --- diagnostics ---
|
|
7
|
+
var DiagnosticsAdapter = /** @class */ (function () {
|
|
8
|
+
function DiagnosticsAdapter(_languageId, _worker, defaults, onSchemaChange) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
this._languageId = _languageId;
|
|
11
|
+
this._worker = _worker;
|
|
12
|
+
this._disposables = [];
|
|
13
|
+
this._contentListener = Object.create(null);
|
|
14
|
+
this._configurationListener = Object.create(null);
|
|
15
|
+
this._schemaListener = Object.create(null);
|
|
16
|
+
var onModelAdd = function (model) {
|
|
17
|
+
var modeId = model.getModeId();
|
|
18
|
+
if (modeId !== _this._languageId) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var debouncedValidation = _.debounce(function (intervals) { return _this._doValidate(model, modeId, intervals); }, 500);
|
|
22
|
+
_this._contentListener[model.uri.toString()] = model.onDidChangeContent(function (e) {
|
|
23
|
+
var intervalsToValidate = changeEventToIntervals(e);
|
|
24
|
+
debouncedValidation(intervalsToValidate);
|
|
25
|
+
});
|
|
26
|
+
_this._configurationListener[model.uri.toString()] = defaults.onDidChange(function () {
|
|
27
|
+
self.setTimeout(function () { return _this._doValidate(model, modeId, []); }, 0);
|
|
28
|
+
});
|
|
29
|
+
_this._schemaListener[model.uri.toString()] = onSchemaChange(function () {
|
|
30
|
+
self.setTimeout(function () { return _this._doValidate(model, modeId, []); }, 0);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
var onModelRemoved = function (model) {
|
|
34
|
+
monaco.editor.setModelMarkers(model, _this._languageId, []);
|
|
35
|
+
var uriStr = model.uri.toString();
|
|
36
|
+
var contentListener = _this._contentListener[uriStr];
|
|
37
|
+
if (contentListener) {
|
|
38
|
+
contentListener.dispose();
|
|
39
|
+
delete _this._contentListener[uriStr];
|
|
40
|
+
}
|
|
41
|
+
var configurationListener = _this._configurationListener[uriStr];
|
|
42
|
+
if (configurationListener) {
|
|
43
|
+
configurationListener.dispose();
|
|
44
|
+
delete _this._configurationListener[uriStr];
|
|
45
|
+
}
|
|
46
|
+
var schemaListener = _this._schemaListener[uriStr];
|
|
47
|
+
if (schemaListener) {
|
|
48
|
+
schemaListener.dispose();
|
|
49
|
+
delete _this._schemaListener[uriStr];
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
|
|
53
|
+
this._disposables.push(monaco.editor.onWillDisposeModel(onModelRemoved));
|
|
54
|
+
this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
|
|
55
|
+
onModelRemoved(event.model);
|
|
56
|
+
onModelAdd(event.model);
|
|
57
|
+
}));
|
|
58
|
+
this._disposables.push({
|
|
59
|
+
dispose: function () {
|
|
60
|
+
for (var key in _this._contentListener) {
|
|
61
|
+
_this._contentListener[key].dispose();
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
monaco.editor.getModels().forEach(onModelAdd);
|
|
66
|
+
}
|
|
67
|
+
DiagnosticsAdapter.prototype.dispose = function () {
|
|
68
|
+
this._disposables.forEach(function (d) { return d && d.dispose(); });
|
|
69
|
+
this._disposables = [];
|
|
70
|
+
};
|
|
71
|
+
DiagnosticsAdapter.prototype._doValidate = function (model, languageId, intervals) {
|
|
72
|
+
if (model.isDisposed()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var resource = model.uri;
|
|
76
|
+
var versionNumberBefore = model.getVersionId();
|
|
77
|
+
this._worker(resource)
|
|
78
|
+
.then(function (worker) {
|
|
79
|
+
return worker.doValidation(resource.toString(), intervals);
|
|
80
|
+
})
|
|
81
|
+
.then(function (diagnostics) {
|
|
82
|
+
var newModel = monaco.editor.getModel(resource);
|
|
83
|
+
var versionId = newModel.getVersionId();
|
|
84
|
+
if (versionId !== versionNumberBefore) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
var markers = diagnostics.map(function (d) { return toDiagnostics(resource, d); });
|
|
88
|
+
var model = monaco.editor.getModel(resource);
|
|
89
|
+
if (model && model.getModeId() === languageId) {
|
|
90
|
+
monaco.editor.setModelMarkers(model, languageId, markers);
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
.then(undefined, function (err) {
|
|
94
|
+
console.error(err);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return DiagnosticsAdapter;
|
|
98
|
+
}());
|
|
99
|
+
export { DiagnosticsAdapter };
|
|
100
|
+
function changeEventToIntervals(e) {
|
|
101
|
+
return e.changes.map(function (change) { return ({
|
|
102
|
+
start: change.rangeOffset,
|
|
103
|
+
end: change.rangeOffset + change.text.length,
|
|
104
|
+
}); });
|
|
105
|
+
}
|
|
106
|
+
function toSeverity(lsSeverity) {
|
|
107
|
+
switch (lsSeverity) {
|
|
108
|
+
case ls.DiagnosticSeverity.Error:
|
|
109
|
+
return monaco.MarkerSeverity.Error;
|
|
110
|
+
case ls.DiagnosticSeverity.Warning:
|
|
111
|
+
return monaco.MarkerSeverity.Warning;
|
|
112
|
+
case ls.DiagnosticSeverity.Information:
|
|
113
|
+
return monaco.MarkerSeverity.Info;
|
|
114
|
+
case ls.DiagnosticSeverity.Hint:
|
|
115
|
+
return monaco.MarkerSeverity.Hint;
|
|
116
|
+
default:
|
|
117
|
+
return monaco.MarkerSeverity.Info;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function toDiagnostics(resource, diag) {
|
|
121
|
+
var code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
|
|
122
|
+
return {
|
|
123
|
+
severity: toSeverity(diag.severity),
|
|
124
|
+
startLineNumber: diag.range.start.line + 1,
|
|
125
|
+
startColumn: diag.range.start.character + 1,
|
|
126
|
+
endLineNumber: diag.range.end.line + 1,
|
|
127
|
+
endColumn: diag.range.end.character + 1,
|
|
128
|
+
message: diag.message,
|
|
129
|
+
code: code,
|
|
130
|
+
source: diag.source,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// --- colorization ---
|
|
134
|
+
function fromIRange(range) {
|
|
135
|
+
if (!range) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
if (range instanceof monaco.Range) {
|
|
139
|
+
return { start: fromPosition(range.getStartPosition()), end: fromPosition(range.getEndPosition()) };
|
|
140
|
+
}
|
|
141
|
+
var startLineNumber = range.startLineNumber, startColumn = range.startColumn, endLineNumber = range.endLineNumber, endColumn = range.endColumn;
|
|
142
|
+
range = new monaco.Range(startLineNumber, startColumn, endLineNumber, endColumn);
|
|
143
|
+
}
|
|
144
|
+
// commented here is the color definitions are were defined by v1 intellisense terminology:
|
|
145
|
+
// { token: 'comment', foreground: '008000' }, // CommentToken Green
|
|
146
|
+
// { token: 'variable.predefined', foreground: '800080' }, // CalculatedColumnToken Purple
|
|
147
|
+
// { token: 'function', foreground: '0000FF' }, // FunctionNameToken Blue
|
|
148
|
+
// { token: 'operator.sql', foreground: 'FF4500' }, // OperatorToken OrangeRed (now changed to darker color CC3700 because wasn't accessible)
|
|
149
|
+
// { token: 'string', foreground: 'B22222' }, // StringLiteralToken Firebrick
|
|
150
|
+
// { token: 'operator.scss', foreground: '0000FF' }, // SubOperatorToken Blue
|
|
151
|
+
// { token: 'variable', foreground: 'C71585' }, // TableColumnToken MediumVioletRed
|
|
152
|
+
// { token: 'variable.parameter', foreground: '9932CC' }, // TableToken DarkOrchid
|
|
153
|
+
// { token: '', foreground: '000000' }, // UnknownToken, PlainTextToken Black
|
|
154
|
+
// { token: 'type', foreground: '0000FF' }, // DataTypeToken Blue
|
|
155
|
+
// { token: 'tag', foreground: '0000FF' }, // ControlCommandToken Blue
|
|
156
|
+
// { token: 'annotation', foreground: '2B91AF' }, // QueryParametersToken FF2B91AF
|
|
157
|
+
// { token: 'keyword', foreground: '0000FF' }, // CslCommandToken, PluginToken Blue
|
|
158
|
+
// { token: 'number', foreground: '191970' }, // LetVariablesToken MidnightBlue
|
|
159
|
+
// { token: 'annotation', foreground: '9400D3' }, // ClientDirectiveToken DarkViolet
|
|
160
|
+
// { token: 'invalid', background: 'cd3131' },
|
|
161
|
+
var classificationToColorLight = {
|
|
162
|
+
Column: 'C71585',
|
|
163
|
+
Comment: '008000',
|
|
164
|
+
Database: 'C71585',
|
|
165
|
+
Function: '0000FF',
|
|
166
|
+
Identifier: '000000',
|
|
167
|
+
Keyword: '0000FF',
|
|
168
|
+
Literal: 'B22222',
|
|
169
|
+
ScalarOperator: '000000',
|
|
170
|
+
MaterializedView: 'C71585',
|
|
171
|
+
MathOperator: '000000',
|
|
172
|
+
Command: '0000FF',
|
|
173
|
+
Parameter: '2B91AF',
|
|
174
|
+
PlainText: '000000',
|
|
175
|
+
Punctuation: '000000',
|
|
176
|
+
QueryOperator: 'CC3700',
|
|
177
|
+
QueryParameter: 'CC3700',
|
|
178
|
+
StringLiteral: 'B22222',
|
|
179
|
+
Table: 'C71585',
|
|
180
|
+
Type: '0000FF',
|
|
181
|
+
Variable: '191970',
|
|
182
|
+
Directive: '9400D3',
|
|
183
|
+
ClientParameter: 'b5cea8',
|
|
184
|
+
SchemaMember: 'C71585',
|
|
185
|
+
SignatureParameter: '2B91AF',
|
|
186
|
+
Option: '000000',
|
|
187
|
+
};
|
|
188
|
+
var classificationToColorDark = {
|
|
189
|
+
Column: '4ec9b0',
|
|
190
|
+
Comment: '608B4E',
|
|
191
|
+
Database: 'c586c0',
|
|
192
|
+
Function: 'dcdcaa',
|
|
193
|
+
Identifier: 'd4d4d4',
|
|
194
|
+
Keyword: '569cd6',
|
|
195
|
+
Literal: 'ce9178',
|
|
196
|
+
ScalarOperator: 'd4d4d4',
|
|
197
|
+
MaterializedView: 'c586c0',
|
|
198
|
+
MathOperator: 'd4d4d4',
|
|
199
|
+
Command: 'd4d4d4',
|
|
200
|
+
Parameter: '2B91AF',
|
|
201
|
+
PlainText: 'd4d4d4',
|
|
202
|
+
Punctuation: 'd4d4d4',
|
|
203
|
+
QueryOperator: '9cdcfe',
|
|
204
|
+
QueryParameter: '9cdcfe',
|
|
205
|
+
StringLiteral: 'ce9178',
|
|
206
|
+
Table: 'c586c0',
|
|
207
|
+
Type: '569cd6',
|
|
208
|
+
Variable: 'd7ba7d',
|
|
209
|
+
Directive: 'b5cea8',
|
|
210
|
+
ClientParameter: 'b5cea8',
|
|
211
|
+
SchemaMember: '4ec9b0',
|
|
212
|
+
SignatureParameter: '2B91AF',
|
|
213
|
+
Option: 'd4d4d4',
|
|
214
|
+
};
|
|
215
|
+
var ColorizationAdapter = /** @class */ (function () {
|
|
216
|
+
function ColorizationAdapter(_languageId, _worker, defaults, onSchemaChange) {
|
|
217
|
+
var _this = this;
|
|
218
|
+
this._languageId = _languageId;
|
|
219
|
+
this._worker = _worker;
|
|
220
|
+
this._disposables = [];
|
|
221
|
+
this._contentListener = Object.create(null);
|
|
222
|
+
this._configurationListener = Object.create(null);
|
|
223
|
+
this._schemaListener = Object.create(null);
|
|
224
|
+
this.decorations = [];
|
|
225
|
+
injectCss();
|
|
226
|
+
var onModelAdd = function (model) {
|
|
227
|
+
var modeId = model.getModeId();
|
|
228
|
+
if (modeId !== _this._languageId) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
var debouncedColorization = _.debounce(function (intervals) { return _this._doColorization(model, modeId, intervals); }, 500);
|
|
232
|
+
var handle;
|
|
233
|
+
_this._contentListener[model.uri.toString()] = model.onDidChangeContent(function (e) {
|
|
234
|
+
// Changes are represented as a range in doc before change, plus the text that it was replaced with.
|
|
235
|
+
// We are interested in the range _after_ the change (since that's what we need to colorize).
|
|
236
|
+
// folowing logic calculates that.
|
|
237
|
+
var intervalsToColorize = changeEventToIntervals(e);
|
|
238
|
+
debouncedColorization(intervalsToColorize);
|
|
239
|
+
});
|
|
240
|
+
_this._configurationListener[model.uri.toString()] = defaults.onDidChange(function () {
|
|
241
|
+
self.setTimeout(function () { return _this._doColorization(model, modeId, []); }, 0);
|
|
242
|
+
});
|
|
243
|
+
_this._schemaListener[model.uri.toString()] = onSchemaChange(function () {
|
|
244
|
+
self.setTimeout(function () { return _this._doColorization(model, modeId, []); }, 0);
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
var onModelRemoved = function (model) {
|
|
248
|
+
model.deltaDecorations(_this.decorations, []);
|
|
249
|
+
var uriStr = model.uri.toString();
|
|
250
|
+
var contentListener = _this._contentListener[uriStr];
|
|
251
|
+
if (contentListener) {
|
|
252
|
+
contentListener.dispose();
|
|
253
|
+
delete _this._contentListener[uriStr];
|
|
254
|
+
}
|
|
255
|
+
var configurationListener = _this._configurationListener[uriStr];
|
|
256
|
+
if (configurationListener) {
|
|
257
|
+
configurationListener.dispose();
|
|
258
|
+
delete _this._configurationListener[uriStr];
|
|
259
|
+
}
|
|
260
|
+
var schemaListener = _this._configurationListener[uriStr];
|
|
261
|
+
if (schemaListener) {
|
|
262
|
+
schemaListener.dispose();
|
|
263
|
+
delete _this._schemaListener[uriStr];
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
|
|
267
|
+
this._disposables.push(monaco.editor.onWillDisposeModel(onModelRemoved));
|
|
268
|
+
this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
|
|
269
|
+
onModelRemoved(event.model);
|
|
270
|
+
onModelAdd(event.model);
|
|
271
|
+
}));
|
|
272
|
+
this._disposables.push({
|
|
273
|
+
dispose: function () {
|
|
274
|
+
for (var key in _this._contentListener) {
|
|
275
|
+
_this._contentListener[key].dispose();
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
monaco.editor.getModels().forEach(onModelAdd);
|
|
280
|
+
}
|
|
281
|
+
ColorizationAdapter.prototype.dispose = function () {
|
|
282
|
+
this._disposables.forEach(function (d) { return d && d.dispose(); });
|
|
283
|
+
this._disposables = [];
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Return true if the range doesn't intersect any of the line ranges.
|
|
287
|
+
* @param range Range
|
|
288
|
+
* @param impactedLineRanges an array of line ranges
|
|
289
|
+
*/
|
|
290
|
+
ColorizationAdapter.prototype._rangeDoesNotIntersectAny = function (range, impactedLineRanges) {
|
|
291
|
+
return impactedLineRanges.every(function (lineRange) {
|
|
292
|
+
return range.startLineNumber > lineRange.lastImpactedLine || range.endLineNumber < lineRange.firstImpactedLine;
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
ColorizationAdapter.prototype._doColorization = function (model, languageId, intervals) {
|
|
296
|
+
var _this = this;
|
|
297
|
+
if (model.isDisposed()) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
var resource = model.uri;
|
|
301
|
+
var versionNumberBeforeColorization = model.getVersionId();
|
|
302
|
+
this._worker(resource)
|
|
303
|
+
.then(function (worker) {
|
|
304
|
+
return worker.doColorization(resource.toString(), intervals);
|
|
305
|
+
})
|
|
306
|
+
.then(function (colorizationRanges) {
|
|
307
|
+
var newModel = monaco.editor.getModel(model.uri);
|
|
308
|
+
var versionId = newModel.getVersionId();
|
|
309
|
+
// don't colorize an older version of the document.
|
|
310
|
+
if (versionId !== versionNumberBeforeColorization) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
var decorationRanges = colorizationRanges.map(function (colorizationRange) {
|
|
314
|
+
var decorations = colorizationRange.classifications
|
|
315
|
+
.map(function (classification) { return toDecoration(model, classification); })
|
|
316
|
+
// The following line will prevent things that aren't going to be colorized anyway to get a CSS class.
|
|
317
|
+
// This will prevent the case where the non-semantic colorizer already figured out that a keyword needs
|
|
318
|
+
// to be colorized, but the outdated semantic colorizer still thinks it's a plain text and wants it colored
|
|
319
|
+
// in black.
|
|
320
|
+
.filter(function (d) {
|
|
321
|
+
return d.options.inlineClassName !== 'PlainText' && d.options.inlineClassName != 'Identifier';
|
|
322
|
+
});
|
|
323
|
+
var firstImpactedLine = model.getPositionAt(colorizationRange.absoluteStart).lineNumber;
|
|
324
|
+
var endPosition = model.getPositionAt(colorizationRange.absoluteEnd);
|
|
325
|
+
// A token that ends in the first column of the next line is not considered to be part of that line.
|
|
326
|
+
var lastImpactedLine = endPosition.column == 1 && endPosition.lineNumber > 1
|
|
327
|
+
? endPosition.lineNumber - 1
|
|
328
|
+
: endPosition.lineNumber;
|
|
329
|
+
return { decorations: decorations, firstImpactedLine: firstImpactedLine, lastImpactedLine: lastImpactedLine };
|
|
330
|
+
});
|
|
331
|
+
// Compute the previous decorations we want to replace with the new ones.
|
|
332
|
+
var oldDecorations = decorationRanges
|
|
333
|
+
.map(function (range) {
|
|
334
|
+
return model
|
|
335
|
+
.getLinesDecorations(range.firstImpactedLine, range.lastImpactedLine)
|
|
336
|
+
.filter(function (d) { return classificationToColorLight[d.options.inlineClassName]; }) // Don't delete any other decorations
|
|
337
|
+
.map(function (d) { return d.id; });
|
|
338
|
+
})
|
|
339
|
+
.reduce(function (prev, curr) { return prev.concat(curr); }, []);
|
|
340
|
+
// Flatten decoration groups to an array of decorations
|
|
341
|
+
var newDecorations = decorationRanges.reduce(function (prev, next) { return prev.concat(next.decorations); }, []);
|
|
342
|
+
if (model && model.getModeId() === languageId) {
|
|
343
|
+
_this.decorations = model.deltaDecorations(oldDecorations, newDecorations);
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
.then(undefined, function (err) {
|
|
347
|
+
console.error(err);
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
return ColorizationAdapter;
|
|
351
|
+
}());
|
|
352
|
+
export { ColorizationAdapter };
|
|
353
|
+
/**
|
|
354
|
+
* Gets all keys of an enum (the string keys not the numeric values).
|
|
355
|
+
* @param e Enum type
|
|
356
|
+
*/
|
|
357
|
+
function getEnumKeys(e) {
|
|
358
|
+
return Object.keys(e).filter(function (k) { return typeof e[k] === 'number'; });
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Generates a mapping between ClassificationKind and color.
|
|
362
|
+
*/
|
|
363
|
+
function getClassificationColorTriplets() {
|
|
364
|
+
var keys = getEnumKeys(ClassificationKind);
|
|
365
|
+
var result = keys.map(function (key) { return ({
|
|
366
|
+
classification: key,
|
|
367
|
+
colorLight: classificationToColorLight[key],
|
|
368
|
+
colorDark: classificationToColorDark[key],
|
|
369
|
+
}); });
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Returns a string which is a css describing all tokens and their colors.
|
|
374
|
+
* looks a little bit something like this:
|
|
375
|
+
*
|
|
376
|
+
* .vs .Literal {color: '#000000';} .vs-dark .Literal {color: '#FFFFFF';}
|
|
377
|
+
* .vs .Comment {color: '#111111';} .vs-dark .Comment {color: '#EEEEEE';}
|
|
378
|
+
*/
|
|
379
|
+
function getCssForClassification() {
|
|
380
|
+
var classificationColorTriplets = getClassificationColorTriplets();
|
|
381
|
+
var cssInnerHtml = classificationColorTriplets
|
|
382
|
+
.map(function (pair) {
|
|
383
|
+
return ".vs ." + pair.classification + " {color: #" + pair.colorLight + ";} .vs-dark ." + pair.classification + " {color: #" + pair.colorDark + ";}";
|
|
384
|
+
})
|
|
385
|
+
.join('\n');
|
|
386
|
+
return cssInnerHtml;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Inject a CSS sheet to the head of document, coloring kusto elements by classification.
|
|
390
|
+
* TODO: make idempotent
|
|
391
|
+
*/
|
|
392
|
+
function injectCss() {
|
|
393
|
+
var container = document.getElementsByTagName('head')[0];
|
|
394
|
+
var style = document.createElement('style');
|
|
395
|
+
style.type = 'text/css';
|
|
396
|
+
style.media = 'screen';
|
|
397
|
+
container.appendChild(style);
|
|
398
|
+
ClassificationKind;
|
|
399
|
+
style.innerHTML = getCssForClassification();
|
|
400
|
+
}
|
|
401
|
+
function toDecoration(model, classification) {
|
|
402
|
+
var start = model.getPositionAt(classification.start);
|
|
403
|
+
var end = model.getPositionAt(classification.start + classification.length);
|
|
404
|
+
var range = new Range(start.lineNumber, start.column, end.lineNumber, end.column);
|
|
405
|
+
var inlineClassName = ClassificationKind.$names[classification.kind];
|
|
406
|
+
return {
|
|
407
|
+
range: range,
|
|
408
|
+
options: {
|
|
409
|
+
inlineClassName: inlineClassName,
|
|
410
|
+
stickiness: monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
// --- completion ------
|
|
415
|
+
function fromPosition(position) {
|
|
416
|
+
if (!position) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
return { character: position.column - 1, line: position.lineNumber - 1 };
|
|
420
|
+
}
|
|
421
|
+
function fromRange(range) {
|
|
422
|
+
if (!range) {
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
return { start: fromPosition(range.getStartPosition()), end: fromPosition(range.getEndPosition()) };
|
|
426
|
+
}
|
|
427
|
+
function toRange(range) {
|
|
428
|
+
if (!range) {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
|
|
432
|
+
}
|
|
433
|
+
function toCompletionItemKind(kind) {
|
|
434
|
+
var mItemKind = monaco.languages.CompletionItemKind;
|
|
435
|
+
switch (kind) {
|
|
436
|
+
case ls.CompletionItemKind.Text:
|
|
437
|
+
return mItemKind.Text;
|
|
438
|
+
case ls.CompletionItemKind.Method:
|
|
439
|
+
return mItemKind.Method;
|
|
440
|
+
case ls.CompletionItemKind.Function:
|
|
441
|
+
return mItemKind.Function;
|
|
442
|
+
case ls.CompletionItemKind.Constructor:
|
|
443
|
+
return mItemKind.Constructor;
|
|
444
|
+
case ls.CompletionItemKind.Field:
|
|
445
|
+
return mItemKind.Field;
|
|
446
|
+
case ls.CompletionItemKind.Variable:
|
|
447
|
+
return mItemKind.Variable;
|
|
448
|
+
case ls.CompletionItemKind.Class:
|
|
449
|
+
return mItemKind.Class;
|
|
450
|
+
case ls.CompletionItemKind.Interface:
|
|
451
|
+
return mItemKind.Interface;
|
|
452
|
+
case ls.CompletionItemKind.Module:
|
|
453
|
+
return mItemKind.Module;
|
|
454
|
+
case ls.CompletionItemKind.Property:
|
|
455
|
+
return mItemKind.Property;
|
|
456
|
+
case ls.CompletionItemKind.Unit:
|
|
457
|
+
return mItemKind.Unit;
|
|
458
|
+
case ls.CompletionItemKind.Value:
|
|
459
|
+
return mItemKind.Value;
|
|
460
|
+
case ls.CompletionItemKind.Enum:
|
|
461
|
+
return mItemKind.Enum;
|
|
462
|
+
case ls.CompletionItemKind.Keyword:
|
|
463
|
+
return mItemKind.Keyword;
|
|
464
|
+
case ls.CompletionItemKind.Snippet:
|
|
465
|
+
return mItemKind.Snippet;
|
|
466
|
+
case ls.CompletionItemKind.Color:
|
|
467
|
+
return mItemKind.Color;
|
|
468
|
+
case ls.CompletionItemKind.File:
|
|
469
|
+
return mItemKind.File;
|
|
470
|
+
case ls.CompletionItemKind.Reference:
|
|
471
|
+
return mItemKind.Reference;
|
|
472
|
+
}
|
|
473
|
+
return mItemKind.Property;
|
|
474
|
+
}
|
|
475
|
+
function toTextEdit(textEdit) {
|
|
476
|
+
if (!textEdit) {
|
|
477
|
+
return void 0;
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
range: toRange(textEdit.range),
|
|
481
|
+
text: textEdit.newText,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
var CompletionAdapter = /** @class */ (function () {
|
|
485
|
+
function CompletionAdapter(_worker, languageSettings) {
|
|
486
|
+
this._worker = _worker;
|
|
487
|
+
this.languageSettings = languageSettings;
|
|
488
|
+
}
|
|
489
|
+
Object.defineProperty(CompletionAdapter.prototype, "triggerCharacters", {
|
|
490
|
+
get: function () {
|
|
491
|
+
return [' '];
|
|
492
|
+
},
|
|
493
|
+
enumerable: false,
|
|
494
|
+
configurable: true
|
|
495
|
+
});
|
|
496
|
+
CompletionAdapter.prototype.provideCompletionItems = function (model, position, context, token) {
|
|
497
|
+
var wordInfo = model.getWordUntilPosition(position);
|
|
498
|
+
var wordRange = new Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
|
|
499
|
+
var resource = model.uri;
|
|
500
|
+
var onDidProvideCompletionItems = this.languageSettings
|
|
501
|
+
.onDidProvideCompletionItems;
|
|
502
|
+
return this._worker(resource)
|
|
503
|
+
.then(function (worker) {
|
|
504
|
+
return worker.doComplete(resource.toString(), fromPosition(position));
|
|
505
|
+
})
|
|
506
|
+
.then(function (info) { return (onDidProvideCompletionItems ? onDidProvideCompletionItems(info) : info); })
|
|
507
|
+
.then(function (info) {
|
|
508
|
+
if (!info) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
var items = info.items.map(function (entry) {
|
|
512
|
+
var item = {
|
|
513
|
+
label: entry.label,
|
|
514
|
+
insertText: entry.insertText,
|
|
515
|
+
sortText: entry.sortText,
|
|
516
|
+
filterText: entry.filterText,
|
|
517
|
+
documentation: entry.documentation,
|
|
518
|
+
detail: entry.detail,
|
|
519
|
+
range: wordRange,
|
|
520
|
+
kind: toCompletionItemKind(entry.kind),
|
|
521
|
+
};
|
|
522
|
+
if (entry.textEdit) {
|
|
523
|
+
item.range = toRange(entry.textEdit.range);
|
|
524
|
+
item.insertText = entry.textEdit.newText;
|
|
525
|
+
}
|
|
526
|
+
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
527
|
+
item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
528
|
+
}
|
|
529
|
+
return item;
|
|
530
|
+
});
|
|
531
|
+
return {
|
|
532
|
+
isIncomplete: info.isIncomplete,
|
|
533
|
+
suggestions: items,
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
return CompletionAdapter;
|
|
538
|
+
}());
|
|
539
|
+
export { CompletionAdapter };
|
|
540
|
+
function isMarkupContent(thing) {
|
|
541
|
+
return thing && typeof thing === 'object' && typeof thing.kind === 'string';
|
|
542
|
+
}
|
|
543
|
+
function toMarkdownString(entry) {
|
|
544
|
+
if (typeof entry === 'string') {
|
|
545
|
+
return {
|
|
546
|
+
value: entry,
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
if (isMarkupContent(entry)) {
|
|
550
|
+
if (entry.kind === 'plaintext') {
|
|
551
|
+
return {
|
|
552
|
+
value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'),
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
value: entry.value,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
return { value: '```' + entry.value + '\n' + entry.value + '\n```\n' };
|
|
560
|
+
}
|
|
561
|
+
function toMarkedStringArray(contents) {
|
|
562
|
+
if (!contents) {
|
|
563
|
+
return void 0;
|
|
564
|
+
}
|
|
565
|
+
if (Array.isArray(contents)) {
|
|
566
|
+
return contents.map(toMarkdownString);
|
|
567
|
+
}
|
|
568
|
+
return [toMarkdownString(contents)];
|
|
569
|
+
}
|
|
570
|
+
// --- definition ------
|
|
571
|
+
function toLocation(location) {
|
|
572
|
+
return {
|
|
573
|
+
uri: Uri.parse(location.uri),
|
|
574
|
+
range: toRange(location.range),
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
var DefinitionAdapter = /** @class */ (function () {
|
|
578
|
+
function DefinitionAdapter(_worker) {
|
|
579
|
+
this._worker = _worker;
|
|
580
|
+
}
|
|
581
|
+
DefinitionAdapter.prototype.provideDefinition = function (model, position, token) {
|
|
582
|
+
var resource = model.uri;
|
|
583
|
+
return this._worker(resource)
|
|
584
|
+
.then(function (worker) {
|
|
585
|
+
return worker.findDefinition(resource.toString(), fromPosition(position));
|
|
586
|
+
})
|
|
587
|
+
.then(function (definition) {
|
|
588
|
+
if (!definition || definition.length == 0) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
return [toLocation(definition[0])];
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
return DefinitionAdapter;
|
|
595
|
+
}());
|
|
596
|
+
export { DefinitionAdapter };
|
|
597
|
+
// --- references ------
|
|
598
|
+
var ReferenceAdapter = /** @class */ (function () {
|
|
599
|
+
function ReferenceAdapter(_worker) {
|
|
600
|
+
this._worker = _worker;
|
|
601
|
+
}
|
|
602
|
+
ReferenceAdapter.prototype.provideReferences = function (model, position, context, token) {
|
|
603
|
+
var resource = model.uri;
|
|
604
|
+
return this._worker(resource)
|
|
605
|
+
.then(function (worker) {
|
|
606
|
+
return worker.findReferences(resource.toString(), fromPosition(position));
|
|
607
|
+
})
|
|
608
|
+
.then(function (entries) {
|
|
609
|
+
if (!entries) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
return entries.map(toLocation);
|
|
613
|
+
});
|
|
614
|
+
};
|
|
615
|
+
return ReferenceAdapter;
|
|
616
|
+
}());
|
|
617
|
+
export { ReferenceAdapter };
|
|
618
|
+
// --- rename ------
|
|
619
|
+
function toWorkspaceEdit(edit) {
|
|
620
|
+
if (!edit || !edit.changes) {
|
|
621
|
+
return void 0;
|
|
622
|
+
}
|
|
623
|
+
var resourceEdits = [];
|
|
624
|
+
for (var uri in edit.changes) {
|
|
625
|
+
var _uri = Uri.parse(uri);
|
|
626
|
+
for (var _i = 0, _a = edit.changes[uri]; _i < _a.length; _i++) {
|
|
627
|
+
var e = _a[_i];
|
|
628
|
+
resourceEdits.push({
|
|
629
|
+
resource: _uri,
|
|
630
|
+
edit: {
|
|
631
|
+
range: toRange(e.range),
|
|
632
|
+
text: e.newText,
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
edits: resourceEdits,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
var RenameAdapter = /** @class */ (function () {
|
|
642
|
+
function RenameAdapter(_worker) {
|
|
643
|
+
this._worker = _worker;
|
|
644
|
+
}
|
|
645
|
+
RenameAdapter.prototype.provideRenameEdits = function (model, position, newName, token) {
|
|
646
|
+
var resource = model.uri;
|
|
647
|
+
return this._worker(resource)
|
|
648
|
+
.then(function (worker) {
|
|
649
|
+
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
650
|
+
})
|
|
651
|
+
.then(function (edit) {
|
|
652
|
+
return toWorkspaceEdit(edit);
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
return RenameAdapter;
|
|
656
|
+
}());
|
|
657
|
+
export { RenameAdapter };
|
|
658
|
+
// --- document symbols ------
|
|
659
|
+
function toSymbolKind(kind) {
|
|
660
|
+
var mKind = monaco.languages.SymbolKind;
|
|
661
|
+
switch (kind) {
|
|
662
|
+
case ls.SymbolKind.File:
|
|
663
|
+
return mKind.Array;
|
|
664
|
+
case ls.SymbolKind.Module:
|
|
665
|
+
return mKind.Module;
|
|
666
|
+
case ls.SymbolKind.Namespace:
|
|
667
|
+
return mKind.Namespace;
|
|
668
|
+
case ls.SymbolKind.Package:
|
|
669
|
+
return mKind.Package;
|
|
670
|
+
case ls.SymbolKind.Class:
|
|
671
|
+
return mKind.Class;
|
|
672
|
+
case ls.SymbolKind.Method:
|
|
673
|
+
return mKind.Method;
|
|
674
|
+
case ls.SymbolKind.Property:
|
|
675
|
+
return mKind.Property;
|
|
676
|
+
case ls.SymbolKind.Field:
|
|
677
|
+
return mKind.Field;
|
|
678
|
+
case ls.SymbolKind.Constructor:
|
|
679
|
+
return mKind.Constructor;
|
|
680
|
+
case ls.SymbolKind.Enum:
|
|
681
|
+
return mKind.Enum;
|
|
682
|
+
case ls.SymbolKind.Interface:
|
|
683
|
+
return mKind.Interface;
|
|
684
|
+
case ls.SymbolKind.Function:
|
|
685
|
+
return mKind.Function;
|
|
686
|
+
case ls.SymbolKind.Variable:
|
|
687
|
+
return mKind.Variable;
|
|
688
|
+
case ls.SymbolKind.Constant:
|
|
689
|
+
return mKind.Constant;
|
|
690
|
+
case ls.SymbolKind.String:
|
|
691
|
+
return mKind.String;
|
|
692
|
+
case ls.SymbolKind.Number:
|
|
693
|
+
return mKind.Number;
|
|
694
|
+
case ls.SymbolKind.Boolean:
|
|
695
|
+
return mKind.Boolean;
|
|
696
|
+
case ls.SymbolKind.Array:
|
|
697
|
+
return mKind.Array;
|
|
698
|
+
}
|
|
699
|
+
return mKind.Function;
|
|
700
|
+
}
|
|
701
|
+
// --- formatting -----
|
|
702
|
+
var DocumentFormatAdapter = /** @class */ (function () {
|
|
703
|
+
function DocumentFormatAdapter(_worker) {
|
|
704
|
+
this._worker = _worker;
|
|
705
|
+
}
|
|
706
|
+
DocumentFormatAdapter.prototype.provideDocumentFormattingEdits = function (model, options, token) {
|
|
707
|
+
var resource = model.uri;
|
|
708
|
+
return this._worker(resource).then(function (worker) {
|
|
709
|
+
return worker.doDocumentFormat(resource.toString()).then(function (edits) { return edits.map(function (edit) { return toTextEdit(edit); }); });
|
|
710
|
+
});
|
|
711
|
+
};
|
|
712
|
+
return DocumentFormatAdapter;
|
|
713
|
+
}());
|
|
714
|
+
export { DocumentFormatAdapter };
|
|
715
|
+
var FormatAdapter = /** @class */ (function () {
|
|
716
|
+
function FormatAdapter(_worker) {
|
|
717
|
+
this._worker = _worker;
|
|
718
|
+
}
|
|
719
|
+
FormatAdapter.prototype.provideDocumentRangeFormattingEdits = function (model, range, options, token) {
|
|
720
|
+
var resource = model.uri;
|
|
721
|
+
return this._worker(resource).then(function (worker) {
|
|
722
|
+
return worker
|
|
723
|
+
.doRangeFormat(resource.toString(), fromRange(range))
|
|
724
|
+
.then(function (edits) { return edits.map(function (edit) { return toTextEdit(edit); }); });
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
return FormatAdapter;
|
|
728
|
+
}());
|
|
729
|
+
export { FormatAdapter };
|
|
730
|
+
// --- Folding ---
|
|
731
|
+
var FoldingAdapter = /** @class */ (function () {
|
|
732
|
+
function FoldingAdapter(_worker) {
|
|
733
|
+
this._worker = _worker;
|
|
734
|
+
}
|
|
735
|
+
FoldingAdapter.prototype.provideFoldingRanges = function (model, context, token) {
|
|
736
|
+
var resource = model.uri;
|
|
737
|
+
return this._worker(resource).then(function (worker) {
|
|
738
|
+
return worker
|
|
739
|
+
.doFolding(resource.toString())
|
|
740
|
+
.then(function (foldingRanges) {
|
|
741
|
+
return foldingRanges.map(function (range) { return toFoldingRange(range); });
|
|
742
|
+
});
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
return FoldingAdapter;
|
|
746
|
+
}());
|
|
747
|
+
export { FoldingAdapter };
|
|
748
|
+
function toFoldingRange(range) {
|
|
749
|
+
return {
|
|
750
|
+
start: range.startLine + 1,
|
|
751
|
+
end: range.endLine + 1,
|
|
752
|
+
kind: monaco.languages.FoldingRangeKind.Region,
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
// --- hover ------
|
|
756
|
+
var HoverAdapter = /** @class */ (function () {
|
|
757
|
+
function HoverAdapter(_worker) {
|
|
758
|
+
this._worker = _worker;
|
|
759
|
+
}
|
|
760
|
+
HoverAdapter.prototype.provideHover = function (model, position, token) {
|
|
761
|
+
var resource = model.uri;
|
|
762
|
+
return this._worker(resource)
|
|
763
|
+
.then(function (worker) {
|
|
764
|
+
return worker.doHover(resource.toString(), fromPosition(position));
|
|
765
|
+
})
|
|
766
|
+
.then(function (info) {
|
|
767
|
+
if (!info) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
range: toRange(info.range),
|
|
772
|
+
contents: toMarkedStringArray(info.contents),
|
|
773
|
+
};
|
|
774
|
+
});
|
|
775
|
+
};
|
|
776
|
+
return HoverAdapter;
|
|
777
|
+
}());
|
|
778
|
+
export { HoverAdapter };
|