@kusto/monaco-kusto 10.0.21 → 11.0.0

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.
@@ -41,6 +41,7 @@ var k2 = Kusto.Language.Editor;
41
41
  var sym = Kusto.Language.Symbols;
42
42
  var GlobalState = Kusto.Language.GlobalState;
43
43
  import { getCslTypeNameFromClrType, getEntityDataTypeFromCslType } from './schema';
44
+ import { createSortingText } from './competionItemSort';
44
45
  var List = System.Collections.Generic.List$1;
45
46
  function assertNever(x) {
46
47
  throw new Error('Unexpected object: ' + x);
@@ -139,7 +140,6 @@ var symbolKindToName = (_a = {},
139
140
  var KustoLanguageService = /** @class */ (function () {
140
141
  function KustoLanguageService(schema, languageSettings) {
141
142
  var _a, _b, _c, _d;
142
- var _this = this;
143
143
  /**
144
144
  * Taken from:
145
145
  * https://msazure.visualstudio.com/One/_git/Azure-Kusto-Service?path=/Src/Tools/Kusto.Explorer.Control/QueryEditors/KustoScriptEditor/KustoScriptEditorControl2.xaml.cs&version=GBdev&line=2075&lineEnd=2075&lineStartColumn=9&lineEndColumn=77&lineStyle=plain&_a=contents
@@ -183,9 +183,6 @@ var KustoLanguageService = /** @class */ (function () {
183
183
  '3Dchart': k2.CompletionKind.RenderChart,
184
184
  list: k2.CompletionKind.RenderChart,
185
185
  };
186
- this.isIntellisenseV2 = function () {
187
- return _this._languageSettings.useIntellisenseV2 && _this._schema && _this._schema.clusterType === 'Engine';
188
- };
189
186
  this.disabledCompletionItemsV1 = {
190
187
  capacity: k.OptionKind.Policy,
191
188
  callout: k.OptionKind.Policy,
@@ -334,7 +331,7 @@ var KustoLanguageService = /** @class */ (function () {
334
331
  this.createRulesProvider(this._kustoJsSchema, this._schema.clusterType);
335
332
  };
336
333
  KustoLanguageService.prototype.doComplete = function (document, position) {
337
- return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
334
+ return this.doCompleteV2(document, position);
338
335
  };
339
336
  /**
340
337
  * important: Only use during development to test Global State.
@@ -395,10 +392,10 @@ var KustoLanguageService = /** @class */ (function () {
395
392
  (disabledItems[item.MatchText] === k2.CompletionKind.Unknown ||
396
393
  disabledItems[item.MatchText] === item.Kind));
397
394
  })
398
- .map(function (kItem, i) {
395
+ .map(function (kItem, index) {
399
396
  var v1CompletionOption = new k.CompletionOption(_this._toOptionKind[kItem.Kind] || k.OptionKind.None, kItem.DisplayText);
400
397
  var helpTopic = _this.getTopic(v1CompletionOption);
401
- // If we have AfterText it means that the cursor should no be placed at end of suggested text.
398
+ // If we have AfterText it means that the cursor should not be placed at end of suggested text.
402
399
  // In that case we switch to snippet format and represent the point where the cursor should be as
403
400
  // as '\$0'
404
401
  var _a = kItem.AfterText && kItem.AfterText.length > 0
@@ -413,19 +410,13 @@ var KustoLanguageService = /** @class */ (function () {
413
410
  format: ls.InsertTextFormat.PlainText,
414
411
  }, textToInsert = _a.textToInsert, format = _a.format;
415
412
  var lsItem = ls.CompletionItem.create(kItem.DisplayText);
416
- // Adding to columns a prefix to their sortText so they will appear first in the list
417
- var sortTextPrefix = lsItem.kind === ls.CompletionItemKind.Field ? 0 : itemsAsArray.length;
418
- var countOfWords = lsItem.label.split('_').filter(function (item) { return !!item; }).length;
419
- // We always want results with multiple words to show after shorter options.
420
- // For example: to show "count_distinct" after "count"
421
- sortTextPrefix = sortTextPrefix * countOfWords;
422
413
  var startPosition = document.positionAt(completionItems.EditStart);
423
414
  var endPosition = document.positionAt(completionItems.EditStart + completionItems.EditLength);
424
415
  lsItem.textEdit = ls.TextEdit.replace(ls.Range.create(startPosition, endPosition), textToInsert);
425
- lsItem.sortText = _this.getSortText(sortTextPrefix + i + 1);
426
416
  // Changing the first letter to be lower case, to ignore case-sensitive matching
427
- lsItem.filterText = lsItem.label.charAt(0).toLowerCase() + lsItem.label.slice(1);
417
+ lsItem.filterText = kItem.MatchText.charAt(0).toLowerCase() + kItem.MatchText.slice(1);
428
418
  lsItem.kind = _this.kustoKindToLsKindV2(kItem.Kind);
419
+ lsItem.sortText = createSortingText(index);
429
420
  lsItem.insertTextFormat = format;
430
421
  lsItem.detail = helpTopic ? helpTopic.ShortDescription : undefined;
431
422
  lsItem.documentation = helpTopic
@@ -453,56 +444,6 @@ var KustoLanguageService = /** @class */ (function () {
453
444
  }
454
445
  return k.CslDocumentation.Instance.GetTopic(completionOption);
455
446
  };
456
- KustoLanguageService.prototype.doCompleteV1 = function (document, position) {
457
- var _this = this;
458
- // TODO: fix typing in CslCommandParser to allow rulesProvider to be query only.
459
- var caretAbsolutePosition = document.offsetAt(position);
460
- // find out what's the current command to only parse this one.
461
- this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
462
- var currentCommand = this.getCurrentCommand(document, caretAbsolutePosition);
463
- var commandTextUntilCursor = '';
464
- if (currentCommand) {
465
- var commandStartOffset = currentCommand.AbsoluteStart;
466
- this.parseTextV1(currentCommand.Text, k.ParseMode.TokenizeAllText);
467
- var caretRelativePosition = caretAbsolutePosition - currentCommand.AbsoluteStart;
468
- commandTextUntilCursor = currentCommand.Text.substring(currentCommand.CslExpressionStartPosition, caretRelativePosition);
469
- }
470
- var commandTextWithoutLastWord = this.getCommandWithoutLastWord(commandTextUntilCursor);
471
- var context = this._rulesProvider.AnalyzeCommand$1(commandTextUntilCursor, currentCommand).Context;
472
- var result = { v: null };
473
- this._rulesProvider.TryMatchAnyRule(commandTextWithoutLastWord, result);
474
- var rule = result.v;
475
- if (rule) {
476
- var completionOptions = this.toArray(rule.GetCompletionOptions(context));
477
- // TODO once AppendPipePolicy becomes a public static member of ApplyPolicy in our c# code, and bridge.Net transplies this,
478
- // remove the 'as any' part..
479
- // Also = DefaultApplyPolicy is internal in c# code, so not exposed in d.ts, so we cast it to any.
480
- if (this._languageSettings.newlineAfterPipe &&
481
- rule.DefaultAfterApplyPolicy === Kusto.Data.IntelliSense.ApplyPolicy.AppendPipePolicy) {
482
- rule.DefaultAfterApplyPolicy = this._newlineAppendPipePolicy;
483
- }
484
- var options = completionOptions
485
- .filter(function (option) {
486
- return !(option && option.Value && _this.disabledCompletionItemsV1[option.Value] === option.Kind);
487
- })
488
- .map(function (option, ordinal) {
489
- var _a = _this.getTextToInsert(rule, option), insertText = _a.insertText, insertTextFormat = _a.insertTextFormat;
490
- var helpTopic = k.CslDocumentation.Instance.GetTopic(option);
491
- var item = ls.CompletionItem.create(option.Value);
492
- item.kind = _this.kustoKindToLsKind(option.Kind);
493
- item.insertText = insertText;
494
- item.insertTextFormat = insertTextFormat;
495
- item.sortText = _this.getSortText(ordinal + 1);
496
- item.detail = helpTopic ? helpTopic.ShortDescription : undefined;
497
- item.documentation = helpTopic
498
- ? { value: helpTopic.LongDescription, kind: ls.MarkupKind.Markdown }
499
- : undefined;
500
- return item;
501
- });
502
- return Promise.resolve(ls.CompletionList.create(options));
503
- }
504
- return Promise.resolve(ls.CompletionList.create([]));
505
- };
506
447
  KustoLanguageService.prototype.doRangeFormat = function (document, range) {
507
448
  if (!document) {
508
449
  return Promise.resolve([]);
@@ -614,7 +555,7 @@ var KustoLanguageService = /** @class */ (function () {
614
555
  KustoLanguageService.prototype.doValidation = function (document, changeIntervals, includeWarnings, includeSuggestions) {
615
556
  var _this = this;
616
557
  // didn't implement validation for v1.
617
- if (!document || !this.isIntellisenseV2()) {
558
+ if (!document) {
618
559
  return Promise.resolve([]);
619
560
  }
620
561
  var script = this.parseDocumentV2(document);
@@ -749,59 +690,6 @@ var KustoLanguageService = /** @class */ (function () {
749
690
  if (!document || !this._languageSettings.useSemanticColorization) {
750
691
  return Promise.resolve([]);
751
692
  }
752
- // V1 intellisense
753
- if (!this.isIntellisenseV2()) {
754
- // Handle specific ranges changes (and not the whole doc)
755
- if (changeIntervals.length > 0) {
756
- this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
757
- var affectedCommands = this.toArray(this._parser.Results).filter(function (command) {
758
- // a command is affected if it intersects at least on of changed ranges.
759
- return command // command can be null. we're filtering all nulls in the array.
760
- ? changeIntervals.some(function (_a) {
761
- var changeStart = _a.start, changeEnd = _a.end;
762
- // both intervals intersect if either the start or the end of interval A is inside interval B.
763
- // If we deleted something at the end of a command, the interval will not intersect the current command.
764
- // so we also want consider affected commands commands the end where the interval begins.
765
- // hence the + 1.
766
- return (command.AbsoluteStart >= changeStart && command.AbsoluteStart <= changeEnd) ||
767
- (changeStart >= command.AbsoluteStart && changeStart <= command.AbsoluteEnd + 1);
768
- })
769
- : false;
770
- });
771
- // We're not on any command so don't return any classifications.
772
- // this can happen if we're at the and of the file and deleting empty rows (for example).
773
- if (!affectedCommands || affectedCommands.length === 0) {
774
- return Promise.resolve([
775
- {
776
- classifications: [],
777
- absoluteStart: changeIntervals[0].start,
778
- absoluteEnd: changeIntervals[0].end,
779
- },
780
- ]);
781
- }
782
- var results = affectedCommands.map(function (command) {
783
- _this.parseTextV1(command.Text, k.ParseMode.TokenizeAllText);
784
- var k2Classifications = _this.getClassificationsFromParseResult(command.AbsoluteStart);
785
- var classifications = toClassifiedRange(k2Classifications);
786
- return {
787
- classifications: classifications,
788
- absoluteStart: command.AbsoluteStart,
789
- absoluteEnd: command.AbsoluteEnd,
790
- };
791
- });
792
- return Promise.resolve(results);
793
- }
794
- // Entire document requested
795
- this.parseDocumentV1(document, k.ParseMode.TokenizeAllText);
796
- var classifications_1 = this.getClassificationsFromParseResult();
797
- return Promise.resolve([
798
- {
799
- classifications: toClassifiedRange(classifications_1),
800
- absoluteStart: 0,
801
- absoluteEnd: document.getText().length,
802
- },
803
- ]);
804
- }
805
693
  // V2 intellisense
806
694
  var script = this.parseDocumentV2(document);
807
695
  if (changeIntervals.length > 0) {
@@ -885,7 +773,7 @@ var KustoLanguageService = /** @class */ (function () {
885
773
  KustoLanguageService.prototype.setSchema = function (schema) {
886
774
  this._schema = schema;
887
775
  // We support intellisenseV2 only if the clusterType is "Engine", even if the setting is enabled
888
- if (this._languageSettings.useIntellisenseV2 && schema && schema.clusterType === 'Engine') {
776
+ if (schema && schema.clusterType === 'Engine') {
889
777
  var kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
890
778
  this._kustoJsSchemaV2 = kustoJsSchemaV2;
891
779
  this._script = undefined;
@@ -899,7 +787,7 @@ var KustoLanguageService = /** @class */ (function () {
899
787
  };
900
788
  KustoLanguageService.prototype.setParameters = function (scalarParameters, tabularParameters) {
901
789
  var _a;
902
- if (!this._languageSettings.useIntellisenseV2 || this._schema.clusterType !== 'Engine') {
790
+ if (this._schema.clusterType !== 'Engine') {
903
791
  throw new Error('setParameters requires intellisense V2 and Engine cluster');
904
792
  }
905
793
  this._schema.globalScalarParameters = scalarParameters;
@@ -1031,13 +919,11 @@ var KustoLanguageService = /** @class */ (function () {
1031
919
  return Promise.resolve(this._schema);
1032
920
  };
1033
921
  KustoLanguageService.prototype.getCommandInContext = function (document, cursorOffset) {
1034
- return this.isIntellisenseV2()
1035
- ? this.getCommandInContextV2(document, cursorOffset)
1036
- : this.getCommandInContextV1(document, cursorOffset);
922
+ return this.getCommandInContextV2(document, cursorOffset);
1037
923
  };
1038
924
  KustoLanguageService.prototype.getCommandAndLocationInContext = function (document, cursorOffset) {
1039
925
  // We are going to remove v1 intellisense. no use to keep parity.
1040
- if (!document || !this.isIntellisenseV2()) {
926
+ if (!document) {
1041
927
  return Promise.resolve(null);
1042
928
  }
1043
929
  var script = this.parseDocumentV2(document);
@@ -1054,14 +940,6 @@ var KustoLanguageService = /** @class */ (function () {
1054
940
  location: location,
1055
941
  });
1056
942
  };
1057
- KustoLanguageService.prototype.getCommandInContextV1 = function (document, cursorOffset) {
1058
- this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
1059
- var command = this.getCurrentCommand(document, cursorOffset);
1060
- if (!command) {
1061
- return Promise.resolve(null);
1062
- }
1063
- return Promise.resolve(command.Text);
1064
- };
1065
943
  KustoLanguageService.prototype.getCommandInContextV2 = function (document, cursorOffset) {
1066
944
  if (!document) {
1067
945
  return Promise.resolve(null);
@@ -1081,9 +959,7 @@ var KustoLanguageService = /** @class */ (function () {
1081
959
  if (!document) {
1082
960
  return Promise.resolve([]);
1083
961
  }
1084
- return this.isIntellisenseV2()
1085
- ? this.getCommandsInDocumentV2(document)
1086
- : this.getCommandsInDocumentV1(document);
962
+ return this.getCommandsInDocumentV2(document);
1087
963
  };
1088
964
  KustoLanguageService.prototype.getCommandsInDocumentV1 = function (document) {
1089
965
  this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
@@ -1183,7 +1059,7 @@ var KustoLanguageService = /** @class */ (function () {
1183
1059
  });
1184
1060
  };
1185
1061
  KustoLanguageService.prototype.findDefinition = function (document, position) {
1186
- if (!document || !this.isIntellisenseV2()) {
1062
+ if (!document) {
1187
1063
  return Promise.resolve([]);
1188
1064
  }
1189
1065
  var script = this.parseDocumentV2(document);
@@ -1205,7 +1081,7 @@ var KustoLanguageService = /** @class */ (function () {
1205
1081
  return Promise.resolve([location]);
1206
1082
  };
1207
1083
  KustoLanguageService.prototype.findReferences = function (document, position) {
1208
- if (!document || !this.isIntellisenseV2()) {
1084
+ if (!document) {
1209
1085
  return Promise.resolve([]);
1210
1086
  }
1211
1087
  var script = this.parseDocumentV2(document);
@@ -1229,10 +1105,9 @@ var KustoLanguageService = /** @class */ (function () {
1229
1105
  return Promise.resolve(references);
1230
1106
  };
1231
1107
  KustoLanguageService.prototype.getQueryParams = function (document, cursorOffset) {
1232
- if (!document || !this.isIntellisenseV2()) {
1108
+ if (!document) {
1233
1109
  return Promise.resolve([]);
1234
1110
  }
1235
- var script = this.parseDocumentV2(document);
1236
1111
  var parsedAndAnalyzed = this.parseAndAnalyze(document, cursorOffset);
1237
1112
  var queryParamStatements = this.toArray(parsedAndAnalyzed.Syntax.GetDescendants(Kusto.Language.Syntax.QueryParametersStatement));
1238
1113
  if (!queryParamStatements || queryParamStatements.length == 0) {
@@ -1373,16 +1248,13 @@ var KustoLanguageService = /** @class */ (function () {
1373
1248
  return Promise.resolve(result);
1374
1249
  };
1375
1250
  KustoLanguageService.prototype.getGlobalParams = function (document) {
1376
- if (!this.isIntellisenseV2()) {
1377
- return Promise.resolve([]);
1378
- }
1379
1251
  var params = this.toArray(this._kustoJsSchemaV2.Parameters);
1380
1252
  var result = params.map(function (param) { return ({ name: param.Name, type: param.Type.Name }); });
1381
1253
  return Promise.resolve(result);
1382
1254
  };
1383
1255
  KustoLanguageService.prototype.doRename = function (document, position, newName) {
1384
1256
  var _a;
1385
- if (!document || !this.isIntellisenseV2()) {
1257
+ if (!document) {
1386
1258
  return Promise.resolve(undefined);
1387
1259
  }
1388
1260
  var script = this.parseDocumentV2(document);
@@ -1409,7 +1281,7 @@ var KustoLanguageService = /** @class */ (function () {
1409
1281
  return Promise.resolve(workspaceEdit);
1410
1282
  };
1411
1283
  KustoLanguageService.prototype.doHover = function (document, position) {
1412
- if (!document || !this.isIntellisenseV2()) {
1284
+ if (!document) {
1413
1285
  return Promise.resolve(undefined);
1414
1286
  }
1415
1287
  var script = this.parseDocumentV2(document);
@@ -1685,28 +1557,6 @@ var KustoLanguageService = /** @class */ (function () {
1685
1557
  var newRange = ls.Range.create(range.start, newEndPosition);
1686
1558
  return newRange;
1687
1559
  };
1688
- /**
1689
- * Maps numbers to strings, such that if a>b numerically, f(a)>f(b) lexicographically.
1690
- * 1 -> "a", 26 -> "z", 27 -> "za", 28 -> "zb", 52 -> "zz", 53 ->"zza"
1691
- * @param order - The number to be converted to a sorting-string. order should start at 1.
1692
- * @returns A string repenting the order.
1693
- */
1694
- KustoLanguageService.prototype.getSortText = function (order) {
1695
- if (order <= 0) {
1696
- throw new RangeError("order should be a number >= 1. instead got ".concat(order));
1697
- }
1698
- var sortText = '';
1699
- var numCharacters = 26; // "z" - "a" + 1;
1700
- var div = Math.floor(order / numCharacters);
1701
- for (var i = 0; i < div; ++i) {
1702
- sortText += 'z';
1703
- }
1704
- var reminder = order % numCharacters;
1705
- if (reminder > 0) {
1706
- sortText += String.fromCharCode(96 + reminder);
1707
- }
1708
- return sortText;
1709
- };
1710
1560
  /**
1711
1561
  * ParseTextV1 parses the given text with the given parse mode.
1712
1562
  * Additionally - it will make sure not to provide rules provider for non-engine clusters
@@ -1852,7 +1702,7 @@ var KustoLanguageService = /** @class */ (function () {
1852
1702
  return conversion || k2.ClassificationKind.PlainText;
1853
1703
  };
1854
1704
  KustoLanguageService.prototype.parseAndAnalyze = function (document, cursorOffset) {
1855
- if (!document || !this.isIntellisenseV2()) {
1705
+ if (!document) {
1856
1706
  return undefined;
1857
1707
  }
1858
1708
  var script = this.parseDocumentV2(document);
@@ -1895,7 +1745,6 @@ var KustoLanguageService = /** @class */ (function () {
1895
1745
  }());
1896
1746
  var languageService = new KustoLanguageService(KustoLanguageService.dummySchema, {
1897
1747
  includeControlCommands: true,
1898
- useIntellisenseV2: true,
1899
1748
  useSemanticColorization: true,
1900
1749
  completionOptions: { includeExtendedSyntax: false },
1901
1750
  });
@@ -3,7 +3,6 @@ export interface LanguageSettings {
3
3
  includeControlCommands?: boolean;
4
4
  newlineAfterPipe?: boolean;
5
5
  openSuggestionDialogAfterPreviousSuggestionAccepted?: boolean;
6
- useIntellisenseV2: boolean;
7
6
  useSemanticColorization?: boolean;
8
7
  useTokenColorization?: boolean;
9
8
  disabledCompletionItems?: string[];
@@ -53,7 +53,6 @@ var defaultLanguageSettings = {
53
53
  includeControlCommands: true,
54
54
  newlineAfterPipe: true,
55
55
  openSuggestionDialogAfterPreviousSuggestionAccepted: true,
56
- useIntellisenseV2: true,
57
56
  useSemanticColorization: true,
58
57
  useTokenColorization: false,
59
58
  enableHover: true,
@@ -181,7 +180,7 @@ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
181
180
  return;
182
181
  }
183
182
  event.selection;
184
- // OK so now we in a situation where we know a suggestion was selected and we want to trigger another one.
183
+ // OK so now we in a situation where we know a suggestion was selected, and we want to trigger another one.
185
184
  // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
186
185
  // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
187
186
  // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * monaco-kusto version: 10.0.21(1a66aa7041bf94687bc1e155f25c36653c952049)
3
+ * monaco-kusto version: 11.0.0(2cd16f8743253b5a0133f2ba4f53203e02c1673c)
4
4
  * Released under the MIT license
5
5
  * https://https://github.com/Azure/monaco-kusto/blob/master/README.md
6
6
  *-----------------------------------------------------------------------------*/