@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.
- package/README.md +8 -0
- package/package.json +2 -2
- package/release/dev/kustoMode.js +2 -2
- package/release/dev/kustoWorker.js +6 -4
- package/release/dev/{main-13f81e95.js → main-eff7d47e.js} +2 -2
- package/release/dev/monaco.contribution.js +2 -2
- package/release/dev/{schema-80ffff1d.js → schema-bbdce01a.js} +2 -2
- package/release/dev/{types-818d43e4.js → types-cf1c0652.js} +2 -2
- package/release/esm/{globals-69cf2754.js → globals-60173baa.js} +1 -1
- package/release/esm/kusto.worker.js +4 -4
- package/release/esm/kustoMode.d.ts +1 -1
- package/release/esm/kustoMode.js +2 -2
- package/release/esm/languageServiceManager/kustoLanguageService.js +4 -2
- package/release/esm/monaco.contribution.js +479 -176
- package/release/esm/{schema-57cbc561.js → schema-e459243d.js} +1 -1
- package/release/min/kustoMode.js +2 -2
- package/release/min/kustoWorker.js +4 -4
- package/release/min/{main-971dcd54.js → main-70bf5d9e.js} +2 -2
- package/release/min/monaco.contribution.js +2 -2
- package/release/min/{schema-53a4e17e.js → schema-6ead6a4e.js} +2 -2
- package/release/min/{types-6f91d960.js → types-2da11ba8.js} +2 -2
|
@@ -1,197 +1,500 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
39
|
-
import
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
429
|
+
return import('./kustoMode.js').then(callback);
|
|
119
430
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
monaco.languages.onLanguage('kusto',
|
|
123
|
-
|
|
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.
|
|
136
|
-
|
|
137
|
-
extensions: ['.csl', '.kql'],
|
|
436
|
+
monaco.editor.onWillDisposeModel(model => {
|
|
437
|
+
disposable.dispose();
|
|
138
438
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
486
|
+
return editor.addAction !== undefined;
|
|
184
487
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
197
|
-
export { getRangeHtml };
|
|
499
|
+
|
|
500
|
+
export { getCallName, getCslTypeNameFromClrType, getEntityDataTypeFromCslType, getExpression, getInputParametersAsCslString, getKustoWorker, getRangeHtml, kustoDefaults };
|