@kusto/monaco-kusto 12.0.4 → 12.0.5
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/README.md +4 -0
- package/package.json +1 -1
- package/release/dev/kustoMode.js +2 -2
- package/release/dev/kustoWorker.js +2 -2
- package/release/dev/{main-8ccfbe97.js → main-a4323fb4.js} +2 -2
- package/release/dev/monaco.contribution.js +5 -5
- package/release/dev/{schema-1cdad6c3.js → schema-fa340338.js} +2 -2
- package/release/dev/{types-fa2666d1.js → types-523ebcf2.js} +2 -2
- package/release/esm/{globals-9d8df38a.js → globals-92607830.js} +1 -1
- package/release/esm/kusto.worker.js +2 -2
- package/release/esm/kustoMode.js +134 -927
- package/release/esm/{schema-0da4a784.js → schema-814f4b29.js} +1 -1
- package/release/esm/syntaxHighlighting/themes.js +3 -3
- package/release/min/kustoMode.js +2 -2
- package/release/min/kustoWorker.js +2 -2
- package/release/min/{main-18af1c62.js → main-7682d6ff.js} +2 -2
- package/release/min/monaco.contribution.js +2 -2
- package/release/min/{schema-aa496175.js → schema-4f275c99.js} +2 -2
- package/release/min/{types-4d703737.js → types-da1c5003.js} +2 -2
package/release/esm/kustoMode.js
CHANGED
|
@@ -1,941 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
9
|
-
import * as ls from 'vscode-languageserver-types';
|
|
10
|
-
import debounce from 'lodash-es/debounce';
|
|
11
|
-
import { L as LANGUAGE_ID, T as Token, t as tokenTypes } from './globals-9d8df38a.js';
|
|
12
|
-
|
|
13
|
-
class WorkerManager {
|
|
14
|
-
constructor(_monacoInstance, defaults) {
|
|
15
|
-
this._monacoInstance = _monacoInstance;
|
|
16
|
-
this._defaults = defaults;
|
|
17
|
-
this._worker = null;
|
|
18
|
-
this._idleCheckInterval = self.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
|
19
|
-
this._lastUsedTime = 0;
|
|
20
|
-
this._configChangeListener = this._defaults.onDidChange(() => this._saveStateAndStopWorker());
|
|
21
|
-
}
|
|
22
|
-
_stopWorker() {
|
|
23
|
-
if (this._worker) {
|
|
24
|
-
this._worker.dispose();
|
|
25
|
-
this._worker = null;
|
|
26
|
-
}
|
|
27
|
-
this._client = null;
|
|
28
|
-
}
|
|
29
|
-
_saveStateAndStopWorker() {
|
|
30
|
-
if (!this._worker) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this._worker.getProxy().then(proxy => {
|
|
34
|
-
proxy.getSchema().then(schema => {
|
|
35
|
-
this._storedState = {
|
|
36
|
-
schema: schema
|
|
37
|
-
};
|
|
38
|
-
this._stopWorker();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
dispose() {
|
|
43
|
-
clearInterval(this._idleCheckInterval);
|
|
44
|
-
this._configChangeListener.dispose();
|
|
45
|
-
this._stopWorker();
|
|
46
|
-
}
|
|
47
|
-
_checkIfIdle() {
|
|
48
|
-
if (!this._worker) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const maxIdleTime = this._defaults.getWorkerMaxIdleTime();
|
|
52
|
-
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
|
53
|
-
if (maxIdleTime > 0 && timePassedSinceLastUsed > maxIdleTime) {
|
|
54
|
-
this._saveStateAndStopWorker();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
_getClient() {
|
|
58
|
-
this._lastUsedTime = Date.now();
|
|
59
|
-
|
|
60
|
-
// Since onDidProvideCompletionItems is not used in web worker, and since functions cannot be trivially serialized (throws exception unable to clone), We remove it here.
|
|
61
|
-
const {
|
|
62
|
-
onDidProvideCompletionItems,
|
|
63
|
-
...languageSettings
|
|
64
|
-
} = this._defaults.languageSettings;
|
|
65
|
-
if (!this._client) {
|
|
66
|
-
this._worker = this._monacoInstance.editor.createWebWorker({
|
|
67
|
-
// module that exports the create() method and returns a `KustoWorker` instance
|
|
68
|
-
moduleId: 'vs/language/kusto/kustoWorker',
|
|
69
|
-
label: 'kusto',
|
|
70
|
-
// passed in to the create() method
|
|
71
|
-
createData: {
|
|
72
|
-
languageSettings: languageSettings,
|
|
73
|
-
languageId: 'kusto'
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
this._client = this._worker.getProxy().then(proxy => {
|
|
77
|
-
// push state we held onto before killing the client.
|
|
78
|
-
if (this._storedState) {
|
|
79
|
-
return proxy.setSchema(this._storedState.schema).then(() => proxy);
|
|
80
|
-
} else {
|
|
81
|
-
return proxy;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return this._client;
|
|
86
|
-
}
|
|
87
|
-
getLanguageServiceWorker(...resources) {
|
|
88
|
-
let _client;
|
|
89
|
-
return this._getClient().then(client => {
|
|
90
|
-
_client = client;
|
|
91
|
-
}).then(_ => {
|
|
92
|
-
return this._worker.withSyncedResources(resources);
|
|
93
|
-
}).then(_ => _client);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const createCompletionCacheManager = getFromLanguageService => {
|
|
98
|
-
let completionList;
|
|
99
|
-
let lastWord;
|
|
100
|
-
return {
|
|
101
|
-
getCompletionItems: (word, resource, position) => {
|
|
102
|
-
const shouldGetItems = !lastWord || !word || !word?.includes(lastWord);
|
|
103
|
-
if (shouldGetItems) {
|
|
104
|
-
completionList = getFromLanguageService(resource, position);
|
|
105
|
-
}
|
|
106
|
-
lastWord = word;
|
|
107
|
-
return completionList;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
function createCompletionFilteredText(userInput, completionItem) {
|
|
113
|
-
if (!userInput) return completionItem.filterText;
|
|
114
|
-
const containedInFilterText = completionItem.filterText.toLowerCase().includes(userInput.toLowerCase());
|
|
115
|
-
if (!containedInFilterText) return completionItem.filterText;
|
|
116
|
-
return `${userInput}${completionItem.filterText}`;
|
|
117
|
-
}
|
|
118
|
-
function getFocusedItem(completionItems, userInput) {
|
|
119
|
-
const firstCompletionItem = completionItems[0];
|
|
120
|
-
if (!userInput) return firstCompletionItem;
|
|
121
|
-
const firstMatchingItem = completionItems.find(item => item.filterText?.toLowerCase().startsWith(userInput.toLowerCase()));
|
|
122
|
-
return firstMatchingItem ?? firstCompletionItem;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// --- diagnostics ---
|
|
126
|
-
|
|
127
|
-
class DiagnosticsAdapter {
|
|
128
|
-
_disposables = [];
|
|
129
|
-
_contentListener = Object.create(null);
|
|
130
|
-
_configurationListener = Object.create(null);
|
|
131
|
-
_schemaListener = Object.create(null);
|
|
132
|
-
_cursorListener = Object.create(null);
|
|
133
|
-
_debouncedValidations = Object.create(null);
|
|
134
|
-
constructor(_monacoInstance, _languageId, _worker, defaults, onSchemaChange) {
|
|
135
|
-
this._monacoInstance = _monacoInstance;
|
|
136
|
-
this._languageId = _languageId;
|
|
137
|
-
this._worker = _worker;
|
|
138
|
-
this.defaults = defaults;
|
|
139
|
-
const onModelAdd = model => {
|
|
140
|
-
let languageId = model.getLanguageId();
|
|
141
|
-
const modelUri = model.uri.toString();
|
|
142
|
-
if (languageId !== this._languageId) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const debouncedValidation = this.getOrCreateDebouncedValidation(model, languageId);
|
|
146
|
-
this._contentListener[modelUri] = model.onDidChangeContent(e => {
|
|
147
|
-
const intervalsToValidate = changeEventToIntervals(e);
|
|
148
|
-
debouncedValidation(intervalsToValidate);
|
|
149
|
-
});
|
|
150
|
-
this._configurationListener[modelUri] = this.defaults.onDidChange(() => {
|
|
151
|
-
self.setTimeout(() => this._doValidate(model, languageId, []), 0);
|
|
152
|
-
});
|
|
153
|
-
this._schemaListener[modelUri] = onSchemaChange(() => {
|
|
154
|
-
self.setTimeout(() => this._doValidate(model, languageId, []), 0);
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
const onEditorAdd = editor => {
|
|
158
|
-
const editorId = editor.getId();
|
|
159
|
-
if (!this._cursorListener[editorId]) {
|
|
160
|
-
editor.onDidDispose(() => {
|
|
161
|
-
this._cursorListener[editorId]?.dispose();
|
|
162
|
-
delete this._cursorListener[editorId];
|
|
163
|
-
});
|
|
164
|
-
this._cursorListener[editorId] = editor.onDidChangeCursorSelection(e => {
|
|
165
|
-
const model = editor.getModel();
|
|
166
|
-
const languageId = model.getLanguageId();
|
|
167
|
-
if (languageId !== this._languageId) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const cursorOffset = model.getOffsetAt(e.selection.getPosition());
|
|
171
|
-
const debouncedValidation = this.getOrCreateDebouncedValidation(model, languageId);
|
|
172
|
-
debouncedValidation([{
|
|
173
|
-
start: cursorOffset,
|
|
174
|
-
end: cursorOffset
|
|
175
|
-
}]);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
const onModelRemoved = model => {
|
|
180
|
-
this._monacoInstance.editor.setModelMarkers(model, this._languageId, []);
|
|
181
|
-
let uriStr = model.uri.toString();
|
|
182
|
-
let contentListener = this._contentListener[uriStr];
|
|
183
|
-
if (contentListener) {
|
|
184
|
-
contentListener.dispose();
|
|
185
|
-
delete this._contentListener[uriStr];
|
|
186
|
-
}
|
|
187
|
-
let configurationListener = this._configurationListener[uriStr];
|
|
188
|
-
if (configurationListener) {
|
|
189
|
-
configurationListener.dispose();
|
|
190
|
-
delete this._configurationListener[uriStr];
|
|
191
|
-
}
|
|
192
|
-
let schemaListener = this._schemaListener[uriStr];
|
|
193
|
-
if (schemaListener) {
|
|
194
|
-
schemaListener.dispose();
|
|
195
|
-
delete this._schemaListener[uriStr];
|
|
196
|
-
}
|
|
197
|
-
let debouncedValidation = this._debouncedValidations[uriStr];
|
|
198
|
-
if (debouncedValidation) {
|
|
199
|
-
debouncedValidation.cancel();
|
|
200
|
-
delete this._debouncedValidations[uriStr];
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
if (this.defaults.languageSettings.enableQuickFixes) {
|
|
204
|
-
this._disposables.push(monaco.languages.registerCodeActionProvider(this._languageId, {
|
|
205
|
-
provideCodeActions: async (model, range, context, _token) => {
|
|
206
|
-
const startOffset = model.getOffsetAt(range.getStartPosition());
|
|
207
|
-
const endOffset = model.getOffsetAt(range.getEndPosition());
|
|
208
|
-
// We want to show the quick fix option only if we have markers in our selected range
|
|
209
|
-
const showQuickFix = context.markers.length > 0;
|
|
210
|
-
const actions = await this.getMonacoCodeActions(model, startOffset, endOffset, showQuickFix);
|
|
211
|
-
return {
|
|
212
|
-
actions,
|
|
213
|
-
dispose: () => {}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
this._disposables.push(this._monacoInstance.editor.onDidCreateEditor(onEditorAdd));
|
|
219
|
-
this._disposables.push(this._monacoInstance.editor.onDidCreateModel(onModelAdd));
|
|
220
|
-
this._disposables.push(this._monacoInstance.editor.onWillDisposeModel(onModelRemoved));
|
|
221
|
-
this._disposables.push(this._monacoInstance.editor.onDidChangeModelLanguage(event => {
|
|
222
|
-
onModelRemoved(event.model);
|
|
223
|
-
onModelAdd(event.model);
|
|
224
|
-
}));
|
|
225
|
-
this._disposables.push({
|
|
226
|
-
dispose: () => {
|
|
227
|
-
for (let key in this._contentListener) {
|
|
228
|
-
this._contentListener[key].dispose();
|
|
229
|
-
}
|
|
230
|
-
for (let key in this._cursorListener) {
|
|
231
|
-
this._cursorListener[key].dispose();
|
|
232
|
-
}
|
|
233
|
-
for (let key in this._debouncedValidations) {
|
|
234
|
-
this._debouncedValidations[key].cancel();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
this._monacoInstance.editor.getModels().forEach(onModelAdd);
|
|
239
|
-
this._monacoInstance.editor.getEditors().forEach(onEditorAdd);
|
|
240
|
-
}
|
|
241
|
-
async getMonacoCodeActions(model, startOffset, endOffset, enableQuickFix) {
|
|
242
|
-
const actions = [];
|
|
243
|
-
const worker = await this._worker(model.uri);
|
|
244
|
-
const resource = model.uri;
|
|
245
|
-
const codeActions = await worker.getResultActions(resource.toString(), startOffset, endOffset);
|
|
246
|
-
for (let i = 0; i < codeActions.length; i++) {
|
|
247
|
-
const codeAction = codeActions[i];
|
|
248
|
-
if (codeAction.kind.includes('Extract Function')) {
|
|
249
|
-
// Ignore extract function actions for now since they are buggy currently
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
const codeActionKind = this.defaults.languageSettings.quickFixCodeActions?.find(actionKind => codeAction.kind.includes(actionKind)) ? 'quickfix' : 'custom';
|
|
253
|
-
if (codeActionKind === 'quickfix' && !enableQuickFix) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const changes = codeAction.changes;
|
|
257
|
-
const edits = changes.map(change => {
|
|
258
|
-
const startPosition = model.getPositionAt(change.start);
|
|
259
|
-
const endPosition = model.getPositionAt(change.start + change.deleteLength);
|
|
260
|
-
return {
|
|
261
|
-
resource: model.uri,
|
|
262
|
-
textEdit: {
|
|
263
|
-
range: {
|
|
264
|
-
startLineNumber: startPosition.lineNumber,
|
|
265
|
-
startColumn: startPosition.column,
|
|
266
|
-
endLineNumber: endPosition.lineNumber,
|
|
267
|
-
endColumn: endPosition.column
|
|
268
|
-
},
|
|
269
|
-
text: change.insertText ?? ''
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
});
|
|
273
|
-
actions.push({
|
|
274
|
-
title: codeAction.title,
|
|
275
|
-
diagnostics: [],
|
|
276
|
-
kind: codeActionKind,
|
|
277
|
-
edit: {
|
|
278
|
-
edits: [...edits]
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
return actions;
|
|
283
|
-
}
|
|
284
|
-
getOrCreateDebouncedValidation(model, languageId) {
|
|
285
|
-
const modelUri = model.uri.toString();
|
|
286
|
-
if (!this._debouncedValidations[modelUri]) {
|
|
287
|
-
this._debouncedValidations[modelUri] = debounce(intervals => this._doValidate(model, languageId, intervals), 500);
|
|
288
|
-
}
|
|
289
|
-
return this._debouncedValidations[modelUri];
|
|
290
|
-
}
|
|
291
|
-
dispose() {
|
|
292
|
-
this._disposables.forEach(d => d && d.dispose());
|
|
293
|
-
this._disposables = [];
|
|
294
|
-
}
|
|
295
|
-
_doValidate(model, languageId, intervals) {
|
|
296
|
-
if (model.isDisposed()) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const resource = model.uri;
|
|
300
|
-
const versionNumberBefore = model.getVersionId();
|
|
301
|
-
this._worker(resource).then(worker => {
|
|
302
|
-
return worker.doValidation(resource.toString(), intervals);
|
|
303
|
-
}).then(diagnostics => {
|
|
304
|
-
const newModel = this._monacoInstance.editor.getModel(resource);
|
|
305
|
-
const versionId = newModel.getVersionId();
|
|
306
|
-
if (versionId !== versionNumberBefore) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
const markers = diagnostics.map(d => toDiagnostics(resource, d));
|
|
310
|
-
let model = this._monacoInstance.editor.getModel(resource);
|
|
311
|
-
let oldDecorations = model.getAllDecorations().filter(decoration => decoration.options.className == 'squiggly-error').map(decoration => decoration.id);
|
|
312
|
-
if (model && model.getLanguageId() === languageId) {
|
|
313
|
-
const syntaxErrorAsMarkDown = this.defaults.languageSettings.syntaxErrorAsMarkDown;
|
|
314
|
-
if (!syntaxErrorAsMarkDown || !syntaxErrorAsMarkDown.enableSyntaxErrorAsMarkDown) {
|
|
315
|
-
// Remove previous syntax error decorations and set the new markers (for example, when disabling syntaxErrorAsMarkDown after it was enabled)
|
|
316
|
-
model.deltaDecorations(oldDecorations, []);
|
|
317
|
-
this._monacoInstance.editor.setModelMarkers(model, languageId, markers);
|
|
318
|
-
} else {
|
|
319
|
-
// Add custom popup for syntax error: icon, header and message as markdown
|
|
320
|
-
const header = syntaxErrorAsMarkDown.header ? `**${syntaxErrorAsMarkDown.header}** \n\n` : '';
|
|
321
|
-
const icon = syntaxErrorAsMarkDown.icon ? `` : '';
|
|
322
|
-
const popupErrorHoverHeaderMessage = `${icon} ${header}`;
|
|
323
|
-
const newDecorations = markers.map(marker => {
|
|
324
|
-
return {
|
|
325
|
-
range: {
|
|
326
|
-
startLineNumber: marker.startLineNumber,
|
|
327
|
-
startColumn: marker.startColumn,
|
|
328
|
-
endLineNumber: marker.endLineNumber,
|
|
329
|
-
endColumn: marker.endColumn
|
|
330
|
-
},
|
|
331
|
-
options: {
|
|
332
|
-
hoverMessage: {
|
|
333
|
-
value: popupErrorHoverHeaderMessage + marker.message
|
|
334
|
-
},
|
|
335
|
-
className: 'squiggly-error',
|
|
336
|
-
// monaco syntax error style (red underline)
|
|
337
|
-
zIndex: 100,
|
|
338
|
-
// This message will be the upper most mesage in the popup
|
|
339
|
-
overviewRuler: {
|
|
340
|
-
// The color indication on the right ruler
|
|
341
|
-
color: 'rgb(255, 18, 18, 0.7)',
|
|
342
|
-
position: monaco.editor.OverviewRulerLane.Right
|
|
343
|
-
},
|
|
344
|
-
minimap: {
|
|
345
|
-
color: 'rgb(255, 18, 18, 0.7)',
|
|
346
|
-
position: monaco.editor.MinimapPosition.Inline
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
});
|
|
351
|
-
const oldMarkers = monaco.editor.getModelMarkers({
|
|
352
|
-
owner: languageId,
|
|
353
|
-
resource: resource
|
|
354
|
-
});
|
|
355
|
-
if (oldMarkers && oldMarkers.length > 0) {
|
|
356
|
-
// In case there were previous markers, remove their decorations (for example, when enabling syntaxErrorAsMarkDown after it was disabled)
|
|
357
|
-
oldDecorations = [];
|
|
358
|
-
// Remove previous markers
|
|
359
|
-
this._monacoInstance.editor.setModelMarkers(model, languageId, []);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Remove previous syntax error decorations and set the new decorations
|
|
363
|
-
model.deltaDecorations(oldDecorations, newDecorations);
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
364
7
|
}
|
|
365
|
-
|
|
366
|
-
}).then(undefined, err => {
|
|
367
|
-
console.error(err);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function changeEventToIntervals(e) {
|
|
372
|
-
return e.changes.map(change => ({
|
|
373
|
-
start: change.rangeOffset,
|
|
374
|
-
end: change.rangeOffset + change.text.length
|
|
375
|
-
}));
|
|
376
|
-
}
|
|
377
|
-
function toSeverity(lsSeverity) {
|
|
378
|
-
switch (lsSeverity) {
|
|
379
|
-
case ls.DiagnosticSeverity.Error:
|
|
380
|
-
return monaco.MarkerSeverity.Error;
|
|
381
|
-
case ls.DiagnosticSeverity.Warning:
|
|
382
|
-
return monaco.MarkerSeverity.Warning;
|
|
383
|
-
case ls.DiagnosticSeverity.Information:
|
|
384
|
-
return monaco.MarkerSeverity.Info;
|
|
385
|
-
case ls.DiagnosticSeverity.Hint:
|
|
386
|
-
return monaco.MarkerSeverity.Hint;
|
|
387
|
-
default:
|
|
388
|
-
return monaco.MarkerSeverity.Info;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function toDiagnostics(resource, diag) {
|
|
392
|
-
let code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
|
|
393
|
-
return {
|
|
394
|
-
severity: toSeverity(diag.severity),
|
|
395
|
-
startLineNumber: diag.range.start.line + 1,
|
|
396
|
-
startColumn: diag.range.start.character + 1,
|
|
397
|
-
endLineNumber: diag.range.end.line + 1,
|
|
398
|
-
endColumn: diag.range.end.character + 1,
|
|
399
|
-
message: diag.message,
|
|
400
|
-
code: code,
|
|
401
|
-
source: diag.source
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// --- completion ------
|
|
406
|
-
|
|
407
|
-
function fromPosition(position) {
|
|
408
|
-
if (!position) {
|
|
409
|
-
return void 0;
|
|
410
|
-
}
|
|
411
|
-
return {
|
|
412
|
-
character: position.column - 1,
|
|
413
|
-
line: position.lineNumber - 1
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
function fromRange(range) {
|
|
417
|
-
if (!range) {
|
|
418
|
-
return void 0;
|
|
419
|
-
}
|
|
420
|
-
return {
|
|
421
|
-
start: fromPosition(range.getStartPosition()),
|
|
422
|
-
end: fromPosition(range.getEndPosition())
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
function toRange(range) {
|
|
426
|
-
if (!range) {
|
|
427
|
-
return void 0;
|
|
428
|
-
}
|
|
429
|
-
return new monaco.Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
|
|
430
|
-
}
|
|
431
|
-
function toCompletionItemKind(kind) {
|
|
432
|
-
let mItemKind = monaco.languages.CompletionItemKind;
|
|
433
|
-
switch (kind) {
|
|
434
|
-
case ls.CompletionItemKind.Text:
|
|
435
|
-
return mItemKind.Text;
|
|
436
|
-
case ls.CompletionItemKind.Method:
|
|
437
|
-
return mItemKind.Method;
|
|
438
|
-
case ls.CompletionItemKind.Function:
|
|
439
|
-
return mItemKind.Function;
|
|
440
|
-
case ls.CompletionItemKind.Constructor:
|
|
441
|
-
return mItemKind.Constructor;
|
|
442
|
-
case ls.CompletionItemKind.Field:
|
|
443
|
-
return mItemKind.Field;
|
|
444
|
-
case ls.CompletionItemKind.Variable:
|
|
445
|
-
return mItemKind.Variable;
|
|
446
|
-
case ls.CompletionItemKind.Class:
|
|
447
|
-
return mItemKind.Class;
|
|
448
|
-
case ls.CompletionItemKind.Interface:
|
|
449
|
-
return mItemKind.Interface;
|
|
450
|
-
case ls.CompletionItemKind.Module:
|
|
451
|
-
return mItemKind.Module;
|
|
452
|
-
case ls.CompletionItemKind.Property:
|
|
453
|
-
return mItemKind.Property;
|
|
454
|
-
case ls.CompletionItemKind.Unit:
|
|
455
|
-
return mItemKind.Unit;
|
|
456
|
-
case ls.CompletionItemKind.Value:
|
|
457
|
-
return mItemKind.Value;
|
|
458
|
-
case ls.CompletionItemKind.Enum:
|
|
459
|
-
return mItemKind.Enum;
|
|
460
|
-
case ls.CompletionItemKind.Keyword:
|
|
461
|
-
return mItemKind.Keyword;
|
|
462
|
-
case ls.CompletionItemKind.Snippet:
|
|
463
|
-
return mItemKind.Snippet;
|
|
464
|
-
case ls.CompletionItemKind.Color:
|
|
465
|
-
return mItemKind.Color;
|
|
466
|
-
case ls.CompletionItemKind.File:
|
|
467
|
-
return mItemKind.File;
|
|
468
|
-
case ls.CompletionItemKind.Reference:
|
|
469
|
-
return mItemKind.Reference;
|
|
470
|
-
}
|
|
471
|
-
return mItemKind.Property;
|
|
472
|
-
}
|
|
473
|
-
function toTextEdit(textEdit) {
|
|
474
|
-
if (!textEdit) {
|
|
475
|
-
return void 0;
|
|
476
|
-
}
|
|
477
|
-
return {
|
|
478
|
-
range: toRange(textEdit.range),
|
|
479
|
-
text: textEdit.newText
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
const DEFAULT_DOCS_BASE_URL = 'https://learn.microsoft.com/azure/data-explorer/kusto/query';
|
|
483
|
-
class CompletionAdapter {
|
|
484
|
-
constructor(workerAccessor, languageSettings) {
|
|
485
|
-
this.languageSettings = languageSettings;
|
|
486
|
-
const getFromLanguageService = async (resource, position) => {
|
|
487
|
-
const worker = await workerAccessor(resource);
|
|
488
|
-
return worker.doComplete(resource.toString(), position);
|
|
8
|
+
return t;
|
|
489
9
|
};
|
|
490
|
-
this
|
|
491
|
-
}
|
|
492
|
-
get triggerCharacters() {
|
|
493
|
-
return [' ', '.', '('];
|
|
494
|
-
}
|
|
495
|
-
provideCompletionItems(model, position, context, token) {
|
|
496
|
-
const wordInfo = model.getWordUntilPosition(position);
|
|
497
|
-
const wordRange = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
|
|
498
|
-
const resource = model.uri;
|
|
499
|
-
const userInput = model?.getWordAtPosition(position)?.word;
|
|
500
|
-
const onDidProvideCompletionItems = this.languageSettings.onDidProvideCompletionItems;
|
|
501
|
-
return this.completionCacheManager.getCompletionItems(userInput, resource, fromPosition(position)).then(info => onDidProvideCompletionItems ? onDidProvideCompletionItems(info) : info).then(info => {
|
|
502
|
-
if (!info) return;
|
|
503
|
-
const selectedItem = getFocusedItem(info.items, userInput);
|
|
504
|
-
let items = info.items.map((entry, index) => {
|
|
505
|
-
let item = {
|
|
506
|
-
label: entry.label,
|
|
507
|
-
insertText: entry.insertText,
|
|
508
|
-
sortText: entry.sortText,
|
|
509
|
-
filterText: createCompletionFilteredText(userInput, entry),
|
|
510
|
-
// TODO: Is this cast safe?
|
|
511
|
-
documentation: this.formatDocLink(entry.documentation?.value),
|
|
512
|
-
detail: entry.detail,
|
|
513
|
-
range: wordRange,
|
|
514
|
-
kind: toCompletionItemKind(entry.kind),
|
|
515
|
-
preselect: selectedItem.filterText === entry.filterText
|
|
516
|
-
};
|
|
517
|
-
if (entry.textEdit) {
|
|
518
|
-
// TODO: Where is the "range" property coming from?
|
|
519
|
-
item.range = toRange(entry.textEdit.range);
|
|
520
|
-
item.insertText = entry.textEdit.newText;
|
|
521
|
-
}
|
|
522
|
-
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
523
|
-
item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
524
|
-
}
|
|
525
|
-
return item;
|
|
526
|
-
});
|
|
527
|
-
return {
|
|
528
|
-
incomplete: true,
|
|
529
|
-
suggestions: items
|
|
530
|
-
};
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
formatDocLink(docString) {
|
|
534
|
-
// If the docString is empty, we want to return undefined to prevent an empty documentation popup.
|
|
535
|
-
if (!docString) {
|
|
536
|
-
return undefined;
|
|
537
|
-
}
|
|
538
|
-
const {
|
|
539
|
-
documentationBaseUrl = DEFAULT_DOCS_BASE_URL,
|
|
540
|
-
documentationSuffix
|
|
541
|
-
} = this.languageSettings;
|
|
542
|
-
const urisProxy = new Proxy({}, {
|
|
543
|
-
get(_target, prop, _receiver) {
|
|
544
|
-
// The link comes with a postfix of ".md" that we want to remove
|
|
545
|
-
let url = prop.toString().replace('.md', '');
|
|
546
|
-
// Sometimes we get the link as a full URL. For example in the main doc link of the item
|
|
547
|
-
if (!url.startsWith('https')) {
|
|
548
|
-
url = `${documentationBaseUrl}/${url}`;
|
|
549
|
-
}
|
|
550
|
-
const monacoUri = monaco.Uri.parse(url);
|
|
551
|
-
if (documentationSuffix) {
|
|
552
|
-
// We need to override the toString method to add the suffix, otherwise it gets encoded and page doesn't open
|
|
553
|
-
monacoUri.toString = () => url + documentationSuffix;
|
|
554
|
-
}
|
|
555
|
-
return monacoUri;
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
return {
|
|
559
|
-
value: docString,
|
|
560
|
-
isTrusted: true,
|
|
561
|
-
uris: urisProxy
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function isMarkupContent(thing) {
|
|
566
|
-
return thing && typeof thing === 'object' && typeof thing.kind === 'string';
|
|
567
|
-
}
|
|
568
|
-
function toMarkdownString(entry) {
|
|
569
|
-
if (typeof entry === 'string') {
|
|
570
|
-
return {
|
|
571
|
-
value: entry
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
if (isMarkupContent(entry)) {
|
|
575
|
-
if (entry.kind === 'plaintext') {
|
|
576
|
-
return {
|
|
577
|
-
value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
return {
|
|
581
|
-
value: entry.value
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
return {
|
|
585
|
-
value: '```' + entry.value + '\n' + entry.value + '\n```\n'
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
function toMarkedStringArray(contents) {
|
|
589
|
-
if (!contents) {
|
|
590
|
-
return void 0;
|
|
591
|
-
}
|
|
592
|
-
if (Array.isArray(contents)) {
|
|
593
|
-
return contents.map(toMarkdownString);
|
|
594
|
-
}
|
|
595
|
-
return [toMarkdownString(contents)];
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// --- definition ------
|
|
599
|
-
|
|
600
|
-
function toLocation(location) {
|
|
601
|
-
return {
|
|
602
|
-
uri: monaco.Uri.parse(location.uri),
|
|
603
|
-
range: toRange(location.range)
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
class DefinitionAdapter {
|
|
607
|
-
constructor(_worker) {
|
|
608
|
-
this._worker = _worker;
|
|
609
|
-
}
|
|
610
|
-
provideDefinition(model, position, token) {
|
|
611
|
-
const resource = model.uri;
|
|
612
|
-
return this._worker(resource).then(worker => {
|
|
613
|
-
return worker.findDefinition(resource.toString(), fromPosition(position));
|
|
614
|
-
}).then(definition => {
|
|
615
|
-
if (!definition || definition.length == 0) {
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
return [toLocation(definition[0])];
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// --- references ------
|
|
624
|
-
|
|
625
|
-
class ReferenceAdapter {
|
|
626
|
-
constructor(_worker) {
|
|
627
|
-
this._worker = _worker;
|
|
628
|
-
}
|
|
629
|
-
provideReferences(model, position, context, token) {
|
|
630
|
-
const resource = model.uri;
|
|
631
|
-
return this._worker(resource).then(worker => {
|
|
632
|
-
return worker.findReferences(resource.toString(), fromPosition(position));
|
|
633
|
-
}).then(entries => {
|
|
634
|
-
if (!entries) {
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
return entries.map(toLocation);
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// --- rename ------
|
|
643
|
-
|
|
644
|
-
function toWorkspaceEdit(edit) {
|
|
645
|
-
if (!edit || !edit.changes) {
|
|
646
|
-
return void 0;
|
|
647
|
-
}
|
|
648
|
-
let resourceEdits = [];
|
|
649
|
-
for (let uri in edit.changes) {
|
|
650
|
-
const _uri = monaco.Uri.parse(uri);
|
|
651
|
-
for (let e of edit.changes[uri]) {
|
|
652
|
-
resourceEdits.push({
|
|
653
|
-
resource: _uri,
|
|
654
|
-
textEdit: {
|
|
655
|
-
range: toRange(e.range),
|
|
656
|
-
text: e.newText
|
|
657
|
-
},
|
|
658
|
-
versionId: undefined
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return {
|
|
663
|
-
edits: resourceEdits
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
class RenameAdapter {
|
|
667
|
-
constructor(_worker) {
|
|
668
|
-
this._worker = _worker;
|
|
669
|
-
}
|
|
670
|
-
provideRenameEdits(model, position, newName, token) {
|
|
671
|
-
const resource = model.uri;
|
|
672
|
-
return this._worker(resource).then(worker => {
|
|
673
|
-
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
674
|
-
}).then(edit => {
|
|
675
|
-
return toWorkspaceEdit(edit);
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// --- formatting -----
|
|
681
|
-
|
|
682
|
-
class DocumentFormatAdapter {
|
|
683
|
-
constructor(_worker) {
|
|
684
|
-
this._worker = _worker;
|
|
685
|
-
}
|
|
686
|
-
provideDocumentFormattingEdits(model, options, token) {
|
|
687
|
-
const resource = model.uri;
|
|
688
|
-
return this._worker(resource).then(worker => {
|
|
689
|
-
return worker.doDocumentFormat(resource.toString()).then(edits => edits.map(edit => toTextEdit(edit)));
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
class FormatAdapter {
|
|
694
|
-
constructor(_worker) {
|
|
695
|
-
this._worker = _worker;
|
|
696
|
-
}
|
|
697
|
-
provideDocumentRangeFormattingEdits(model, range, options, token) {
|
|
698
|
-
const resource = model.uri;
|
|
699
|
-
return this._worker(resource).then(worker => {
|
|
700
|
-
return worker.doRangeFormat(resource.toString(), fromRange(range)).then(edits => edits.map(edit => toTextEdit(edit)));
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
// --- Folding ---
|
|
706
|
-
class FoldingAdapter {
|
|
707
|
-
constructor(_worker) {
|
|
708
|
-
this._worker = _worker;
|
|
709
|
-
}
|
|
710
|
-
provideFoldingRanges(model, context, token) {
|
|
711
|
-
const resource = model.uri;
|
|
712
|
-
return this._worker(resource).then(worker => {
|
|
713
|
-
return worker.doFolding(resource.toString()).then(foldingRanges => foldingRanges.map(range => toFoldingRange(range)));
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
function toFoldingRange(range) {
|
|
718
|
-
return {
|
|
719
|
-
start: range.startLine + 1,
|
|
720
|
-
end: range.endLine + 1,
|
|
721
|
-
kind: monaco.languages.FoldingRangeKind.Region
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// --- hover ------
|
|
726
|
-
|
|
727
|
-
class HoverAdapter {
|
|
728
|
-
constructor(_worker) {
|
|
729
|
-
this._worker = _worker;
|
|
730
|
-
}
|
|
731
|
-
provideHover(model, position, token) {
|
|
732
|
-
let resource = model.uri;
|
|
733
|
-
return this._worker(resource).then(worker => {
|
|
734
|
-
return worker.doHover(resource.toString(), fromPosition(position));
|
|
735
|
-
}).then(info => {
|
|
736
|
-
if (!info) {
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
return {
|
|
740
|
-
range: toRange(info.range),
|
|
741
|
-
contents: toMarkedStringArray(info.contents)
|
|
742
|
-
};
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
const queryOperators = ['as', 'consume', 'distinct', 'evaluate', 'extend', 'getschema', 'graph-match', 'graph-merge', 'graph-to-table', 'invoke', 'join', 'limit', 'lookup', 'make-graph', 'make-series', 'mv-apply', 'mv-expand', 'order', 'parse', 'parse-kv', 'parse-where', 'project', 'project-away', 'project-keep', 'project-rename', 'project-reorder', 'range', 'reduce', 'render', 'sample', 'sample-distinct', 'scan', 'serialize', 'sort', 'summarize', 'take', 'top', 'top-hitters', 'top-nested', 'union', 'where', 'filter', 'fork', 'facet', 'range', 'consume', 'find', 'search', 'print', 'partition', 'lookup'];
|
|
748
|
-
const queryParameters = ['kind'];
|
|
749
|
-
const types = ['bool', 'datetime', 'decimal', 'double', 'dynamic', 'guid', 'int', 'long', 'real', 'string', 'timespan'];
|
|
750
|
-
const commands = ['.add', '.alter', '.alter-merge', '.append', '.as', '.assert', '.attach', '.consume', '.count', '.create', '.create-merge', '.create-or-alter', '.create-set', '.datatable', '.default', '.define', '.delete', '.detach', '.distinct', '.drop', '.drop-pretend', '.dup-next-failed-ingest', '.dup-next-ingest', '.evaluate', '.export', '.extend', '.externaldata', '.filter', '.find', '.fork', '.getschema', '.ingest', '.join', '.limit', '.load', '.make-series', '.materialize', '.move', '.mv-expand', '.order', '.parse', '.parse-where', '.partition', '.pivot', '.print', '.project', '.project-away', '.project-keep', '.project-rename', '.reduce', '.remove', '.rename', '.replace', '.restrict', '.run', '.sample', '.sample-distinct', '.save', '.search', '.serialize', '.set', '.set-or-append', '.set-or-replace', '.show', '.sort', '.summarize', '.take', '.top', '.top-hitters', '.top-nested', '.union'];
|
|
751
|
-
const functions = ['abs', 'acos', 'ago', 'array_concat', 'array_length', 'array_slice', 'array_split', 'asin', 'atan', 'atan2', 'avg', 'bag_keys', 'base64_decodestring', 'base64_encodestring', 'bin', 'bin_at', 'binary_and', 'binary_not', 'binary_or', 'binary_shift_left', 'binary_shift_right', 'binary_xor', 'case', 'ceiling', 'coalesce', 'columnifexists', 'cos', 'count', 'countof', 'cot', 'cursor_after', 'datatable', 'datepart', 'datetime_add', 'datetime_diff', 'datetime_part', 'dayofmonth', 'dayofweek', 'dayofyear', 'dcount', 'dcount_hll', 'degrees', 'endofday', 'endofmonth', 'endofweek', 'endofyear', 'exp', 'exp10', 'exp2', 'extract', 'extractall', 'extractjson', 'format_datetime', 'format_timespan', 'floor', 'gamma', 'geo_distance_2points', 'geo_geohash_to_central_point', 'geo_point_in_circle', 'geo_point_in_polygon', 'geo_point_to_geohash', 'getmonth', 'gettype', 'getyear', 'hash', 'hash_sha256', 'hll_merge', 'iif', 'indexof', 'isempty', 'isfinite', 'isinf', 'isascii', 'isnan', 'isnotempty', 'isnotnull', 'isnull', 'isutf8', 'log', 'log10', 'log2', 'loggamma', 'make_datetime', 'make_string', 'make_timespan', 'materialize', 'max', 'max_of', 'min', 'min_of', 'monthofyear', 'next', 'not', 'pack', 'pack_array', 'pack_dictionary', 'parse_csv', 'parse_ipv4', 'parse_json', 'parse_path', 'parse_url', 'parse_urlquery', 'parse_user_agent', 'parse_version', 'parse_xml', 'parsejson', 'percentrank_tdigest', 'percentile_tdigest', 'pow', 'prev', 'radians', 'rand', 'rank_tdigest', 'repeat', 'replace', 'reverse', 'round', 'row_cumsum', 'row_window_session', 'series_add', 'series_decompose', 'series_decompose_anomalies', 'series_decompose_forecast', 'series_divide', 'series_equals', 'series_fill_backward', 'series_fill_const', 'series_fill_forward', 'series_fill_linear', 'series_fir', 'series_fit_2lines', 'series_fit_2lines_dynamic', 'series_fit_line', 'series_fit_line_dynamic', 'series_greater', 'series_greater_equals', 'series_iir', 'series_less', 'series_less_equals', 'series_multiply', 'series_not_equals', 'series_outliers', 'series_pearson_correlation', 'series_periods_detect', 'series_periods_validate', 'series_seasonal', 'series_stats', 'series_stats_dynamic', 'series_subtract', 'sign', 'sin', 'split', 'sqrt', 'startofday', 'startofmonth', 'startofweek', 'startofyear', 'strcat', 'strcat_array', 'strcat_delim', 'strcmp', 'strlen', 'strrep', 'string_size', 'substring', 'sum', 'tan', 'tdigest_merge', 'tobool', 'toboolean', 'todecimal', 'todouble', 'todynamic', 'tofloat', 'toguid', 'tohex', 'toint', 'tolong', 'tolower', 'toobject', 'toreal', 'toscalar', 'tostring', 'totimespan', 'toupper', 'translate', 'trim', 'trim_end', 'trim_start', 'typeof', 'url_decode', 'url_encode', 'week_of_year', 'welch_test'];
|
|
752
|
-
const keywords = ['and', 'as', 'asc', 'between', 'by', 'contains', 'count', 'desc', 'extend', 'false', 'filter', 'find', 'from', 'has', 'in', 'inner', 'join', 'leftouter', 'let', 'not', 'on', 'or', 'policy', 'project', 'project-away', 'project-rename', 'project-reorder', 'project-keep', 'range', 'rename', 'retention', 'summarize', 'table', 'take', 'to', 'true', 'where', 'with'];
|
|
753
|
-
const kustoLanguageDefinition = {
|
|
754
|
-
name: LANGUAGE_ID,
|
|
755
|
-
mimeTypes: ['text/kusto'],
|
|
756
|
-
displayName: 'Kusto',
|
|
757
|
-
defaultToken: 'invalid',
|
|
758
|
-
queryOperators,
|
|
759
|
-
queryParameters,
|
|
760
|
-
types,
|
|
761
|
-
commands,
|
|
762
|
-
functions,
|
|
763
|
-
keywords,
|
|
764
|
-
tokenizer: {
|
|
765
|
-
root: [[/(\/\/.*$)/, Token.Comment], [/[\(\)\{\}\|\[\]\:\=\,\<|\.\..]/, Token.Punctuation], [/[\+\-\*\/\%\!\<\<=\>\>=\=\==\!=\<>\:\;\,\=~\@\?\=>\!~]/, Token.MathOperator], [/"([^"\\]*(\\.[^"\\]*)*)"/, Token.StringLiteral], [/'([^"\\]*(\\.[^"\\]*)*)'/, Token.StringLiteral], [/[\w@#\-$\.]+/, {
|
|
766
|
-
cases: {
|
|
767
|
-
'@queryOperators': Token.QueryOperator,
|
|
768
|
-
'@queryParameters': Token.QueryParameter,
|
|
769
|
-
'@types': Token.Type,
|
|
770
|
-
'@commands': Token.Command,
|
|
771
|
-
'@functions': Token.Function,
|
|
772
|
-
'@keywords': Token.Keyword,
|
|
773
|
-
'@default': 'identifier'
|
|
774
|
-
}
|
|
775
|
-
}]]
|
|
776
|
-
}
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
777
11
|
};
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
tokenTypes,
|
|
786
|
-
tokenModifiers: []
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
async provideDocumentSemanticTokens(model) {
|
|
790
|
-
const resource = model.uri;
|
|
791
|
-
const classifications = await this.classificationsGetter(resource);
|
|
792
|
-
const semanticTokens = classifications.map((classification, index) => {
|
|
793
|
-
const previousClassification = classifications[index - 1];
|
|
794
|
-
return semanticTokenMaker(classification, previousClassification);
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
795
19
|
});
|
|
796
|
-
return {
|
|
797
|
-
data: new Uint32Array(semanticTokens.flat()),
|
|
798
|
-
resultId: model.getVersionId().toString()
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
releaseDocumentSemanticTokens() {}
|
|
802
|
-
}
|
|
803
|
-
const emptyClassification = {
|
|
804
|
-
line: 0,
|
|
805
|
-
character: 0,
|
|
806
|
-
length: 0,
|
|
807
|
-
kind: 0
|
|
808
20
|
};
|
|
809
|
-
function
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
semanticTokensDisposable.dispose();
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
835
46
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
let workerPromise = new Promise((resolve, reject) => {
|
|
850
|
-
resolveWorker = resolve;
|
|
47
|
+
};
|
|
48
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
49
|
+
import { WorkerManager } from './workerManager';
|
|
50
|
+
import * as languageFeatures from './languageFeatures';
|
|
51
|
+
import { kustoLanguageDefinition } from './syntaxHighlighting/kustoMonarchLanguageDefinition';
|
|
52
|
+
import { LANGUAGE_ID } from './globals';
|
|
53
|
+
import { semanticTokensProviderRegistrarCreator } from './syntaxHighlighting/semanticTokensProviderRegistrar';
|
|
54
|
+
var kustoWorker;
|
|
55
|
+
var resolveWorker;
|
|
56
|
+
var rejectWorker;
|
|
57
|
+
var workerPromise = new Promise(function (resolve, reject) {
|
|
58
|
+
resolveWorker = resolve;
|
|
59
|
+
rejectWorker = reject;
|
|
851
60
|
});
|
|
852
|
-
|
|
853
61
|
/**
|
|
854
62
|
* Called when Kusto language is first needed (a model has the language set)
|
|
855
63
|
* @param defaults
|
|
856
64
|
*/
|
|
857
|
-
function setupMode(defaults, monacoInstance) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
65
|
+
export function setupMode(defaults, monacoInstance) {
|
|
66
|
+
var _this = this;
|
|
67
|
+
var onSchemaChange = new monaco.Emitter();
|
|
68
|
+
// TODO: when should we dispose of these? seems like monaco-css and monaco-typescript don't dispose of these.
|
|
69
|
+
var disposables = [];
|
|
70
|
+
var semanticTokensProviderRegistrar = semanticTokensProviderRegistrarCreator();
|
|
71
|
+
var client = new WorkerManager(monacoInstance, defaults);
|
|
72
|
+
disposables.push(client);
|
|
73
|
+
var workerAccessor = function (first) {
|
|
74
|
+
var more = [];
|
|
75
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
76
|
+
more[_i - 1] = arguments[_i];
|
|
77
|
+
}
|
|
78
|
+
var augmentedSetSchema = function (schema, worker) { return __awaiter(_this, void 0, void 0, function () {
|
|
79
|
+
var workerPromise;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
workerPromise = worker.setSchema(schema);
|
|
84
|
+
return [4 /*yield*/, workerPromise.then(function () {
|
|
85
|
+
onSchemaChange.fire(schema);
|
|
86
|
+
})];
|
|
87
|
+
case 1:
|
|
88
|
+
_a.sent();
|
|
89
|
+
semanticTokensProviderRegistrar(monacoInstance, workerAccessor);
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}); };
|
|
94
|
+
var worker = client.getLanguageServiceWorker.apply(client, [first].concat(more));
|
|
95
|
+
return worker.then(function (worker) { return (__assign(__assign({}, worker), { setSchema: function (schema) { return augmentedSetSchema(schema, worker); }, setSchemaFromShowSchema: function (schema, connection, database, globalScalarParameters, globalTabularParameters) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, worker.normalizeSchema(schema, connection, database).then(function (schema) {
|
|
100
|
+
if (globalScalarParameters || globalTabularParameters) {
|
|
101
|
+
schema = __assign(__assign({}, schema), { globalScalarParameters: globalScalarParameters, globalTabularParameters: globalTabularParameters });
|
|
102
|
+
}
|
|
103
|
+
augmentedSetSchema(schema, worker);
|
|
104
|
+
})];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
return [2 /*return*/];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
} })); });
|
|
871
112
|
};
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
monacoInstance.languages.setLanguageConfiguration(LANGUAGE_ID, {
|
|
905
|
-
folding: {
|
|
906
|
-
offSide: false,
|
|
907
|
-
markers: {
|
|
908
|
-
start: /^\s*[\r\n]/gm,
|
|
909
|
-
end: /^\s*[\r\n]/gm
|
|
910
|
-
}
|
|
911
|
-
},
|
|
912
|
-
comments: {
|
|
913
|
-
lineComment: '//',
|
|
914
|
-
blockComment: null
|
|
915
|
-
},
|
|
916
|
-
autoClosingPairs: [{
|
|
917
|
-
open: '{',
|
|
918
|
-
close: '}'
|
|
919
|
-
}, {
|
|
920
|
-
open: '[',
|
|
921
|
-
close: ']'
|
|
922
|
-
}, {
|
|
923
|
-
open: '(',
|
|
924
|
-
close: ')'
|
|
925
|
-
}, {
|
|
926
|
-
open: "'",
|
|
927
|
-
close: "'",
|
|
928
|
-
notIn: ['string', 'comment']
|
|
929
|
-
}, {
|
|
930
|
-
open: '"',
|
|
931
|
-
close: '"',
|
|
932
|
-
notIn: ['string', 'comment']
|
|
933
|
-
}]
|
|
934
|
-
});
|
|
935
|
-
return kustoWorker;
|
|
113
|
+
disposables.push(monacoInstance.languages.registerCompletionItemProvider(LANGUAGE_ID, new languageFeatures.CompletionAdapter(workerAccessor, defaults.languageSettings)));
|
|
114
|
+
var monarchTokensProvider = monacoInstance.languages.setMonarchTokensProvider(LANGUAGE_ID, kustoLanguageDefinition);
|
|
115
|
+
disposables.push(new languageFeatures.DiagnosticsAdapter(monacoInstance, LANGUAGE_ID, workerAccessor, defaults, onSchemaChange.event));
|
|
116
|
+
disposables.push(monacoInstance.languages.registerDocumentRangeFormattingEditProvider(LANGUAGE_ID, new languageFeatures.FormatAdapter(workerAccessor)));
|
|
117
|
+
disposables.push(monacoInstance.languages.registerFoldingRangeProvider(LANGUAGE_ID, new languageFeatures.FoldingAdapter(workerAccessor)));
|
|
118
|
+
disposables.push(monacoInstance.languages.registerDefinitionProvider(LANGUAGE_ID, new languageFeatures.DefinitionAdapter(workerAccessor)));
|
|
119
|
+
disposables.push(monacoInstance.languages.registerRenameProvider(LANGUAGE_ID, new languageFeatures.RenameAdapter(workerAccessor)));
|
|
120
|
+
disposables.push(monacoInstance.languages.registerReferenceProvider(LANGUAGE_ID, new languageFeatures.ReferenceAdapter(workerAccessor)));
|
|
121
|
+
if (defaults.languageSettings.enableHover) {
|
|
122
|
+
disposables.push(monacoInstance.languages.registerHoverProvider(LANGUAGE_ID, new languageFeatures.HoverAdapter(workerAccessor)));
|
|
123
|
+
}
|
|
124
|
+
monacoInstance.languages.registerDocumentFormattingEditProvider(LANGUAGE_ID, new languageFeatures.DocumentFormatAdapter(workerAccessor));
|
|
125
|
+
kustoWorker = workerAccessor;
|
|
126
|
+
resolveWorker(workerAccessor);
|
|
127
|
+
monacoInstance.languages.setLanguageConfiguration(LANGUAGE_ID, {
|
|
128
|
+
folding: {
|
|
129
|
+
offSide: false,
|
|
130
|
+
markers: { start: /^\s*[\r\n]/gm, end: /^\s*[\r\n]/gm },
|
|
131
|
+
},
|
|
132
|
+
comments: {
|
|
133
|
+
lineComment: '//',
|
|
134
|
+
blockComment: null,
|
|
135
|
+
},
|
|
136
|
+
autoClosingPairs: [
|
|
137
|
+
{ open: '{', close: '}' },
|
|
138
|
+
{ open: '[', close: ']' },
|
|
139
|
+
{ open: '(', close: ')' },
|
|
140
|
+
{ open: "'", close: "'", notIn: ['string', 'comment'] },
|
|
141
|
+
{ open: '"', close: '"', notIn: ['string', 'comment'] },
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
return kustoWorker;
|
|
936
145
|
}
|
|
937
|
-
function getKustoWorker() {
|
|
938
|
-
|
|
146
|
+
export function getKustoWorker() {
|
|
147
|
+
return workerPromise.then(function () { return kustoWorker; });
|
|
939
148
|
}
|
|
940
|
-
|
|
941
|
-
export { getKustoWorker, setupMode };
|