UNPKG

@kusto/monaco-kusto

Version:

CSL, KQL plugin for the Monaco Editor

693 lines (671 loc) 41.8 kB
/*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * monaco-kusto version: 13.1.1(178105a761985a9b7c16d45b528f829e1c112ff0) * Released under the MIT license * https://https://github.com/Azure/monaco-kusto/blob/master/README.md *-----------------------------------------------------------------------------*/ define('vs/language/kusto/monaco.contribution', ['require', 'exports', 'vs/editor/editor.main', './types-7f893d92', './schema-46504958'], (function (require, exports, monaco, types, schema) { 'use strict'; function _interopNamespaceDefault(e) { var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var monaco__namespace = /*#__PURE__*/_interopNamespaceDefault(monaco); function getCurrentCommandRange(editor, cursorPosition) { var zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1; var lines = editor.getModel().getLinesContent(); var commandOrdinal = 0; var linesWithCommandOrdinal = []; for (var lineNumber = 0; lineNumber < lines.length; lineNumber++) { var isEmptyLine = lines[lineNumber].trim() === ''; if (isEmptyLine) { // increase commandCounter - we'll be starting a new command. linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal++, lineNumber: lineNumber }); } else { linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal, lineNumber: lineNumber }); } // No need to keep scanning if we're past our line and we've seen an empty line. if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) { break; } } var currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal; var currentCommandLines = linesWithCommandOrdinal.filter(function (line) { return line.commandOrdinal === currentCommandOrdinal; }); var currentCommandStartLine = currentCommandLines[0].lineNumber + 1; var currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1; // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis. // Start-column of 1 and End column of 2 means 1st character is selected. // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted. var commandEndColumn = lines[currentCommandEndLine - 1].length + 1; return new monaco__namespace.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn); } /** * Extending ICode editor to contain additional kusto-specific methods. * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless. */ function extend(editor) { var proto = Object.getPrototypeOf(editor); proto.getCurrentCommandRange = function (cursorPosition) { getCurrentCommandRange(this, cursorPosition); }; } function _typeof$3(o) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$3(o); } function _classCallCheck$3(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties$3(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey$3(o.key), o); } } function _createClass$3(e, r, t) { return r && _defineProperties$3(e.prototype, r), t && _defineProperties$3(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty$3(e, r, t) { return (r = _toPropertyKey$3(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey$3(t) { var i = _toPrimitive$3(t, "string"); return "symbol" == _typeof$3(i) ? i : i + ""; } function _toPrimitive$3(t, r) { if ("object" != _typeof$3(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof$3(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Highlights the command that surround cursor location */ var KustoCommandHighlighter = /*#__PURE__*/function () { /** * Register to cursor movement and selection events. * @param editor monaco editor instance */ function KustoCommandHighlighter(editor) { var _this = this; _classCallCheck$3(this, KustoCommandHighlighter); _defineProperty$3(this, "disposables", []); _defineProperty$3(this, "decorations", []); this.editor = editor; // 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. // This case is counted as a 0-length selection starting and ending on the cursor position. this.editor.onDidChangeCursorSelection(function (changeEvent) { if (_this.editor.getModel().getLanguageId() !== 'kusto') { return; } _this.highlightCommandUnderCursor(changeEvent); }); } return _createClass$3(KustoCommandHighlighter, [{ key: "getId", value: function getId() { return KustoCommandHighlighter.ID; } }, { key: "dispose", value: function dispose() { this.disposables.forEach(function (d) { return d.dispose(); }); } }, { key: "highlightCommandUnderCursor", value: function highlightCommandUnderCursor(changeEvent) { // Looks like the user selected a bunch of text. we don't want to highlight the entire command in this case - since highlighting // the text is more helpful. if (!changeEvent.selection.isEmpty()) { this.decorations = this.editor.deltaDecorations(this.decorations, []); return; } var commandRange = getCurrentCommandRange(this.editor, changeEvent.selection.getStartPosition()); var decorations = [{ range: commandRange, options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT }]; this.decorations = this.editor.deltaDecorations(this.decorations, decorations); } }]); }(); _defineProperty$3(KustoCommandHighlighter, "ID", 'editor.contrib.kustoCommandHighlighter'); _defineProperty$3(KustoCommandHighlighter, "CURRENT_COMMAND_HIGHLIGHT", { className: 'selectionHighlight' }); function _typeof$2(o) { "@babel/helpers - typeof"; return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$2(o); } function _defineProperties$2(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey$2(o.key), o); } } function _createClass$2(e, r, t) { return r && _defineProperties$2(e.prototype, r), t && _defineProperties$2(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _classCallCheck$2(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperty$2(e, r, t) { return (r = _toPropertyKey$2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey$2(t) { var i = _toPrimitive$2(t, "string"); return "symbol" == _typeof$2(i) ? i : i + ""; } function _toPrimitive$2(t, r) { if ("object" != _typeof$2(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof$2(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var KustoCommandFormatter = /*#__PURE__*/_createClass$2(function KustoCommandFormatter(editor) { var _this = this; _classCallCheck$2(this, KustoCommandFormatter); _defineProperty$2(this, "actionAdded", false); this.editor = editor; // selection also represents no selection - for example the event gets triggered when moving cursor from point // a to point b. in the case start position will equal end position. editor.onDidChangeCursorSelection(function (changeEvent) { if (_this.editor.getModel().getLanguageId() !== 'kusto') { return; } // Theoretically you would expect this code to run only once in onDidCreateEditor. // Turns out that onDidCreateEditor is fired before the IStandaloneEditor is completely created (it is emitted by // the super ctor before the child ctor was able to fully run). // Thus we don't have a key binding provided yet when onDidCreateEditor is run, which is essential to call addAction. // By adding the action here in onDidChangeCursorSelection we're making sure that the editor has a key binding provider, // and we just need to make sure that this happens only once. if (!_this.actionAdded) { editor.addAction({ id: 'editor.action.kusto.formatCurrentCommand', label: 'Format Command Under Cursor', keybindings: [monaco__namespace.KeyMod.chord(monaco__namespace.KeyMod.CtrlCmd | monaco__namespace.KeyCode.KeyK, monaco__namespace.KeyMod.CtrlCmd | monaco__namespace.KeyCode.KeyF)], run: function run(ed) { editor.trigger('KustoCommandFormatter', 'editor.action.formatSelection', null); }, contextMenuGroupId: '1_modification' }); _this.actionAdded = true; } }); }); function dateStringWrapper(editor) { editor.onDidPaste(function (event) { var range = event.range; if (!range) return; var model = editor.getModel(); var pasted = model.getValueInRange(range); if (!isBareIsoDate(pasted)) return; var wrapped = "datetime(".concat(pasted, ")"); var edit = { range: range, text: wrapped, forceMoveMarkers: true }; var cursorStateComputer = function cursorStateComputer() { var startOffset = model.getOffsetAt(range.getStartPosition()); var endPos = model.getPositionAt(startOffset + wrapped.length); return [new monaco__namespace.Selection(endPos.lineNumber, endPos.column, endPos.lineNumber, endPos.column)]; }; editor.executeEdits('paste-date', [edit], cursorStateComputer); }); } function isBareIsoDate(text) { var s = text.trim(); return /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}Z)?$/.test(s); } var ThemeName = /*#__PURE__*/function (ThemeName) { ThemeName["light"] = "kusto-light"; ThemeName["dark"] = "kusto-dark"; return ThemeName; }({}); var colors = { white: '#DCDCDC', lightGoldenrodYellow: '#FAFAD2', softGold: '#D7BA7D', paleChestnut: '#D69D85', paleVioletRed: '#DB7093', firebrick: '#B22222', orangeRed: '#CE3600', mediumVioletRed: '#C71585', magenta: '#FF00FF', // for debugging darkOrchid: '#9932CC', darkViolet: '#9400D3', midnightBlue: '#191970', blue: '#0000FF', blueSapphire: '#004E8C', tealBlue: '#2B91AF', skyBlue: '#569CD6', lightSkyBlue: '#92CAF4', mediumTurquoise: '#4EC9B0', oliveDrab: '#608B4E', green: '#008000', jetBlack: '#1B1A19', black: '#000000' }; var light = { base: 'vs', inherit: true, rules: [{ token: '', foreground: colors.black }, { token: types.Token.PlainText, foreground: colors.black }, { token: types.Token.Comment, foreground: colors.green }, { token: types.Token.Punctuation, foreground: colors.black }, { token: types.Token.Directive, foreground: colors.darkViolet }, { token: types.Token.Literal, foreground: colors.black }, { token: types.Token.StringLiteral, foreground: colors.firebrick }, { token: types.Token.Type, foreground: colors.blue }, { token: types.Token.Column, foreground: colors.mediumVioletRed }, { token: types.Token.Table, foreground: colors.darkOrchid }, { token: types.Token.Database, foreground: colors.darkOrchid }, { token: types.Token.Function, foreground: colors.blue }, { token: types.Token.Parameter, foreground: colors.midnightBlue }, { token: types.Token.Variable, foreground: colors.midnightBlue }, { token: types.Token.Identifier, foreground: colors.black }, { token: types.Token.ClientParameter, foreground: colors.tealBlue }, { token: types.Token.QueryParameter, foreground: colors.tealBlue }, { token: types.Token.ScalarParameter, foreground: colors.blue }, { token: types.Token.MathOperator, foreground: colors.black }, { token: types.Token.QueryOperator, foreground: colors.orangeRed }, { token: types.Token.Command, foreground: colors.blue }, { token: types.Token.Keyword, foreground: colors.blue }, { token: types.Token.MaterializedView, foreground: colors.darkOrchid }, { token: types.Token.SchemaMember, foreground: colors.black }, { token: types.Token.SignatureParameter, foreground: colors.black }, { token: types.Token.Option, foreground: colors.black }], colors: {} }; var dark = { base: 'vs-dark', inherit: true, rules: [{ token: '', foreground: colors.white }, { token: types.Token.PlainText, foreground: colors.white }, { token: types.Token.Comment, foreground: colors.oliveDrab }, { token: types.Token.Punctuation, foreground: colors.white }, { token: types.Token.Directive, foreground: colors.lightGoldenrodYellow }, { token: types.Token.Literal, foreground: colors.white }, { token: types.Token.StringLiteral, foreground: colors.paleChestnut }, { token: types.Token.Type, foreground: colors.skyBlue }, { token: types.Token.Column, foreground: colors.paleVioletRed }, { token: types.Token.Table, foreground: colors.softGold }, { token: types.Token.Database, foreground: colors.softGold }, { token: types.Token.Function, foreground: colors.skyBlue }, { token: types.Token.Parameter, foreground: colors.lightSkyBlue }, { token: types.Token.Variable, foreground: colors.lightSkyBlue }, { token: types.Token.Identifier, foreground: colors.white }, { token: types.Token.ClientParameter, foreground: colors.tealBlue }, { token: types.Token.QueryParameter, foreground: colors.tealBlue }, { token: types.Token.ScalarParameter, foreground: colors.skyBlue }, { token: types.Token.MathOperator, foreground: colors.white }, { token: types.Token.QueryOperator, foreground: colors.mediumTurquoise }, { token: types.Token.Command, foreground: colors.skyBlue }, { token: types.Token.Keyword, foreground: colors.skyBlue }, { token: types.Token.MaterializedView, foreground: colors.softGold }, { token: types.Token.SchemaMember, foreground: colors.white }, { token: types.Token.SignatureParameter, foreground: colors.white }, { token: types.Token.Option, foreground: colors.white }], colors: { 'editor.background': colors.jetBlack, 'editorSuggestWidget.selectedBackground': colors.blueSapphire } }; var themes = [{ name: ThemeName.light, data: light }, { name: ThemeName.dark, data: dark }]; function getRangeHtml(model, range) { var startLineNumber = range.startLineNumber, endLineNumber = range.endLineNumber, endColumn = range.endColumn; var isLastLineEmpty = endColumn === 1; var actualLastLine = isLastLineEmpty ? endLineNumber - 1 : endLineNumber; var totalLines = actualLastLine - startLineNumber + 1; var colorizedLines = new Array(totalLines).fill(undefined).map(function (_, index) { return monaco.editor.colorizeModelLine(model, startLineNumber + index); }); return colorizedLines.join('<br/>'); } function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); } function _classCallCheck$1(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties$1(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey$1(o.key), o); } } function _createClass$1(e, r, t) { return r && _defineProperties$1(e.prototype, r), t && _defineProperties$1(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty$1(e, r, t) { return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey$1(t) { var i = _toPrimitive$1(t, "string"); return "symbol" == _typeof$1(i) ? i : i + ""; } function _toPrimitive$1(t, r) { if ("object" != _typeof$1(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof$1(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Registers a Kusto-specific action to close the IntelliSense suggestions popup. * * Note: * We register the action on the first cursor movement, not on editor creation, * because Monaco fires 'onDidCreateEditor' before the keybinding service is fully initialized. * Waiting for a cursor event guarantees that the editor is fully ready * and allows safe registration of actions with keybindings. */ var CaseInvertor = /*#__PURE__*/function () { function CaseInvertor(editor) { var _this = this; _classCallCheck$1(this, CaseInvertor); _defineProperty$1(this, "actionsRegistered", false); this.editor = editor; this.ctrlKeyMod = this.isMac() ? monaco__namespace.KeyMod.WinCtrl : monaco__namespace.KeyMod.CtrlCmd; this.editor.onDidChangeCursorSelection(function () { var _this$editor$getModel; if (((_this$editor$getModel = _this.editor.getModel()) === null || _this$editor$getModel === void 0 ? void 0 : _this$editor$getModel.getLanguageId()) !== 'kusto') { return; } if (!_this.actionsRegistered) { _this.registerUpperCaseHandler(); _this.registerLowerCaseHandler(); _this.actionsRegistered = true; } }); } return _createClass$1(CaseInvertor, [{ key: "registerUpperCaseHandler", value: function registerUpperCaseHandler() { this.editor.addAction({ id: 'kusto.toUpperCase', label: 'To Upper Case', keybindings: [this.ctrlKeyMod | monaco__namespace.KeyMod.Shift | monaco__namespace.KeyCode.KeyU], run: function run(editor) { var selectedRange = editor.getSelection(); var selectedText = editor.getModel().getValueInRange(selectedRange); var upperCaseText = selectedText.toUpperCase(); editor.executeEdits('toUpperCase', [{ range: selectedRange, text: upperCaseText }]); } }); } }, { key: "registerLowerCaseHandler", value: function registerLowerCaseHandler() { this.editor.addAction({ id: 'kusto.toLowerCase', label: 'To Lower Case', keybindings: [this.ctrlKeyMod | monaco__namespace.KeyMod.Shift | monaco__namespace.KeyCode.KeyL], run: function run(editor) { var selectedRange = editor.getSelection(); var selectedText = editor.getModel().getValueInRange(selectedRange); var lowerCaseText = selectedText.toLowerCase(); editor.executeEdits('toLowerCase', [{ range: selectedRange, text: lowerCaseText }]); } }); } }, { key: "isMac", value: function isMac() { var uaData = navigator.userAgentData; return uaData ? uaData.platform === 'macOS' : /Mac|iPod|iPhone|iPad/.test(navigator.platform); } }]); }(); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _regeneratorRuntime() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // --- Kusto configuration and defaults --------- var LanguageServiceDefaultsImpl = /*#__PURE__*/function () { // in milliseconds. For example - this is 2 minutes 2 * 60 * 1000 function LanguageServiceDefaultsImpl(languageSettings) { _classCallCheck(this, LanguageServiceDefaultsImpl); _defineProperty(this, "_onDidChange", new monaco__namespace.Emitter()); this.setLanguageSettings(languageSettings); // default to never kill worker when idle. // reason: when killing worker - schema gets lost. We transmit the schema back to main process when killing // the worker, but in some extreme cases web worker runs out of memory while stringifying the schema. // This stems from the fact that web workers have much more limited memory that the main process. // An alternative solution (not currently implemented) is to just save the schema in the main process whenever calling // setSchema. That way we don't need to stringify the schema on the worker side when killing the web worker. this._workerMaxIdleTime = 0; } return _createClass(LanguageServiceDefaultsImpl, [{ key: "onDidChange", get: function get() { return this._onDidChange.event; } }, { key: "languageSettings", get: function get() { return this._languageSettings; } }, { key: "setLanguageSettings", value: function setLanguageSettings(options) { this._languageSettings = options || Object.create(null); this._onDidChange.fire(this); } }, { key: "setMaximumWorkerIdleTime", value: function setMaximumWorkerIdleTime(value) { // doesn't fire an event since no // worker restart is required here this._workerMaxIdleTime = value; } }, { key: "getWorkerMaxIdleTime", value: function getWorkerMaxIdleTime() { return this._workerMaxIdleTime; } }]); }(); var defaultLanguageSettings = { includeControlCommands: true, newlineAfterPipe: true, openSuggestionDialogAfterPreviousSuggestionAccepted: true, enableHover: true, formatter: { indentationSize: 4, pipeOperatorStyle: 'Smart' }, syntaxErrorAsMarkDown: { enableSyntaxErrorAsMarkDown: false }, enableQueryWarnings: false, enableQuerySuggestions: false, disabledDiagnosticCodes: [], quickFixCodeActions: ['Change to', 'FixAll'], enableQuickFixes: false, completionOptions: { includeExtendedSyntax: false } }; function getKustoWorker() { return new Promise(function (resolve, reject) { withMode(function (mode) { mode.getKustoWorker().then(resolve, reject); }); }); } function withMode(callback) { return new Promise(function (resolve, reject) { require(['./kustoMode'], resolve, reject); }).then(callback); } var kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings); monaco__namespace.languages.onLanguage('kusto', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return withMode(function (mode) { return mode.setupMode(kustoDefaults, monaco__namespace); }); case 2: case "end": return _context.stop(); } }, _callee); }))); monaco__namespace.languages.register({ id: types.LANGUAGE_ID, extensions: ['.csl', '.kql'] }); themes.forEach(function (_ref2) { var name = _ref2.name, data = _ref2.data; return monaco__namespace.editor.defineTheme(name, data); }); // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis. // Most other language features are initialized in kustoMode.ts monaco__namespace.editor.onDidCreateEditor(function (editor) { var _window$MonacoEnviron; if ((_window$MonacoEnviron = window.MonacoEnvironment) !== null && _window$MonacoEnviron !== void 0 && _window$MonacoEnviron.globalAPI) { // hook up extension methods to editor. extend(editor); } // 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. // https://stackoverflow.com/questions/46700245/how-to-add-an-ieditorcontribution-to-monaco-editor new KustoCommandHighlighter(editor); if (isStandaloneCodeEditor(editor)) { new KustoCommandFormatter(editor); new CaseInvertor(editor); } triggerSuggestDialogWhenCompletionItemSelected(editor); dateStringWrapper(editor); }); function triggerSuggestDialogWhenCompletionItemSelected(editor) { editor.onDidChangeCursorSelection(function (event) { // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime. if (kustoDefaults && kustoDefaults.languageSettings && kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) { var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco__namespace.editor.CursorChangeReason.NotSet; // If the word at the current position is not null - meaning we did not add a space after completion. // In this case we don't want to activate the eager mode, since it will display the current selected word.. if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) { return; } event.selection; // OK so now we in a situation where we know a suggestion was selected, and we want to trigger another one. // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close. // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions, // this is the best we have. setTimeout(function () { return editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}); }, 10); } }); } function isStandaloneCodeEditor(editor) { return editor.addAction !== undefined; } var globalApi = { getCslTypeNameFromClrType: schema.getCslTypeNameFromClrType, getCallName: schema.getCallName, getExpression: schema.getExpression, getInputParametersAsCslString: schema.getInputParametersAsCslString, getEntityDataTypeFromCslType: schema.getEntityDataTypeFromCslType, kustoDefaults: kustoDefaults, getKustoWorker: getKustoWorker, getRangeHtml: getRangeHtml }; monaco__namespace.languages.kusto = globalApi; exports.getCallName = schema.getCallName; exports.getCslTypeNameFromClrType = schema.getCslTypeNameFromClrType; exports.getEntityDataTypeFromCslType = schema.getEntityDataTypeFromCslType; exports.getExpression = schema.getExpression; exports.getInputParametersAsCslString = schema.getInputParametersAsCslString; exports.showSchema = schema.showSchema; exports.getKustoWorker = getKustoWorker; exports.getRangeHtml = getRangeHtml; exports.kustoDefaults = kustoDefaults; }));