@kusto/monaco-kusto 12.0.8 → 12.0.10

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.
@@ -1,197 +1,500 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
1
+ /*!-----------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * monaco-kusto version: 12.0.10(45043a1eff35e1151edde6f70c24b55565dda115)
4
+ * Released under the MIT license
5
+ * https://https://github.com/Azure/monaco-kusto/blob/master/README.md
6
+ *-----------------------------------------------------------------------------*/
7
+
37
8
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
38
- import KustoCommandHighlighter from './commandHighlighter';
39
- import KustoCommandFormatter from './commandFormatter';
40
- import { extend } from './extendedEditor';
41
- import { themes } from './syntaxHighlighting/themes';
42
- import { LANGUAGE_ID } from './globals';
43
- import { getCslTypeNameFromClrType, getCallName, getExpression, getInputParametersAsCslString, getEntityDataTypeFromCslType, } from './languageServiceManager/schema';
44
- import { getRangeHtml } from './extendedGlobalApi';
45
- export * from './languageServiceManager/schema';
46
- export * from './languageServiceManager/renderInfo';
47
- export * from './languageServiceManager/settings';
48
- export * from './types';
49
- export * from './extendedGlobalApi';
50
- // --- Kusto configuration and defaults ---------
51
- var LanguageServiceDefaultsImpl = /** @class */ (function () {
52
- function LanguageServiceDefaultsImpl(languageSettings) {
53
- this._onDidChange = new monaco.Emitter();
54
- this.setLanguageSettings(languageSettings);
55
- // default to never kill worker when idle.
56
- // reason: when killing worker - schema gets lost. We transmit the schema back to main process when killing
57
- // the worker, but in some extreme cases web worker runs out of memory while stringifying the schema.
58
- // This stems from the fact that web workers have much more limited memory that the main process.
59
- // An alternative solution (not currently implemented) is to just save the schema in the main process whenever calling
60
- // setSchema. That way we don't need to stringify the schema on the worker side when killing the web worker.
61
- this._workerMaxIdleTime = 0;
9
+ import { editor } from 'monaco-editor/esm/vs/editor/editor.api';
10
+ import { T as Token, L as LANGUAGE_ID } from './globals-60173baa.js';
11
+ import { g as getCslTypeNameFromClrType, a as getCallName, b as getExpression, c as getInputParametersAsCslString, d as getEntityDataTypeFromCslType } from './schema-e459243d.js';
12
+ export { s as showSchema } from './schema-e459243d.js';
13
+
14
+ function getCurrentCommandRange(editor, cursorPosition) {
15
+ const zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
16
+ const lines = editor.getModel().getLinesContent();
17
+ let commandOrdinal = 0;
18
+ const linesWithCommandOrdinal = [];
19
+ for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
20
+ let isEmptyLine = lines[lineNumber].trim() === '';
21
+ if (isEmptyLine) {
22
+ // increase commandCounter - we'll be starting a new command.
23
+ linesWithCommandOrdinal.push({
24
+ commandOrdinal: commandOrdinal++,
25
+ lineNumber
26
+ });
27
+ } else {
28
+ linesWithCommandOrdinal.push({
29
+ commandOrdinal: commandOrdinal,
30
+ lineNumber
31
+ });
32
+ }
33
+
34
+ // No need to keep scanning if we're past our line and we've seen an empty line.
35
+ if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
36
+ break;
62
37
  }
63
- Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "onDidChange", {
64
- get: function () {
65
- return this._onDidChange.event;
66
- },
67
- enumerable: false,
68
- configurable: true
38
+ }
39
+ const currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
40
+ const currentCommandLines = linesWithCommandOrdinal.filter(line => line.commandOrdinal === currentCommandOrdinal);
41
+ const currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
42
+ const currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
43
+
44
+ // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
45
+ // Start-column of 1 and End column of 2 means 1st character is selected.
46
+ // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
47
+ const commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
48
+ return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
49
+ }
50
+
51
+ /**
52
+ * Extending ICode editor to contain additional kusto-specific methods.
53
+ * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
54
+ */
55
+ function extend(editor) {
56
+ const proto = Object.getPrototypeOf(editor);
57
+ proto.getCurrentCommandRange = function (cursorPosition) {
58
+ getCurrentCommandRange(this, cursorPosition);
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Highlights the command that surround cursor location
64
+ */
65
+ class KustoCommandHighlighter {
66
+ static ID = 'editor.contrib.kustoCommandHighlighter';
67
+ static CURRENT_COMMAND_HIGHLIGHT = {
68
+ className: 'selectionHighlight'
69
+ };
70
+ disposables = [];
71
+ decorations = [];
72
+
73
+ /**
74
+ * Register to cursor movement and selection events.
75
+ * @param editor monaco editor instance
76
+ */
77
+ constructor(editor) {
78
+ this.editor = editor;
79
+ // Note that selection update is triggered not only for selection changes, but also just when no text selection is occurring and cursor just moves around.
80
+ // This case is counted as a 0-length selection starting and ending on the cursor position.
81
+ this.editor.onDidChangeCursorSelection(changeEvent => {
82
+ if (this.editor.getModel().getLanguageId() !== 'kusto') {
83
+ return;
84
+ }
85
+ this.highlightCommandUnderCursor(changeEvent);
69
86
  });
70
- Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "languageSettings", {
71
- get: function () {
72
- return this._languageSettings;
73
- },
74
- enumerable: false,
75
- configurable: true
87
+ }
88
+ getId() {
89
+ return KustoCommandHighlighter.ID;
90
+ }
91
+ dispose() {
92
+ this.disposables.forEach(d => d.dispose());
93
+ }
94
+ highlightCommandUnderCursor(changeEvent) {
95
+ // Looks like the user selected a bunch of text. we don't want to highlight the entire command in this case - since highlighting
96
+ // the text is more helpful.
97
+ if (!changeEvent.selection.isEmpty()) {
98
+ this.decorations = this.editor.deltaDecorations(this.decorations, []);
99
+ return;
100
+ }
101
+ const commandRange = getCurrentCommandRange(this.editor, changeEvent.selection.getStartPosition());
102
+ const decorations = [{
103
+ range: commandRange,
104
+ options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT
105
+ }];
106
+ this.decorations = this.editor.deltaDecorations(this.decorations, decorations);
107
+ }
108
+ }
109
+
110
+ class KustoCommandFormatter {
111
+ actionAdded = false;
112
+ constructor(editor) {
113
+ this.editor = editor;
114
+ // selection also represents no selection - for example the event gets triggered when moving cursor from point
115
+ // a to point b. in the case start position will equal end position.
116
+ editor.onDidChangeCursorSelection(changeEvent => {
117
+ if (this.editor.getModel().getLanguageId() !== 'kusto') {
118
+ return;
119
+ }
120
+ // Theoretically you would expect this code to run only once in onDidCreateEditor.
121
+ // Turns out that onDidCreateEditor is fired before the IStandaloneEditor is completely created (it is emitted by
122
+ // the super ctor before the child ctor was able to fully run).
123
+ // Thus we don't have a key binding provided yet when onDidCreateEditor is run, which is essential to call addAction.
124
+ // By adding the action here in onDidChangeCursorSelection we're making sure that the editor has a key binding provider,
125
+ // and we just need to make sure that this happens only once.
126
+ if (!this.actionAdded) {
127
+ editor.addAction({
128
+ id: 'editor.action.kusto.formatCurrentCommand',
129
+ label: 'Format Command Under Cursor',
130
+ keybindings: [monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF)],
131
+ run: ed => {
132
+ editor.trigger('KustoCommandFormatter', 'editor.action.formatSelection', null);
133
+ },
134
+ contextMenuGroupId: '1_modification'
135
+ });
136
+ this.actionAdded = true;
137
+ }
76
138
  });
77
- LanguageServiceDefaultsImpl.prototype.setLanguageSettings = function (options) {
78
- this._languageSettings = options || Object.create(null);
79
- this._onDidChange.fire(this);
80
- };
81
- LanguageServiceDefaultsImpl.prototype.setMaximumWorkerIdleTime = function (value) {
82
- // doesn't fire an event since no
83
- // worker restart is required here
84
- this._workerMaxIdleTime = value;
85
- };
86
- LanguageServiceDefaultsImpl.prototype.getWorkerMaxIdleTime = function () {
87
- return this._workerMaxIdleTime;
88
- };
89
- return LanguageServiceDefaultsImpl;
90
- }());
91
- var defaultLanguageSettings = {
92
- includeControlCommands: true,
93
- newlineAfterPipe: true,
94
- openSuggestionDialogAfterPreviousSuggestionAccepted: true,
95
- enableHover: true,
96
- formatter: {
97
- indentationSize: 4,
98
- pipeOperatorStyle: 'Smart',
99
- },
100
- syntaxErrorAsMarkDown: {
101
- enableSyntaxErrorAsMarkDown: false,
102
- },
103
- enableQueryWarnings: false,
104
- enableQuerySuggestions: false,
105
- disabledDiagnosticCodes: [],
106
- quickFixCodeActions: ['Change to', 'FixAll'],
107
- enableQuickFixes: false,
108
- completionOptions: { includeExtendedSyntax: false },
139
+ }
140
+ }
141
+
142
+ let ThemeName = /*#__PURE__*/function (ThemeName) {
143
+ ThemeName["light"] = "kusto-light";
144
+ ThemeName["dark"] = "kusto-dark";
145
+ return ThemeName;
146
+ }({});
147
+ const colors = {
148
+ white: '#DCDCDC',
149
+ lightGoldenrodYellow: '#FAFAD2',
150
+ softGold: '#D7BA7D',
151
+ paleChestnut: '#D69D85',
152
+ paleVioletRed: '#DB7093',
153
+ firebrick: '#B22222',
154
+ orangeRed: '#FF4500',
155
+ mediumVioletRed: '#C71585',
156
+ magenta: '#FF00FF',
157
+ // for debugging
158
+ darkOrchid: '#9932CC',
159
+ darkViolet: '#9400D3',
160
+ midnightBlue: '#191970',
161
+ blue: '#0000FF',
162
+ blueSapphire: '#004E8C',
163
+ tealBlue: '#2B91AF',
164
+ skyBlue: '#569CD6',
165
+ lightSkyBlue: '#92CAF4',
166
+ mediumTurquoise: '#4EC9B0',
167
+ oliveDrab: '#608B4E',
168
+ green: '#008000',
169
+ jetBlack: '#1B1A19',
170
+ black: '#000000'
109
171
  };
110
- export function getKustoWorker() {
111
- return new Promise(function (resolve, reject) {
112
- withMode(function (mode) {
113
- mode.getKustoWorker().then(resolve, reject);
114
- });
172
+ const light = {
173
+ base: 'vs',
174
+ inherit: true,
175
+ rules: [{
176
+ token: '',
177
+ foreground: colors.black
178
+ }, {
179
+ token: Token.PlainText,
180
+ foreground: colors.black
181
+ }, {
182
+ token: Token.Comment,
183
+ foreground: colors.green
184
+ }, {
185
+ token: Token.Punctuation,
186
+ foreground: colors.black
187
+ }, {
188
+ token: Token.Directive,
189
+ foreground: colors.darkViolet
190
+ }, {
191
+ token: Token.Literal,
192
+ foreground: colors.black
193
+ }, {
194
+ token: Token.StringLiteral,
195
+ foreground: colors.firebrick
196
+ }, {
197
+ token: Token.Type,
198
+ foreground: colors.blue
199
+ }, {
200
+ token: Token.Column,
201
+ foreground: colors.mediumVioletRed
202
+ }, {
203
+ token: Token.Table,
204
+ foreground: colors.darkOrchid
205
+ }, {
206
+ token: Token.Database,
207
+ foreground: colors.darkOrchid
208
+ }, {
209
+ token: Token.Function,
210
+ foreground: colors.blue
211
+ }, {
212
+ token: Token.Parameter,
213
+ foreground: colors.midnightBlue
214
+ }, {
215
+ token: Token.Variable,
216
+ foreground: colors.midnightBlue
217
+ }, {
218
+ token: Token.Identifier,
219
+ foreground: colors.black
220
+ }, {
221
+ token: Token.ClientParameter,
222
+ foreground: colors.tealBlue
223
+ }, {
224
+ token: Token.QueryParameter,
225
+ foreground: colors.tealBlue
226
+ }, {
227
+ token: Token.ScalarParameter,
228
+ foreground: colors.blue
229
+ }, {
230
+ token: Token.MathOperator,
231
+ foreground: colors.black
232
+ }, {
233
+ token: Token.QueryOperator,
234
+ foreground: colors.orangeRed
235
+ }, {
236
+ token: Token.Command,
237
+ foreground: colors.blue
238
+ }, {
239
+ token: Token.Keyword,
240
+ foreground: colors.blue
241
+ }, {
242
+ token: Token.MaterializedView,
243
+ foreground: colors.darkOrchid
244
+ }, {
245
+ token: Token.SchemaMember,
246
+ foreground: colors.black
247
+ }, {
248
+ token: Token.SignatureParameter,
249
+ foreground: colors.black
250
+ }, {
251
+ token: Token.Option,
252
+ foreground: colors.black
253
+ }],
254
+ colors: {}
255
+ };
256
+ const dark = {
257
+ base: 'vs-dark',
258
+ inherit: true,
259
+ rules: [{
260
+ token: '',
261
+ foreground: colors.white
262
+ }, {
263
+ token: Token.PlainText,
264
+ foreground: colors.white
265
+ }, {
266
+ token: Token.Comment,
267
+ foreground: colors.oliveDrab
268
+ }, {
269
+ token: Token.Punctuation,
270
+ foreground: colors.white
271
+ }, {
272
+ token: Token.Directive,
273
+ foreground: colors.lightGoldenrodYellow
274
+ }, {
275
+ token: Token.Literal,
276
+ foreground: colors.white
277
+ }, {
278
+ token: Token.StringLiteral,
279
+ foreground: colors.paleChestnut
280
+ }, {
281
+ token: Token.Type,
282
+ foreground: colors.skyBlue
283
+ }, {
284
+ token: Token.Column,
285
+ foreground: colors.paleVioletRed
286
+ }, {
287
+ token: Token.Table,
288
+ foreground: colors.softGold
289
+ }, {
290
+ token: Token.Database,
291
+ foreground: colors.softGold
292
+ }, {
293
+ token: Token.Function,
294
+ foreground: colors.skyBlue
295
+ }, {
296
+ token: Token.Parameter,
297
+ foreground: colors.lightSkyBlue
298
+ }, {
299
+ token: Token.Variable,
300
+ foreground: colors.lightSkyBlue
301
+ }, {
302
+ token: Token.Identifier,
303
+ foreground: colors.white
304
+ }, {
305
+ token: Token.ClientParameter,
306
+ foreground: colors.tealBlue
307
+ }, {
308
+ token: Token.QueryParameter,
309
+ foreground: colors.tealBlue
310
+ }, {
311
+ token: Token.ScalarParameter,
312
+ foreground: colors.skyBlue
313
+ }, {
314
+ token: Token.MathOperator,
315
+ foreground: colors.white
316
+ }, {
317
+ token: Token.QueryOperator,
318
+ foreground: colors.mediumTurquoise
319
+ }, {
320
+ token: Token.Command,
321
+ foreground: colors.skyBlue
322
+ }, {
323
+ token: Token.Keyword,
324
+ foreground: colors.skyBlue
325
+ }, {
326
+ token: Token.MaterializedView,
327
+ foreground: colors.softGold
328
+ }, {
329
+ token: Token.SchemaMember,
330
+ foreground: colors.white
331
+ }, {
332
+ token: Token.SignatureParameter,
333
+ foreground: colors.white
334
+ }, {
335
+ token: Token.Option,
336
+ foreground: colors.white
337
+ }],
338
+ colors: {
339
+ 'editor.background': colors.jetBlack,
340
+ 'editorSuggestWidget.selectedBackground': colors.blueSapphire
341
+ }
342
+ };
343
+ const themes = [{
344
+ name: ThemeName.light,
345
+ data: light
346
+ }, {
347
+ name: ThemeName.dark,
348
+ data: dark
349
+ }];
350
+
351
+ function getRangeHtml(model, range) {
352
+ const {
353
+ startLineNumber,
354
+ endLineNumber,
355
+ endColumn
356
+ } = range;
357
+ const isLastLineEmpty = endColumn === 1;
358
+ const actualLastLine = isLastLineEmpty ? endLineNumber - 1 : endLineNumber;
359
+ const totalLines = actualLastLine - startLineNumber + 1;
360
+ const colorizedLines = new Array(totalLines).fill(undefined).map((_, index) => editor.colorizeModelLine(model, startLineNumber + index));
361
+ return colorizedLines.join('<br/>');
362
+ }
363
+
364
+ // --- Kusto configuration and defaults ---------
365
+
366
+ class LanguageServiceDefaultsImpl {
367
+ _onDidChange = new monaco.Emitter();
368
+
369
+ // in milliseconds. For example - this is 2 minutes 2 * 60 * 1000
370
+
371
+ constructor(languageSettings) {
372
+ this.setLanguageSettings(languageSettings);
373
+ // default to never kill worker when idle.
374
+ // reason: when killing worker - schema gets lost. We transmit the schema back to main process when killing
375
+ // the worker, but in some extreme cases web worker runs out of memory while stringifying the schema.
376
+ // This stems from the fact that web workers have much more limited memory that the main process.
377
+ // An alternative solution (not currently implemented) is to just save the schema in the main process whenever calling
378
+ // setSchema. That way we don't need to stringify the schema on the worker side when killing the web worker.
379
+ this._workerMaxIdleTime = 0;
380
+ }
381
+ get onDidChange() {
382
+ return this._onDidChange.event;
383
+ }
384
+ get languageSettings() {
385
+ return this._languageSettings;
386
+ }
387
+ setLanguageSettings(options) {
388
+ this._languageSettings = options || Object.create(null);
389
+ this._onDidChange.fire(this);
390
+ }
391
+ setMaximumWorkerIdleTime(value) {
392
+ // doesn't fire an event since no
393
+ // worker restart is required here
394
+ this._workerMaxIdleTime = value;
395
+ }
396
+ getWorkerMaxIdleTime() {
397
+ return this._workerMaxIdleTime;
398
+ }
399
+ }
400
+ const defaultLanguageSettings = {
401
+ includeControlCommands: true,
402
+ newlineAfterPipe: true,
403
+ openSuggestionDialogAfterPreviousSuggestionAccepted: true,
404
+ enableHover: true,
405
+ formatter: {
406
+ indentationSize: 4,
407
+ pipeOperatorStyle: 'Smart'
408
+ },
409
+ syntaxErrorAsMarkDown: {
410
+ enableSyntaxErrorAsMarkDown: false
411
+ },
412
+ enableQueryWarnings: false,
413
+ enableQuerySuggestions: false,
414
+ disabledDiagnosticCodes: [],
415
+ quickFixCodeActions: ['Change to', 'FixAll'],
416
+ enableQuickFixes: false,
417
+ completionOptions: {
418
+ includeExtendedSyntax: false
419
+ }
420
+ };
421
+ function getKustoWorker() {
422
+ return new Promise((resolve, reject) => {
423
+ withMode(mode => {
424
+ mode.getKustoWorker().then(resolve, reject);
115
425
  });
426
+ });
116
427
  }
117
428
  function withMode(callback) {
118
- return import('./kustoMode').then(callback);
429
+ return import('./kustoMode.js').then(callback);
119
430
  }
120
- export var kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
121
- var disposable;
122
- monaco.languages.onLanguage('kusto', function () { return __awaiter(void 0, void 0, void 0, function () {
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4 /*yield*/, withMode(function (mode) { return mode.setupMode(kustoDefaults, monaco); })];
126
- case 1:
127
- disposable = _a.sent();
128
- return [2 /*return*/];
129
- }
130
- });
131
- }); });
132
- monaco.editor.onWillDisposeModel(function (model) {
133
- disposable.dispose();
431
+ const kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
432
+ let disposable;
433
+ monaco.languages.onLanguage('kusto', async () => {
434
+ disposable = await withMode(mode => mode.setupMode(kustoDefaults, monaco));
134
435
  });
135
- monaco.languages.register({
136
- id: LANGUAGE_ID,
137
- extensions: ['.csl', '.kql'],
436
+ monaco.editor.onWillDisposeModel(model => {
437
+ disposable.dispose();
138
438
  });
139
- themes.forEach(function (_a) {
140
- var name = _a.name, data = _a.data;
141
- return monaco.editor.defineTheme(name, data);
439
+ monaco.languages.register({
440
+ id: LANGUAGE_ID,
441
+ extensions: ['.csl', '.kql']
142
442
  });
443
+ themes.forEach(({
444
+ name,
445
+ data
446
+ }) => monaco.editor.defineTheme(name, data));
447
+
143
448
  // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis.
144
449
  // Most other language features are initialized in kustoMode.ts
145
- monaco.editor.onDidCreateEditor(function (editor) {
146
- var _a;
147
- if ((_a = window.MonacoEnvironment) === null || _a === void 0 ? void 0 : _a.globalAPI) {
148
- // hook up extension methods to editor.
149
- extend(editor);
150
- }
151
- // TODO: asked if there's a cleaner way to register an editor contribution. looks like monaco has an internal contribution registrar but it's no exposed in the API.
152
- // https://stackoverflow.com/questions/46700245/how-to-add-an-ieditorcontribution-to-monaco-editor
153
- new KustoCommandHighlighter(editor);
154
- if (isStandaloneCodeEditor(editor)) {
155
- new KustoCommandFormatter(editor);
156
- }
157
- triggerSuggestDialogWhenCompletionItemSelected(editor);
450
+ monaco.editor.onDidCreateEditor(editor => {
451
+ if (window.MonacoEnvironment?.globalAPI) {
452
+ // hook up extension methods to editor.
453
+ extend(editor);
454
+ }
455
+
456
+ // TODO: asked if there's a cleaner way to register an editor contribution. looks like monaco has an internal contribution registrar but it's no exposed in the API.
457
+ // https://stackoverflow.com/questions/46700245/how-to-add-an-ieditorcontribution-to-monaco-editor
458
+ new KustoCommandHighlighter(editor);
459
+ if (isStandaloneCodeEditor(editor)) {
460
+ new KustoCommandFormatter(editor);
461
+ }
462
+ triggerSuggestDialogWhenCompletionItemSelected(editor);
158
463
  });
159
464
  function triggerSuggestDialogWhenCompletionItemSelected(editor) {
160
- editor.onDidChangeCursorSelection(function (event) {
161
- // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime.
162
- if (kustoDefaults &&
163
- kustoDefaults.languageSettings &&
164
- kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
165
- var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco.editor.CursorChangeReason.NotSet;
166
- // If the word at the current position is not null - meaning we did not add a space after completion.
167
- // In this case we don't want to activate the eager mode, since it will display the current selected word..
168
- if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) {
169
- return;
170
- }
171
- event.selection;
172
- // OK so now we in a situation where we know a suggestion was selected, and we want to trigger another one.
173
- // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
174
- // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
175
- // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
176
- // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions,
177
- // this is the best we have.
178
- setTimeout(function () { return editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}); }, 10);
179
- }
180
- });
465
+ editor.onDidChangeCursorSelection(event => {
466
+ // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime.
467
+ if (kustoDefaults && kustoDefaults.languageSettings && kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
468
+ var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco.editor.CursorChangeReason.NotSet;
469
+ // If the word at the current position is not null - meaning we did not add a space after completion.
470
+ // In this case we don't want to activate the eager mode, since it will display the current selected word..
471
+ if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) {
472
+ return;
473
+ }
474
+ event.selection;
475
+ // OK so now we in a situation where we know a suggestion was selected, and we want to trigger another one.
476
+ // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
477
+ // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
478
+ // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
479
+ // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions,
480
+ // this is the best we have.
481
+ setTimeout(() => editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}), 10);
482
+ }
483
+ });
181
484
  }
182
485
  function isStandaloneCodeEditor(editor) {
183
- return editor.addAction !== undefined;
486
+ return editor.addAction !== undefined;
184
487
  }
185
- var globalApi = {
186
- getCslTypeNameFromClrType: getCslTypeNameFromClrType,
187
- getCallName: getCallName,
188
- getExpression: getExpression,
189
- getInputParametersAsCslString: getInputParametersAsCslString,
190
- getEntityDataTypeFromCslType: getEntityDataTypeFromCslType,
191
- kustoDefaults: kustoDefaults,
192
- getKustoWorker: getKustoWorker,
193
- getRangeHtml: getRangeHtml,
488
+ const globalApi = {
489
+ getCslTypeNameFromClrType,
490
+ getCallName,
491
+ getExpression,
492
+ getInputParametersAsCslString,
493
+ getEntityDataTypeFromCslType,
494
+ kustoDefaults,
495
+ getKustoWorker,
496
+ getRangeHtml
194
497
  };
195
498
  monaco.languages.kusto = globalApi;
196
- // I am not sure why this is needed, but it is. Without it, parcel production build removes this function.
197
- export { getRangeHtml };
499
+
500
+ export { getCallName, getCslTypeNameFromClrType, getEntityDataTypeFromCslType, getExpression, getInputParametersAsCslString, getKustoWorker, getRangeHtml, kustoDefaults };