@kusto/monaco-kusto 12.0.0 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +1 -1
- package/release/dev/kustoMode-d3f9e09a.js +1818 -0
- package/release/dev/kustoMode.js +4 -1757
- package/release/dev/kustoWorker.js +2 -2
- package/release/dev/{main-b690e47e.js → main-f36cb42f.js} +2 -2
- package/release/dev/monaco.contribution.js +72 -66
- package/release/dev/{schema-957f5e9b.js → schema-077630e6.js} +2 -2
- package/release/esm/kusto.worker.js +2 -2
- package/release/esm/kustoMode-349f5467.js +957 -0
- package/release/esm/kustoMode.d.ts +4 -8
- package/release/esm/kustoMode.js +91 -111
- package/release/esm/languageFeatures.d.ts +1 -1
- package/release/esm/languageServiceManager/schema.d.ts +2 -2
- package/release/esm/monaco.contribution.js +42 -9
- package/release/esm/{schema-66580db4.js → schema-b8f0ba9b.js} +1 -1
- package/release/esm/syntaxHighlighting/SemanticTokensProvider.d.ts +1 -1
- package/release/esm/syntaxHighlighting/SemanticTokensProvider.js +3 -3
- package/release/esm/syntaxHighlighting/semanticTokensProviderRegistrar.d.ts +6 -0
- package/release/esm/syntaxHighlighting/semanticTokensProviderRegistrar.js +23 -0
- package/release/min/kustoMode-2dd4a01e.js +7 -0
- package/release/min/kustoMode.js +2 -2
- package/release/min/kustoWorker.js +2 -2
- package/release/min/{main-13659fc4.js → main-86d6c837.js} +2 -2
- package/release/min/monaco.contribution.js +2 -2
- package/release/min/{schema-ab3cbb28.js → schema-a60c216c.js} +2 -2
- package/release/dev/globals-0aacfe72.js +0 -46
- package/release/esm/globals-88d92b64.js +0 -40
- package/release/min/globals-cce7b304.js +0 -7
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
/*!-----------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* monaco-kusto version: 12.0.1(56b90ce0fd31e7d6792f5098d1e8204274966b6e)
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://https://github.com/Azure/monaco-kusto/blob/master/README.md
|
|
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
|
+
|
|
12
|
+
class WorkerManager {
|
|
13
|
+
constructor(_monacoInstance, defaults) {
|
|
14
|
+
this._monacoInstance = _monacoInstance;
|
|
15
|
+
this._defaults = defaults;
|
|
16
|
+
this._worker = null;
|
|
17
|
+
this._idleCheckInterval = self.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
|
18
|
+
this._lastUsedTime = 0;
|
|
19
|
+
this._configChangeListener = this._defaults.onDidChange(() => this._saveStateAndStopWorker());
|
|
20
|
+
}
|
|
21
|
+
_stopWorker() {
|
|
22
|
+
if (this._worker) {
|
|
23
|
+
this._worker.dispose();
|
|
24
|
+
this._worker = null;
|
|
25
|
+
}
|
|
26
|
+
this._client = null;
|
|
27
|
+
}
|
|
28
|
+
_saveStateAndStopWorker() {
|
|
29
|
+
if (!this._worker) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this._worker.getProxy().then(proxy => {
|
|
33
|
+
proxy.getSchema().then(schema => {
|
|
34
|
+
this._storedState = {
|
|
35
|
+
schema: schema
|
|
36
|
+
};
|
|
37
|
+
this._stopWorker();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
dispose() {
|
|
42
|
+
clearInterval(this._idleCheckInterval);
|
|
43
|
+
this._configChangeListener.dispose();
|
|
44
|
+
this._stopWorker();
|
|
45
|
+
}
|
|
46
|
+
_checkIfIdle() {
|
|
47
|
+
if (!this._worker) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const maxIdleTime = this._defaults.getWorkerMaxIdleTime();
|
|
51
|
+
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
|
52
|
+
if (maxIdleTime > 0 && timePassedSinceLastUsed > maxIdleTime) {
|
|
53
|
+
this._saveStateAndStopWorker();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_getClient() {
|
|
57
|
+
this._lastUsedTime = Date.now();
|
|
58
|
+
|
|
59
|
+
// Since onDidProvideCompletionItems is not used in web worker, and since functions cannot be trivially serialized (throws exception unable to clone), We remove it here.
|
|
60
|
+
const {
|
|
61
|
+
onDidProvideCompletionItems,
|
|
62
|
+
...languageSettings
|
|
63
|
+
} = this._defaults.languageSettings;
|
|
64
|
+
if (!this._client) {
|
|
65
|
+
this._worker = this._monacoInstance.editor.createWebWorker({
|
|
66
|
+
// module that exports the create() method and returns a `KustoWorker` instance
|
|
67
|
+
moduleId: 'vs/language/kusto/kustoWorker',
|
|
68
|
+
label: 'kusto',
|
|
69
|
+
// passed in to the create() method
|
|
70
|
+
createData: {
|
|
71
|
+
languageSettings: languageSettings,
|
|
72
|
+
languageId: 'kusto'
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this._client = this._worker.getProxy().then(proxy => {
|
|
76
|
+
// push state we held onto before killing the client.
|
|
77
|
+
if (this._storedState) {
|
|
78
|
+
return proxy.setSchema(this._storedState.schema).then(() => proxy);
|
|
79
|
+
} else {
|
|
80
|
+
return proxy;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return this._client;
|
|
85
|
+
}
|
|
86
|
+
getLanguageServiceWorker(...resources) {
|
|
87
|
+
let _client;
|
|
88
|
+
return this._getClient().then(client => {
|
|
89
|
+
_client = client;
|
|
90
|
+
}).then(_ => {
|
|
91
|
+
return this._worker.withSyncedResources(resources);
|
|
92
|
+
}).then(_ => _client);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const createCompletionCacheManager = getFromLanguageService => {
|
|
97
|
+
let completionList;
|
|
98
|
+
let lastWord;
|
|
99
|
+
return {
|
|
100
|
+
getCompletionItems: (word, resource, position) => {
|
|
101
|
+
const shouldGetItems = !lastWord || !word || !word?.includes(lastWord);
|
|
102
|
+
if (shouldGetItems) {
|
|
103
|
+
completionList = getFromLanguageService(resource, position);
|
|
104
|
+
}
|
|
105
|
+
lastWord = word;
|
|
106
|
+
return completionList;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function createCompletionFilteredText(userInput, completionItem) {
|
|
112
|
+
if (!userInput) return completionItem.filterText;
|
|
113
|
+
const containedInFilterText = completionItem.filterText.toLowerCase().includes(userInput.toLowerCase());
|
|
114
|
+
if (!containedInFilterText) return completionItem.filterText;
|
|
115
|
+
return `${userInput}${completionItem.filterText}`;
|
|
116
|
+
}
|
|
117
|
+
function getFocusedItem(completionItems, userInput) {
|
|
118
|
+
const firstCompletionItem = completionItems[0];
|
|
119
|
+
if (!userInput) return firstCompletionItem;
|
|
120
|
+
const firstMatchingItem = completionItems.find(item => item.filterText?.toLowerCase().startsWith(userInput.toLowerCase()));
|
|
121
|
+
return firstMatchingItem ?? firstCompletionItem;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// --- diagnostics ---
|
|
125
|
+
|
|
126
|
+
class DiagnosticsAdapter {
|
|
127
|
+
_disposables = [];
|
|
128
|
+
_contentListener = Object.create(null);
|
|
129
|
+
_configurationListener = Object.create(null);
|
|
130
|
+
_schemaListener = Object.create(null);
|
|
131
|
+
_cursorListener = Object.create(null);
|
|
132
|
+
_debouncedValidations = Object.create(null);
|
|
133
|
+
constructor(_monacoInstance, _languageId, _worker, defaults, onSchemaChange) {
|
|
134
|
+
this._monacoInstance = _monacoInstance;
|
|
135
|
+
this._languageId = _languageId;
|
|
136
|
+
this._worker = _worker;
|
|
137
|
+
this.defaults = defaults;
|
|
138
|
+
const onModelAdd = model => {
|
|
139
|
+
let languageId = model.getLanguageId();
|
|
140
|
+
const modelUri = model.uri.toString();
|
|
141
|
+
if (languageId !== this._languageId) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const debouncedValidation = this.getOrCreateDebouncedValidation(model, languageId);
|
|
145
|
+
this._contentListener[modelUri] = model.onDidChangeContent(e => {
|
|
146
|
+
const intervalsToValidate = changeEventToIntervals(e);
|
|
147
|
+
debouncedValidation(intervalsToValidate);
|
|
148
|
+
});
|
|
149
|
+
this._configurationListener[modelUri] = this.defaults.onDidChange(() => {
|
|
150
|
+
self.setTimeout(() => this._doValidate(model, languageId, []), 0);
|
|
151
|
+
});
|
|
152
|
+
this._schemaListener[modelUri] = onSchemaChange(() => {
|
|
153
|
+
self.setTimeout(() => this._doValidate(model, languageId, []), 0);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const onEditorAdd = editor => {
|
|
157
|
+
const editorId = editor.getId();
|
|
158
|
+
if (!this._cursorListener[editorId]) {
|
|
159
|
+
editor.onDidDispose(() => {
|
|
160
|
+
this._cursorListener[editorId]?.dispose();
|
|
161
|
+
delete this._cursorListener[editorId];
|
|
162
|
+
});
|
|
163
|
+
this._cursorListener[editorId] = editor.onDidChangeCursorSelection(e => {
|
|
164
|
+
const model = editor.getModel();
|
|
165
|
+
const languageId = model.getLanguageId();
|
|
166
|
+
if (languageId !== this._languageId) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const cursorOffset = model.getOffsetAt(e.selection.getPosition());
|
|
170
|
+
const debouncedValidation = this.getOrCreateDebouncedValidation(model, languageId);
|
|
171
|
+
debouncedValidation([{
|
|
172
|
+
start: cursorOffset,
|
|
173
|
+
end: cursorOffset
|
|
174
|
+
}]);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const onModelRemoved = model => {
|
|
179
|
+
this._monacoInstance.editor.setModelMarkers(model, this._languageId, []);
|
|
180
|
+
let uriStr = model.uri.toString();
|
|
181
|
+
let contentListener = this._contentListener[uriStr];
|
|
182
|
+
if (contentListener) {
|
|
183
|
+
contentListener.dispose();
|
|
184
|
+
delete this._contentListener[uriStr];
|
|
185
|
+
}
|
|
186
|
+
let configurationListener = this._configurationListener[uriStr];
|
|
187
|
+
if (configurationListener) {
|
|
188
|
+
configurationListener.dispose();
|
|
189
|
+
delete this._configurationListener[uriStr];
|
|
190
|
+
}
|
|
191
|
+
let schemaListener = this._schemaListener[uriStr];
|
|
192
|
+
if (schemaListener) {
|
|
193
|
+
schemaListener.dispose();
|
|
194
|
+
delete this._schemaListener[uriStr];
|
|
195
|
+
}
|
|
196
|
+
let debouncedValidation = this._debouncedValidations[uriStr];
|
|
197
|
+
if (debouncedValidation) {
|
|
198
|
+
debouncedValidation.cancel();
|
|
199
|
+
delete this._debouncedValidations[uriStr];
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
if (this.defaults.languageSettings.enableQuickFixes) {
|
|
203
|
+
this._disposables.push(monaco.languages.registerCodeActionProvider(this._languageId, {
|
|
204
|
+
provideCodeActions: async (model, range, context, _token) => {
|
|
205
|
+
const startOffset = model.getOffsetAt(range.getStartPosition());
|
|
206
|
+
const endOffset = model.getOffsetAt(range.getEndPosition());
|
|
207
|
+
// We want to show the quick fix option only if we have markers in our selected range
|
|
208
|
+
const showQuickFix = context.markers.length > 0;
|
|
209
|
+
const actions = await this.getMonacoCodeActions(model, startOffset, endOffset, showQuickFix);
|
|
210
|
+
return {
|
|
211
|
+
actions,
|
|
212
|
+
dispose: () => {}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
this._disposables.push(this._monacoInstance.editor.onDidCreateEditor(onEditorAdd));
|
|
218
|
+
this._disposables.push(this._monacoInstance.editor.onDidCreateModel(onModelAdd));
|
|
219
|
+
this._disposables.push(this._monacoInstance.editor.onWillDisposeModel(onModelRemoved));
|
|
220
|
+
this._disposables.push(this._monacoInstance.editor.onDidChangeModelLanguage(event => {
|
|
221
|
+
onModelRemoved(event.model);
|
|
222
|
+
onModelAdd(event.model);
|
|
223
|
+
}));
|
|
224
|
+
this._disposables.push({
|
|
225
|
+
dispose: () => {
|
|
226
|
+
for (let key in this._contentListener) {
|
|
227
|
+
this._contentListener[key].dispose();
|
|
228
|
+
}
|
|
229
|
+
for (let key in this._cursorListener) {
|
|
230
|
+
this._cursorListener[key].dispose();
|
|
231
|
+
}
|
|
232
|
+
for (let key in this._debouncedValidations) {
|
|
233
|
+
this._debouncedValidations[key].cancel();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
this._monacoInstance.editor.getModels().forEach(onModelAdd);
|
|
238
|
+
this._monacoInstance.editor.getEditors().forEach(onEditorAdd);
|
|
239
|
+
}
|
|
240
|
+
async getMonacoCodeActions(model, startOffset, endOffset, enableQuickFix) {
|
|
241
|
+
const actions = [];
|
|
242
|
+
const worker = await this._worker(model.uri);
|
|
243
|
+
const resource = model.uri;
|
|
244
|
+
const codeActions = await worker.getResultActions(resource.toString(), startOffset, endOffset);
|
|
245
|
+
for (let i = 0; i < codeActions.length; i++) {
|
|
246
|
+
const codeAction = codeActions[i];
|
|
247
|
+
if (codeAction.kind.includes('Extract Function')) {
|
|
248
|
+
// Ignore extract function actions for now since they are buggy currently
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const codeActionKind = this.defaults.languageSettings.quickFixCodeActions?.find(actionKind => codeAction.kind.includes(actionKind)) ? 'quickfix' : 'custom';
|
|
252
|
+
if (codeActionKind === 'quickfix' && !enableQuickFix) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const changes = codeAction.changes;
|
|
256
|
+
const edits = changes.map(change => {
|
|
257
|
+
const startPosition = model.getPositionAt(change.start);
|
|
258
|
+
const endPosition = model.getPositionAt(change.start + change.deleteLength);
|
|
259
|
+
return {
|
|
260
|
+
resource: model.uri,
|
|
261
|
+
textEdit: {
|
|
262
|
+
range: {
|
|
263
|
+
startLineNumber: startPosition.lineNumber,
|
|
264
|
+
startColumn: startPosition.column,
|
|
265
|
+
endLineNumber: endPosition.lineNumber,
|
|
266
|
+
endColumn: endPosition.column
|
|
267
|
+
},
|
|
268
|
+
text: change.insertText ?? ''
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
actions.push({
|
|
273
|
+
title: codeAction.title,
|
|
274
|
+
diagnostics: [],
|
|
275
|
+
kind: codeActionKind,
|
|
276
|
+
edit: {
|
|
277
|
+
edits: [...edits]
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return actions;
|
|
282
|
+
}
|
|
283
|
+
getOrCreateDebouncedValidation(model, languageId) {
|
|
284
|
+
const modelUri = model.uri.toString();
|
|
285
|
+
if (!this._debouncedValidations[modelUri]) {
|
|
286
|
+
this._debouncedValidations[modelUri] = debounce(intervals => this._doValidate(model, languageId, intervals), 500);
|
|
287
|
+
}
|
|
288
|
+
return this._debouncedValidations[modelUri];
|
|
289
|
+
}
|
|
290
|
+
dispose() {
|
|
291
|
+
this._disposables.forEach(d => d && d.dispose());
|
|
292
|
+
this._disposables = [];
|
|
293
|
+
}
|
|
294
|
+
_doValidate(model, languageId, intervals) {
|
|
295
|
+
if (model.isDisposed()) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const resource = model.uri;
|
|
299
|
+
const versionNumberBefore = model.getVersionId();
|
|
300
|
+
this._worker(resource).then(worker => {
|
|
301
|
+
return worker.doValidation(resource.toString(), intervals);
|
|
302
|
+
}).then(diagnostics => {
|
|
303
|
+
const newModel = this._monacoInstance.editor.getModel(resource);
|
|
304
|
+
const versionId = newModel.getVersionId();
|
|
305
|
+
if (versionId !== versionNumberBefore) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const markers = diagnostics.map(d => toDiagnostics(resource, d));
|
|
309
|
+
let model = this._monacoInstance.editor.getModel(resource);
|
|
310
|
+
let oldDecorations = model.getAllDecorations().filter(decoration => decoration.options.className == 'squiggly-error').map(decoration => decoration.id);
|
|
311
|
+
if (model && model.getLanguageId() === languageId) {
|
|
312
|
+
const syntaxErrorAsMarkDown = this.defaults.languageSettings.syntaxErrorAsMarkDown;
|
|
313
|
+
if (!syntaxErrorAsMarkDown || !syntaxErrorAsMarkDown.enableSyntaxErrorAsMarkDown) {
|
|
314
|
+
// Remove previous syntax error decorations and set the new markers (for example, when disabling syntaxErrorAsMarkDown after it was enabled)
|
|
315
|
+
model.deltaDecorations(oldDecorations, []);
|
|
316
|
+
this._monacoInstance.editor.setModelMarkers(model, languageId, markers);
|
|
317
|
+
} else {
|
|
318
|
+
// Add custom popup for syntax error: icon, header and message as markdown
|
|
319
|
+
const header = syntaxErrorAsMarkDown.header ? `**${syntaxErrorAsMarkDown.header}** \n\n` : '';
|
|
320
|
+
const icon = syntaxErrorAsMarkDown.icon ? `` : '';
|
|
321
|
+
const popupErrorHoverHeaderMessage = `${icon} ${header}`;
|
|
322
|
+
const newDecorations = markers.map(marker => {
|
|
323
|
+
return {
|
|
324
|
+
range: {
|
|
325
|
+
startLineNumber: marker.startLineNumber,
|
|
326
|
+
startColumn: marker.startColumn,
|
|
327
|
+
endLineNumber: marker.endLineNumber,
|
|
328
|
+
endColumn: marker.endColumn
|
|
329
|
+
},
|
|
330
|
+
options: {
|
|
331
|
+
hoverMessage: {
|
|
332
|
+
value: popupErrorHoverHeaderMessage + marker.message
|
|
333
|
+
},
|
|
334
|
+
className: 'squiggly-error',
|
|
335
|
+
// monaco syntax error style (red underline)
|
|
336
|
+
zIndex: 100,
|
|
337
|
+
// This message will be the upper most mesage in the popup
|
|
338
|
+
overviewRuler: {
|
|
339
|
+
// The color indication on the right ruler
|
|
340
|
+
color: 'rgb(255, 18, 18, 0.7)',
|
|
341
|
+
position: monaco.editor.OverviewRulerLane.Right
|
|
342
|
+
},
|
|
343
|
+
minimap: {
|
|
344
|
+
color: 'rgb(255, 18, 18, 0.7)',
|
|
345
|
+
position: monaco.editor.MinimapPosition.Inline
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
const oldMarkers = monaco.editor.getModelMarkers({
|
|
351
|
+
owner: languageId,
|
|
352
|
+
resource: resource
|
|
353
|
+
});
|
|
354
|
+
if (oldMarkers && oldMarkers.length > 0) {
|
|
355
|
+
// In case there were previous markers, remove their decorations (for example, when enabling syntaxErrorAsMarkDown after it was disabled)
|
|
356
|
+
oldDecorations = [];
|
|
357
|
+
// Remove previous markers
|
|
358
|
+
this._monacoInstance.editor.setModelMarkers(model, languageId, []);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Remove previous syntax error decorations and set the new decorations
|
|
362
|
+
model.deltaDecorations(oldDecorations, newDecorations);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}).then(undefined, err => {
|
|
366
|
+
console.error(err);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function changeEventToIntervals(e) {
|
|
371
|
+
return e.changes.map(change => ({
|
|
372
|
+
start: change.rangeOffset,
|
|
373
|
+
end: change.rangeOffset + change.text.length
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
function toSeverity(lsSeverity) {
|
|
377
|
+
switch (lsSeverity) {
|
|
378
|
+
case ls.DiagnosticSeverity.Error:
|
|
379
|
+
return monaco.MarkerSeverity.Error;
|
|
380
|
+
case ls.DiagnosticSeverity.Warning:
|
|
381
|
+
return monaco.MarkerSeverity.Warning;
|
|
382
|
+
case ls.DiagnosticSeverity.Information:
|
|
383
|
+
return monaco.MarkerSeverity.Info;
|
|
384
|
+
case ls.DiagnosticSeverity.Hint:
|
|
385
|
+
return monaco.MarkerSeverity.Hint;
|
|
386
|
+
default:
|
|
387
|
+
return monaco.MarkerSeverity.Info;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function toDiagnostics(resource, diag) {
|
|
391
|
+
let code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
|
|
392
|
+
return {
|
|
393
|
+
severity: toSeverity(diag.severity),
|
|
394
|
+
startLineNumber: diag.range.start.line + 1,
|
|
395
|
+
startColumn: diag.range.start.character + 1,
|
|
396
|
+
endLineNumber: diag.range.end.line + 1,
|
|
397
|
+
endColumn: diag.range.end.character + 1,
|
|
398
|
+
message: diag.message,
|
|
399
|
+
code: code,
|
|
400
|
+
source: diag.source
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// --- completion ------
|
|
405
|
+
|
|
406
|
+
function fromPosition(position) {
|
|
407
|
+
if (!position) {
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
character: position.column - 1,
|
|
412
|
+
line: position.lineNumber - 1
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function fromRange(range) {
|
|
416
|
+
if (!range) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
start: fromPosition(range.getStartPosition()),
|
|
421
|
+
end: fromPosition(range.getEndPosition())
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function toRange(range) {
|
|
425
|
+
if (!range) {
|
|
426
|
+
return void 0;
|
|
427
|
+
}
|
|
428
|
+
return new monaco.Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
|
|
429
|
+
}
|
|
430
|
+
function toCompletionItemKind(kind) {
|
|
431
|
+
let mItemKind = monaco.languages.CompletionItemKind;
|
|
432
|
+
switch (kind) {
|
|
433
|
+
case ls.CompletionItemKind.Text:
|
|
434
|
+
return mItemKind.Text;
|
|
435
|
+
case ls.CompletionItemKind.Method:
|
|
436
|
+
return mItemKind.Method;
|
|
437
|
+
case ls.CompletionItemKind.Function:
|
|
438
|
+
return mItemKind.Function;
|
|
439
|
+
case ls.CompletionItemKind.Constructor:
|
|
440
|
+
return mItemKind.Constructor;
|
|
441
|
+
case ls.CompletionItemKind.Field:
|
|
442
|
+
return mItemKind.Field;
|
|
443
|
+
case ls.CompletionItemKind.Variable:
|
|
444
|
+
return mItemKind.Variable;
|
|
445
|
+
case ls.CompletionItemKind.Class:
|
|
446
|
+
return mItemKind.Class;
|
|
447
|
+
case ls.CompletionItemKind.Interface:
|
|
448
|
+
return mItemKind.Interface;
|
|
449
|
+
case ls.CompletionItemKind.Module:
|
|
450
|
+
return mItemKind.Module;
|
|
451
|
+
case ls.CompletionItemKind.Property:
|
|
452
|
+
return mItemKind.Property;
|
|
453
|
+
case ls.CompletionItemKind.Unit:
|
|
454
|
+
return mItemKind.Unit;
|
|
455
|
+
case ls.CompletionItemKind.Value:
|
|
456
|
+
return mItemKind.Value;
|
|
457
|
+
case ls.CompletionItemKind.Enum:
|
|
458
|
+
return mItemKind.Enum;
|
|
459
|
+
case ls.CompletionItemKind.Keyword:
|
|
460
|
+
return mItemKind.Keyword;
|
|
461
|
+
case ls.CompletionItemKind.Snippet:
|
|
462
|
+
return mItemKind.Snippet;
|
|
463
|
+
case ls.CompletionItemKind.Color:
|
|
464
|
+
return mItemKind.Color;
|
|
465
|
+
case ls.CompletionItemKind.File:
|
|
466
|
+
return mItemKind.File;
|
|
467
|
+
case ls.CompletionItemKind.Reference:
|
|
468
|
+
return mItemKind.Reference;
|
|
469
|
+
}
|
|
470
|
+
return mItemKind.Property;
|
|
471
|
+
}
|
|
472
|
+
function toTextEdit(textEdit) {
|
|
473
|
+
if (!textEdit) {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
range: toRange(textEdit.range),
|
|
478
|
+
text: textEdit.newText
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
const DEFAULT_DOCS_BASE_URL = 'https://learn.microsoft.com/azure/data-explorer/kusto/query';
|
|
482
|
+
class CompletionAdapter {
|
|
483
|
+
constructor(workerAccessor, languageSettings) {
|
|
484
|
+
this.languageSettings = languageSettings;
|
|
485
|
+
const getFromLanguageService = async (resource, position) => {
|
|
486
|
+
const worker = await workerAccessor(resource);
|
|
487
|
+
return worker.doComplete(resource.toString(), position);
|
|
488
|
+
};
|
|
489
|
+
this.completionCacheManager = createCompletionCacheManager(getFromLanguageService);
|
|
490
|
+
}
|
|
491
|
+
get triggerCharacters() {
|
|
492
|
+
return [' ', '.', '('];
|
|
493
|
+
}
|
|
494
|
+
provideCompletionItems(model, position, context, token) {
|
|
495
|
+
const wordInfo = model.getWordUntilPosition(position);
|
|
496
|
+
const wordRange = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
|
|
497
|
+
const resource = model.uri;
|
|
498
|
+
const userInput = model?.getWordAtPosition(position)?.word;
|
|
499
|
+
const onDidProvideCompletionItems = this.languageSettings.onDidProvideCompletionItems;
|
|
500
|
+
return this.completionCacheManager.getCompletionItems(userInput, resource, fromPosition(position)).then(info => onDidProvideCompletionItems ? onDidProvideCompletionItems(info) : info).then(info => {
|
|
501
|
+
if (!info) return;
|
|
502
|
+
const selectedItem = getFocusedItem(info.items, userInput);
|
|
503
|
+
let items = info.items.map((entry, index) => {
|
|
504
|
+
let item = {
|
|
505
|
+
label: entry.label,
|
|
506
|
+
insertText: entry.insertText,
|
|
507
|
+
sortText: entry.sortText,
|
|
508
|
+
filterText: createCompletionFilteredText(userInput, entry),
|
|
509
|
+
// TODO: Is this cast safe?
|
|
510
|
+
documentation: this.formatDocLink(entry.documentation?.value),
|
|
511
|
+
detail: entry.detail,
|
|
512
|
+
range: wordRange,
|
|
513
|
+
kind: toCompletionItemKind(entry.kind),
|
|
514
|
+
preselect: selectedItem.filterText === entry.filterText
|
|
515
|
+
};
|
|
516
|
+
if (entry.textEdit) {
|
|
517
|
+
// TODO: Where is the "range" property coming from?
|
|
518
|
+
item.range = toRange(entry.textEdit.range);
|
|
519
|
+
item.insertText = entry.textEdit.newText;
|
|
520
|
+
}
|
|
521
|
+
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
522
|
+
item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
523
|
+
}
|
|
524
|
+
return item;
|
|
525
|
+
});
|
|
526
|
+
return {
|
|
527
|
+
incomplete: true,
|
|
528
|
+
suggestions: items
|
|
529
|
+
};
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
formatDocLink(docString) {
|
|
533
|
+
// If the docString is empty, we want to return undefined to prevent an empty documentation popup.
|
|
534
|
+
if (!docString) {
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
const {
|
|
538
|
+
documentationBaseUrl = DEFAULT_DOCS_BASE_URL,
|
|
539
|
+
documentationSuffix
|
|
540
|
+
} = this.languageSettings;
|
|
541
|
+
const urisProxy = new Proxy({}, {
|
|
542
|
+
get(_target, prop, _receiver) {
|
|
543
|
+
// The link comes with a postfix of ".md" that we want to remove
|
|
544
|
+
let url = prop.toString().replace('.md', '');
|
|
545
|
+
// Sometimes we get the link as a full URL. For example in the main doc link of the item
|
|
546
|
+
if (!url.startsWith('https')) {
|
|
547
|
+
url = `${documentationBaseUrl}/${url}`;
|
|
548
|
+
}
|
|
549
|
+
const monacoUri = monaco.Uri.parse(url);
|
|
550
|
+
if (documentationSuffix) {
|
|
551
|
+
// We need to override the toString method to add the suffix, otherwise it gets encoded and page doesn't open
|
|
552
|
+
monacoUri.toString = () => url + documentationSuffix;
|
|
553
|
+
}
|
|
554
|
+
return monacoUri;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
return {
|
|
558
|
+
value: docString,
|
|
559
|
+
isTrusted: true,
|
|
560
|
+
uris: urisProxy
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function isMarkupContent(thing) {
|
|
565
|
+
return thing && typeof thing === 'object' && typeof thing.kind === 'string';
|
|
566
|
+
}
|
|
567
|
+
function toMarkdownString(entry) {
|
|
568
|
+
if (typeof entry === 'string') {
|
|
569
|
+
return {
|
|
570
|
+
value: entry
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
if (isMarkupContent(entry)) {
|
|
574
|
+
if (entry.kind === 'plaintext') {
|
|
575
|
+
return {
|
|
576
|
+
value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
return {
|
|
580
|
+
value: entry.value
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
value: '```' + entry.value + '\n' + entry.value + '\n```\n'
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function toMarkedStringArray(contents) {
|
|
588
|
+
if (!contents) {
|
|
589
|
+
return void 0;
|
|
590
|
+
}
|
|
591
|
+
if (Array.isArray(contents)) {
|
|
592
|
+
return contents.map(toMarkdownString);
|
|
593
|
+
}
|
|
594
|
+
return [toMarkdownString(contents)];
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// --- definition ------
|
|
598
|
+
|
|
599
|
+
function toLocation(location) {
|
|
600
|
+
return {
|
|
601
|
+
uri: monaco.Uri.parse(location.uri),
|
|
602
|
+
range: toRange(location.range)
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
class DefinitionAdapter {
|
|
606
|
+
constructor(_worker) {
|
|
607
|
+
this._worker = _worker;
|
|
608
|
+
}
|
|
609
|
+
provideDefinition(model, position, token) {
|
|
610
|
+
const resource = model.uri;
|
|
611
|
+
return this._worker(resource).then(worker => {
|
|
612
|
+
return worker.findDefinition(resource.toString(), fromPosition(position));
|
|
613
|
+
}).then(definition => {
|
|
614
|
+
if (!definition || definition.length == 0) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
return [toLocation(definition[0])];
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// --- references ------
|
|
623
|
+
|
|
624
|
+
class ReferenceAdapter {
|
|
625
|
+
constructor(_worker) {
|
|
626
|
+
this._worker = _worker;
|
|
627
|
+
}
|
|
628
|
+
provideReferences(model, position, context, token) {
|
|
629
|
+
const resource = model.uri;
|
|
630
|
+
return this._worker(resource).then(worker => {
|
|
631
|
+
return worker.findReferences(resource.toString(), fromPosition(position));
|
|
632
|
+
}).then(entries => {
|
|
633
|
+
if (!entries) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
return entries.map(toLocation);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// --- rename ------
|
|
642
|
+
|
|
643
|
+
function toWorkspaceEdit(edit) {
|
|
644
|
+
if (!edit || !edit.changes) {
|
|
645
|
+
return void 0;
|
|
646
|
+
}
|
|
647
|
+
let resourceEdits = [];
|
|
648
|
+
for (let uri in edit.changes) {
|
|
649
|
+
const _uri = monaco.Uri.parse(uri);
|
|
650
|
+
for (let e of edit.changes[uri]) {
|
|
651
|
+
resourceEdits.push({
|
|
652
|
+
resource: _uri,
|
|
653
|
+
textEdit: {
|
|
654
|
+
range: toRange(e.range),
|
|
655
|
+
text: e.newText
|
|
656
|
+
},
|
|
657
|
+
versionId: undefined
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
edits: resourceEdits
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
class RenameAdapter {
|
|
666
|
+
constructor(_worker) {
|
|
667
|
+
this._worker = _worker;
|
|
668
|
+
}
|
|
669
|
+
provideRenameEdits(model, position, newName, token) {
|
|
670
|
+
const resource = model.uri;
|
|
671
|
+
return this._worker(resource).then(worker => {
|
|
672
|
+
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
673
|
+
}).then(edit => {
|
|
674
|
+
return toWorkspaceEdit(edit);
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// --- formatting -----
|
|
680
|
+
|
|
681
|
+
class DocumentFormatAdapter {
|
|
682
|
+
constructor(_worker) {
|
|
683
|
+
this._worker = _worker;
|
|
684
|
+
}
|
|
685
|
+
provideDocumentFormattingEdits(model, options, token) {
|
|
686
|
+
const resource = model.uri;
|
|
687
|
+
return this._worker(resource).then(worker => {
|
|
688
|
+
return worker.doDocumentFormat(resource.toString()).then(edits => edits.map(edit => toTextEdit(edit)));
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
class FormatAdapter {
|
|
693
|
+
constructor(_worker) {
|
|
694
|
+
this._worker = _worker;
|
|
695
|
+
}
|
|
696
|
+
provideDocumentRangeFormattingEdits(model, range, options, token) {
|
|
697
|
+
const resource = model.uri;
|
|
698
|
+
return this._worker(resource).then(worker => {
|
|
699
|
+
return worker.doRangeFormat(resource.toString(), fromRange(range)).then(edits => edits.map(edit => toTextEdit(edit)));
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// --- Folding ---
|
|
705
|
+
class FoldingAdapter {
|
|
706
|
+
constructor(_worker) {
|
|
707
|
+
this._worker = _worker;
|
|
708
|
+
}
|
|
709
|
+
provideFoldingRanges(model, context, token) {
|
|
710
|
+
const resource = model.uri;
|
|
711
|
+
return this._worker(resource).then(worker => {
|
|
712
|
+
return worker.doFolding(resource.toString()).then(foldingRanges => foldingRanges.map(range => toFoldingRange(range)));
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
function toFoldingRange(range) {
|
|
717
|
+
return {
|
|
718
|
+
start: range.startLine + 1,
|
|
719
|
+
end: range.endLine + 1,
|
|
720
|
+
kind: monaco.languages.FoldingRangeKind.Region
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// --- hover ------
|
|
725
|
+
|
|
726
|
+
class HoverAdapter {
|
|
727
|
+
constructor(_worker) {
|
|
728
|
+
this._worker = _worker;
|
|
729
|
+
}
|
|
730
|
+
provideHover(model, position, token) {
|
|
731
|
+
let resource = model.uri;
|
|
732
|
+
return this._worker(resource).then(worker => {
|
|
733
|
+
return worker.doHover(resource.toString(), fromPosition(position));
|
|
734
|
+
}).then(info => {
|
|
735
|
+
if (!info) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
return {
|
|
739
|
+
range: toRange(info.range),
|
|
740
|
+
contents: toMarkedStringArray(info.contents)
|
|
741
|
+
};
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
const LANGUAGE_ID = 'kusto';
|
|
747
|
+
|
|
748
|
+
let Token = /*#__PURE__*/function (Token) {
|
|
749
|
+
Token["PlainText"] = "plainText";
|
|
750
|
+
Token["Comment"] = "comment";
|
|
751
|
+
Token["Punctuation"] = "punctuation";
|
|
752
|
+
Token["Directive"] = "directive";
|
|
753
|
+
Token["Literal"] = "literal";
|
|
754
|
+
Token["StringLiteral"] = "stringLiteral";
|
|
755
|
+
Token["Type"] = "type";
|
|
756
|
+
Token["Column"] = "column";
|
|
757
|
+
Token["Table"] = "table";
|
|
758
|
+
Token["Database"] = "database";
|
|
759
|
+
Token["Function"] = "function";
|
|
760
|
+
Token["Parameter"] = "parameter";
|
|
761
|
+
Token["Variable"] = "variable";
|
|
762
|
+
Token["Identifier"] = "identifier";
|
|
763
|
+
Token["ClientParameter"] = "clientParameter";
|
|
764
|
+
Token["QueryParameter"] = "queryParameter";
|
|
765
|
+
Token["ScalarParameter"] = "scalarParameter";
|
|
766
|
+
Token["MathOperator"] = "mathOperator";
|
|
767
|
+
Token["QueryOperator"] = "queryOperator";
|
|
768
|
+
Token["Command"] = "command";
|
|
769
|
+
Token["Keyword"] = "keyword";
|
|
770
|
+
Token["MaterializedView"] = "materializedView";
|
|
771
|
+
Token["SchemaMember"] = "schemaMember";
|
|
772
|
+
Token["SignatureParameter"] = "signatureParameter";
|
|
773
|
+
Token["Option"] = "option";
|
|
774
|
+
return Token;
|
|
775
|
+
}({});
|
|
776
|
+
const tokenTypes = [Token.PlainText, Token.Comment, Token.Punctuation, Token.Directive, Token.Literal, Token.StringLiteral, Token.Type, Token.Column, Token.Table, Token.Database, Token.Function, Token.Parameter, Token.Variable, Token.Identifier, Token.ClientParameter, Token.QueryParameter, Token.ScalarParameter, Token.MathOperator, Token.QueryOperator, Token.Command, Token.Keyword, Token.MaterializedView, Token.SchemaMember, Token.SignatureParameter, Token.Option];
|
|
777
|
+
|
|
778
|
+
class SemanticTokensProvider {
|
|
779
|
+
constructor(classificationsGetter) {
|
|
780
|
+
this.classificationsGetter = classificationsGetter;
|
|
781
|
+
}
|
|
782
|
+
getLegend() {
|
|
783
|
+
return {
|
|
784
|
+
tokenTypes,
|
|
785
|
+
tokenModifiers: []
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
async provideDocumentSemanticTokens(model) {
|
|
789
|
+
const uri = model.uri.toString();
|
|
790
|
+
const classifications = await this.classificationsGetter(uri);
|
|
791
|
+
const semanticTokens = classifications.map((classification, index) => {
|
|
792
|
+
const previousClassification = classifications[index - 1];
|
|
793
|
+
return semanticTokenMaker(classification, previousClassification);
|
|
794
|
+
});
|
|
795
|
+
return {
|
|
796
|
+
data: new Uint32Array(semanticTokens.flat()),
|
|
797
|
+
resultId: model.getVersionId().toString()
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
releaseDocumentSemanticTokens() {}
|
|
801
|
+
}
|
|
802
|
+
const emptyClassification = {
|
|
803
|
+
line: 0,
|
|
804
|
+
character: 0,
|
|
805
|
+
length: 0,
|
|
806
|
+
kind: 0
|
|
807
|
+
};
|
|
808
|
+
function semanticTokenMaker(classification, previousClassification = emptyClassification) {
|
|
809
|
+
const {
|
|
810
|
+
line,
|
|
811
|
+
character,
|
|
812
|
+
length,
|
|
813
|
+
kind
|
|
814
|
+
} = classification;
|
|
815
|
+
const deltaLine = line - previousClassification.line;
|
|
816
|
+
const deltaStart = deltaLine ? character : character - previousClassification.character;
|
|
817
|
+
return [deltaLine, deltaStart, length, kind, 0];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// Registers semantic token provider that utilizes the language service
|
|
821
|
+
// for more context-relevant syntax highlighting.
|
|
822
|
+
function semanticTokensProviderRegistrarCreator() {
|
|
823
|
+
const semanticTokensProviderRegistrar = semanticTokensProviderRegistrarCreatorForTest();
|
|
824
|
+
return (monacoInstance, worker) => {
|
|
825
|
+
const semanticTokensProvider = semanticTokensProviderMaker(worker);
|
|
826
|
+
semanticTokensProviderRegistrar(monacoInstance, semanticTokensProvider);
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
function semanticTokensProviderRegistrarCreatorForTest() {
|
|
830
|
+
let semanticTokensDisposable;
|
|
831
|
+
return (monacoInstance, semanticTokensProvider) => {
|
|
832
|
+
if (semanticTokensDisposable) {
|
|
833
|
+
semanticTokensDisposable.dispose();
|
|
834
|
+
}
|
|
835
|
+
semanticTokensDisposable = monacoInstance.languages.registerDocumentSemanticTokensProvider(LANGUAGE_ID, semanticTokensProvider);
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
function semanticTokensProviderMaker(worker) {
|
|
839
|
+
return new SemanticTokensProvider(worker.getClassifications);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
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'];
|
|
843
|
+
const queryParameters = ['kind'];
|
|
844
|
+
const types = ['bool', 'datetime', 'decimal', 'double', 'dynamic', 'guid', 'int', 'long', 'real', 'string', 'timespan'];
|
|
845
|
+
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'];
|
|
846
|
+
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'];
|
|
847
|
+
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'];
|
|
848
|
+
const kustoLanguageDefinition = {
|
|
849
|
+
name: LANGUAGE_ID,
|
|
850
|
+
mimeTypes: ['text/kusto'],
|
|
851
|
+
displayName: 'Kusto',
|
|
852
|
+
defaultToken: 'invalid',
|
|
853
|
+
queryOperators,
|
|
854
|
+
queryParameters,
|
|
855
|
+
types,
|
|
856
|
+
commands,
|
|
857
|
+
functions,
|
|
858
|
+
keywords,
|
|
859
|
+
tokenizer: {
|
|
860
|
+
root: [[/(\/\/.*$)/, Token.Comment], [/[\(\)\{\}\|\[\]\:\=\,\<|\.\..]/, Token.Punctuation], [/[\+\-\*\/\%\!\<\<=\>\>=\=\==\!=\<>\:\;\,\=~\@\?\=>\!~]/, Token.MathOperator], [/"([^"\\]*(\\.[^"\\]*)*)"/, Token.StringLiteral], [/'([^"\\]*(\\.[^"\\]*)*)'/, Token.StringLiteral], [/[\w@#\-$\.]+/, {
|
|
861
|
+
cases: {
|
|
862
|
+
'@queryOperators': Token.QueryOperator,
|
|
863
|
+
'@queryParameters': Token.QueryParameter,
|
|
864
|
+
'@types': Token.Type,
|
|
865
|
+
'@commands': Token.Command,
|
|
866
|
+
'@functions': Token.Function,
|
|
867
|
+
'@keywords': Token.Keyword,
|
|
868
|
+
'@default': 'identifier'
|
|
869
|
+
}
|
|
870
|
+
}]]
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
let workerAccessor;
|
|
875
|
+
async function setupMode(defaults, monacoInstance) {
|
|
876
|
+
let onSchemaChange = new monaco.Emitter();
|
|
877
|
+
const client = new WorkerManager(monacoInstance, defaults);
|
|
878
|
+
const semanticTokensProviderRegistrar = semanticTokensProviderRegistrarCreator();
|
|
879
|
+
workerAccessor = async uri => {
|
|
880
|
+
const worker = await client.getLanguageServiceWorker(uri);
|
|
881
|
+
const augmentedSetSchema = async schema => {
|
|
882
|
+
await worker.setSchema(schema);
|
|
883
|
+
onSchemaChange.fire(schema);
|
|
884
|
+
semanticTokensProviderRegistrar(monacoInstance, worker);
|
|
885
|
+
};
|
|
886
|
+
const setSchemaFromShowSchema = async (schema, clusterConnectionString, databaseInContextName, globalScalarParameters, globalTabularParameters) => {
|
|
887
|
+
const normalizedSchema = await worker.normalizeSchema(schema, clusterConnectionString, databaseInContextName);
|
|
888
|
+
normalizedSchema.globalScalarParameters = globalScalarParameters;
|
|
889
|
+
normalizedSchema.globalTabularParameters = globalTabularParameters;
|
|
890
|
+
await augmentedSetSchema(normalizedSchema);
|
|
891
|
+
};
|
|
892
|
+
return {
|
|
893
|
+
...worker,
|
|
894
|
+
setSchema: augmentedSetSchema,
|
|
895
|
+
setSchemaFromShowSchema
|
|
896
|
+
};
|
|
897
|
+
};
|
|
898
|
+
monacoInstance.languages.setMonarchTokensProvider(LANGUAGE_ID, kustoLanguageDefinition);
|
|
899
|
+
const completionAdapter = new CompletionAdapter(workerAccessor, defaults.languageSettings);
|
|
900
|
+
monacoInstance.languages.registerCompletionItemProvider(LANGUAGE_ID, completionAdapter);
|
|
901
|
+
|
|
902
|
+
// this constructor has side effects and therefore doesn't need to be passed anywhere
|
|
903
|
+
new DiagnosticsAdapter(monacoInstance, LANGUAGE_ID, workerAccessor, defaults, onSchemaChange.event);
|
|
904
|
+
const documentRangeFormattingAdapter = new FormatAdapter(workerAccessor);
|
|
905
|
+
monacoInstance.languages.registerDocumentRangeFormattingEditProvider(LANGUAGE_ID, documentRangeFormattingAdapter);
|
|
906
|
+
const foldingRangeAdapter = new FoldingAdapter(workerAccessor);
|
|
907
|
+
monacoInstance.languages.registerFoldingRangeProvider(LANGUAGE_ID, foldingRangeAdapter);
|
|
908
|
+
const definitionProvider = new DefinitionAdapter(workerAccessor);
|
|
909
|
+
monacoInstance.languages.registerDefinitionProvider(LANGUAGE_ID, definitionProvider);
|
|
910
|
+
monacoInstance.languages.registerRenameProvider(LANGUAGE_ID, new RenameAdapter(workerAccessor));
|
|
911
|
+
const referenceProvider = new ReferenceAdapter(workerAccessor);
|
|
912
|
+
monacoInstance.languages.registerReferenceProvider(LANGUAGE_ID, referenceProvider);
|
|
913
|
+
if (defaults.languageSettings.enableHover) {
|
|
914
|
+
const hoverAdapter = new HoverAdapter(workerAccessor);
|
|
915
|
+
monacoInstance.languages.registerHoverProvider(LANGUAGE_ID, hoverAdapter);
|
|
916
|
+
}
|
|
917
|
+
const documentFormattingAdapter = new DocumentFormatAdapter(workerAccessor);
|
|
918
|
+
monacoInstance.languages.registerDocumentFormattingEditProvider(LANGUAGE_ID, documentFormattingAdapter);
|
|
919
|
+
const languageConfiguration = {
|
|
920
|
+
folding: {
|
|
921
|
+
offSide: false,
|
|
922
|
+
markers: {
|
|
923
|
+
start: /^\s*[\r\n]/gm,
|
|
924
|
+
end: /^\s*[\r\n]/gm
|
|
925
|
+
}
|
|
926
|
+
},
|
|
927
|
+
comments: {
|
|
928
|
+
lineComment: '//',
|
|
929
|
+
blockComment: null
|
|
930
|
+
},
|
|
931
|
+
autoClosingPairs: [{
|
|
932
|
+
open: '{',
|
|
933
|
+
close: '}'
|
|
934
|
+
}, {
|
|
935
|
+
open: '[',
|
|
936
|
+
close: ']'
|
|
937
|
+
}, {
|
|
938
|
+
open: '(',
|
|
939
|
+
close: ')'
|
|
940
|
+
}, {
|
|
941
|
+
open: "'",
|
|
942
|
+
close: "'",
|
|
943
|
+
notIn: ['string', 'comment']
|
|
944
|
+
}, {
|
|
945
|
+
open: '"',
|
|
946
|
+
close: '"',
|
|
947
|
+
notIn: ['string', 'comment']
|
|
948
|
+
}]
|
|
949
|
+
};
|
|
950
|
+
monacoInstance.languages.setLanguageConfiguration(LANGUAGE_ID, languageConfiguration);
|
|
951
|
+
return workerAccessor;
|
|
952
|
+
}
|
|
953
|
+
async function getKustoWorker() {
|
|
954
|
+
return workerAccessor;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
export { LANGUAGE_ID as L, Token as T, getKustoWorker as g, setupMode as s };
|