@kusto/monaco-kusto 4.0.6 → 4.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kusto/monaco-kusto",
3
- "version": "4.0.6",
3
+ "version": "4.1.3",
4
4
  "description": "CSL, KQL plugin for the Monaco Editor",
5
5
  "author": {
6
6
  "name": "Microsoft"
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@kusto/language-service": "2.0.0-beta.0",
58
- "@kusto/language-service-next": "0.0.51"
58
+ "@kusto/language-service-next": "0.0.52"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "monaco-editor": "^0.24.0"
@@ -6358,6 +6358,7 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
6358
6358
  kind: classification.Kind,
6359
6359
  }); });
6360
6360
  }
6361
+ ;
6361
6362
  /**
6362
6363
  * Kusto Language service translates the kusto object model (transpiled from C# by Bridge.Net)
6363
6364
  * to the vscode language server types, which are used by vscode language extensions.
@@ -6511,12 +6512,46 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
6511
6512
  _d);
6512
6513
  this._schemaCache = {};
6513
6514
  this._kustoJsSchema = KustoLanguageService.convertToKustoJsSchema(schema);
6514
- this._kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
6515
+ this.__kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
6515
6516
  this._schema = schema;
6517
+ this._clustersSetInGlobalState = new Set();
6518
+ this._nonEmptyDatabaseSetInGlobalState = new Set(); // used to remove clusters that are already in the global state
6516
6519
  this.configure(languageSettings);
6517
6520
  this._newlineAppendPipePolicy = new Kusto.Data.IntelliSense.ApplyPolicy();
6518
6521
  this._newlineAppendPipePolicy.Text = '\n| ';
6519
6522
  }
6523
+ KustoLanguageService.prototype.createDatabaseUniqueName = function (clusterName, databaseName) {
6524
+ return clusterName + "_" + databaseName;
6525
+ };
6526
+ Object.defineProperty(KustoLanguageService.prototype, "_kustoJsSchemaV2", {
6527
+ /**
6528
+ * A getter for __kustoJsSchemaV2
6529
+ */
6530
+ get: function () {
6531
+ return this.__kustoJsSchemaV2;
6532
+ },
6533
+ /**
6534
+ * A setter for _kustoJsSchemaV2. After a schema (global state) is set, create 2 sets of cluster and database names.
6535
+ */
6536
+ set: function (globalState) {
6537
+ this.__kustoJsSchemaV2 = globalState;
6538
+ this._clustersSetInGlobalState.clear();
6539
+ this._nonEmptyDatabaseSetInGlobalState.clear();
6540
+ // create 2 Sets with cluster names and database names based on the updated Global State.
6541
+ for (var i = 0; i < globalState.Clusters.Count; i++) {
6542
+ var clusterSymbol = this._kustoJsSchemaV2.Clusters.getItem(i);
6543
+ this._clustersSetInGlobalState.add(clusterSymbol.Name);
6544
+ for (var i2 = 0; i2 < clusterSymbol.Databases.Count; i2++) {
6545
+ var databaseSymbol = clusterSymbol.Databases.getItem(i2);
6546
+ if (databaseSymbol.Tables.Count > 0) { // only include database with tables
6547
+ this._nonEmptyDatabaseSetInGlobalState.add(this.createDatabaseUniqueName(clusterSymbol.Name, databaseSymbol.Name));
6548
+ }
6549
+ }
6550
+ }
6551
+ },
6552
+ enumerable: false,
6553
+ configurable: true
6554
+ });
6520
6555
  KustoLanguageService.prototype.configure = function (languageSettings) {
6521
6556
  this._languageSettings = languageSettings;
6522
6557
  // Since we're still reverting to V1 intellisense for control commands, we need to update the rules provider
@@ -6526,15 +6561,43 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
6526
6561
  KustoLanguageService.prototype.doComplete = function (document, position) {
6527
6562
  return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
6528
6563
  };
6564
+ /**
6565
+ * important: Only use during development to test Global State.
6566
+ * Prints clusters, databases and tables that are currently in the GlobalState.
6567
+ */
6568
+ KustoLanguageService.prototype.debugGlobalState = function (globals) {
6569
+ // iterate over clusters
6570
+ console.log("globals.Clusters.Count: " + globals.Clusters.Count);
6571
+ for (var i = 0; i < globals.Clusters.Count; i++) {
6572
+ var cluster = globals.Clusters.getItem(i);
6573
+ console.log("cluster: " + cluster.Name);
6574
+ // iterate over databases
6575
+ console.log("cluster.Databases.Count: " + cluster.Databases.Count);
6576
+ for (var i2 = 0; i2 < cluster.Databases.Count; i2++) {
6577
+ var database = cluster.Databases.getItem(i2);
6578
+ console.log("cluster.database: [" + cluster.Name + "].[" + database.Name + "]");
6579
+ // iterate over tables
6580
+ console.log("cluster.Databases.Tables.Count: " + database.Tables.Count);
6581
+ for (var i3 = 0; i3 < database.Tables.Count; i3++) {
6582
+ var table = database.Tables.getItem(i3);
6583
+ console.log("cluster.database.table: [" + cluster.Name + "].[" + database.Name + "].[" + table.Name + "]");
6584
+ }
6585
+ }
6586
+ }
6587
+ };
6529
6588
  KustoLanguageService.prototype.doCompleteV2 = function (document, position) {
6530
6589
  var _this = this;
6531
6590
  if (!document) {
6532
6591
  return Promise.resolve(ls.CompletionList.create([]));
6533
6592
  }
6534
6593
  var script = this.parseDocumentV2(document);
6594
+ // print cluster/database/tables from CodeScript.Globals
6595
+ // this.debugGlobalState(script.Globals);
6596
+ // get current command
6535
6597
  var cursorOffset = document.offsetAt(position);
6536
- var currentcommand = this.getCurrentCommandV2(script, cursorOffset);
6537
- var completionItems = currentcommand.Service.GetCompletionItems(cursorOffset);
6598
+ var currentCommand = script.GetBlockAtPosition(cursorOffset);
6599
+ // get completion items
6600
+ var completionItems = currentCommand.Service.GetCompletionItems(cursorOffset);
6538
6601
  var disabledItems = this.disabledCompletionItemsV2;
6539
6602
  if (this._languageSettings.disabledCompletionItems) {
6540
6603
  this._languageSettings.disabledCompletionItems.map(function (item) {
@@ -6701,6 +6764,62 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
6701
6764
  });
6702
6765
  });
6703
6766
  };
6767
+ KustoLanguageService.prototype.getClusterReferences = function (document, cursorOffset) {
6768
+ var _a;
6769
+ var script = this.parseDocumentV2(document);
6770
+ var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
6771
+ var clusterReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetClusterReferences();
6772
+ if (!clusterReferences) {
6773
+ return Promise.resolve([]);
6774
+ }
6775
+ var newClustersReferences = [];
6776
+ var newClustersReferencesSet = new Set(); // used to remove duplicates
6777
+ // Keep only unique clusters that aren't already exist in the Global State
6778
+ for (var i = 0; i < clusterReferences.Count; i++) {
6779
+ var clusterReference = clusterReferences.getItem(i);
6780
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterReference.Cluster);
6781
+ // ignore duplicates
6782
+ if (newClustersReferencesSet.has(clusterHostName)) {
6783
+ continue;
6784
+ }
6785
+ newClustersReferencesSet.add(clusterHostName);
6786
+ // ignore references that are already in the GlobalState.
6787
+ if (!this._clustersSetInGlobalState.has(clusterHostName)) {
6788
+ newClustersReferences.push({ clusterName: clusterHostName });
6789
+ }
6790
+ }
6791
+ return Promise.resolve(newClustersReferences);
6792
+ };
6793
+ KustoLanguageService.prototype.getDatabaseReferences = function (document, cursorOffset) {
6794
+ var _a;
6795
+ var script = this.parseDocumentV2(document);
6796
+ var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
6797
+ var databasesReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetDatabaseReferences();
6798
+ if (!databasesReferences) {
6799
+ return Promise.resolve([]);
6800
+ }
6801
+ var newDatabasesReferences = [];
6802
+ var newDatabasesReferencesSet = new Set();
6803
+ for (var i1 = 0; i1 < databasesReferences.Count; i1++) {
6804
+ var databaseReference = databasesReferences.getItem(i1);
6805
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(databaseReference.Cluster);
6806
+ // ignore duplicates
6807
+ var databaseReferenceUniqueId = this.createDatabaseUniqueName(clusterHostName, databaseReference.Database);
6808
+ if (newDatabasesReferencesSet.has(databaseReferenceUniqueId)) {
6809
+ continue;
6810
+ }
6811
+ newDatabasesReferencesSet.add(databaseReferenceUniqueId);
6812
+ // ignore references that are already in the GlobalState.
6813
+ var foundInGlobalState = this._nonEmptyDatabaseSetInGlobalState.has(databaseReferenceUniqueId);
6814
+ if (!foundInGlobalState) {
6815
+ newDatabasesReferences.push({
6816
+ databaseName: databaseReference.Database,
6817
+ clusterName: databaseReference.Cluster
6818
+ });
6819
+ }
6820
+ }
6821
+ return Promise.resolve(newDatabasesReferences);
6822
+ };
6704
6823
  KustoLanguageService.prototype.doValidation = function (document, changeIntervals) {
6705
6824
  var _this = this;
6706
6825
  // didn't implement validation for v1.
@@ -6841,6 +6960,43 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
6841
6960
  : false;
6842
6961
  });
6843
6962
  };
6963
+ KustoLanguageService.prototype.addClusterToSchema = function (document, clusterName, databaseNames) {
6964
+ var clusterNameOnly = Kusto.Language.KustoFacts.GetHostName(clusterName);
6965
+ var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterNameOnly);
6966
+ if (cluster) {
6967
+ // add databases that are not already in the cluster.
6968
+ databaseNames
6969
+ .filter(function (databaseName) { return !cluster.GetDatabase(databaseName); })
6970
+ .map(function (databaseName) {
6971
+ var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
6972
+ cluster = cluster.AddDatabase(symbol);
6973
+ });
6974
+ }
6975
+ if (!cluster) {
6976
+ var databaseSymbols = databaseNames
6977
+ .map(function (databaseName) {
6978
+ var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
6979
+ return symbol;
6980
+ });
6981
+ var databaseSymbolsList = KustoLanguageService.toBridgeList(databaseSymbols);
6982
+ cluster = new sym.ClusterSymbol.$ctor1(clusterNameOnly, databaseSymbolsList, false);
6983
+ }
6984
+ this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
6985
+ this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
6986
+ return Promise.resolve();
6987
+ };
6988
+ KustoLanguageService.prototype.addDatabaseToSchema = function (document, clusterName, databaseSchema) {
6989
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterName);
6990
+ var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterHostName);
6991
+ if (!cluster) {
6992
+ cluster = new sym.ClusterSymbol.$ctor1(clusterHostName, null, false);
6993
+ }
6994
+ var databaseSymbol = KustoLanguageService.convertToDatabaseSymbol(databaseSchema);
6995
+ cluster = cluster.AddOrUpdateDatabase(databaseSymbol);
6996
+ this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
6997
+ this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
6998
+ return Promise.resolve();
6999
+ };
6844
7000
  KustoLanguageService.prototype.setSchema = function (schema) {
6845
7001
  var _this = this;
6846
7002
  this._schema = schema;
@@ -7555,7 +7711,7 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
7555
7711
  var argumentType = new sym.TableSymbol.ctor(param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); }));
7556
7712
  return new sym.Parameter.$ctor2(param.name, argumentType);
7557
7713
  };
7558
- KustoLanguageService.convertToDatabaseSymbol = function (db, globalState, addFunctions) {
7714
+ KustoLanguageService.convertToDatabaseSymbol = function (db) {
7559
7715
  var createFunctionSymbol = function (fn) {
7560
7716
  var parameters = fn.inputParameters.map(function (param) {
7561
7717
  return KustoLanguageService.createParameter(param);
@@ -7612,7 +7768,7 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
7612
7768
  cachedDb.database.majorVersion < db.majorVersion ||
7613
7769
  (shouldIncludeFunctions && !cachedDb.includesFunctions)) {
7614
7770
  // only add functions for the database in context (it's very time consuming)
7615
- var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db, globalState, shouldIncludeFunctions);
7771
+ var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db);
7616
7772
  cached[db.name] = { database: db, symbol: databaseSymbol_1, includesFunctions: shouldIncludeFunctions };
7617
7773
  }
7618
7774
  var databaseSymbol = cached[db.name].symbol;
@@ -7874,6 +8030,22 @@ define('vs/language/kusto/kustoWorker',["require", "exports", "./languageService
7874
8030
  KustoWorker.prototype.setSchema = function (schema) {
7875
8031
  return this._languageService.setSchema(schema);
7876
8032
  };
8033
+ KustoWorker.prototype.addClusterToSchema = function (uri, clusterName, databasesNames) {
8034
+ var document = this._getTextDocument(uri);
8035
+ if (!document) {
8036
+ console.error("addClusterToSchema: document is " + document + ". uri is " + uri);
8037
+ return Promise.resolve();
8038
+ }
8039
+ return this._languageService.addClusterToSchema(document, clusterName, databasesNames);
8040
+ };
8041
+ KustoWorker.prototype.addDatabaseToSchema = function (uri, clusterName, databaseSchema) {
8042
+ var document = this._getTextDocument(uri);
8043
+ if (!document) {
8044
+ console.error("addDatabaseToSchema: document is " + document + ". uri is " + uri);
8045
+ return Promise.resolve();
8046
+ }
8047
+ return this._languageService.addDatabaseToSchema(document, clusterName, databaseSchema);
8048
+ };
7877
8049
  KustoWorker.prototype.setSchemaFromShowSchema = function (schema, clusterConnectionString, databaseInContextName) {
7878
8050
  return this._languageService.setSchemaFromShowSchema(schema, clusterConnectionString, databaseInContextName);
7879
8051
  };
@@ -8044,6 +8216,20 @@ define('vs/language/kusto/kustoWorker',["require", "exports", "./languageService
8044
8216
  KustoWorker.prototype.setParameters = function (parameters) {
8045
8217
  return this._languageService.setParameters(parameters);
8046
8218
  };
8219
+ KustoWorker.prototype.getClusterReferences = function (uri, cursorOffset) {
8220
+ var document = this._getTextDocument(uri);
8221
+ if (!document) {
8222
+ return Promise.resolve(null);
8223
+ }
8224
+ return this._languageService.getClusterReferences(document, cursorOffset);
8225
+ };
8226
+ KustoWorker.prototype.getDatabaseReferences = function (uri, cursorOffset) {
8227
+ var document = this._getTextDocument(uri);
8228
+ if (!document) {
8229
+ return Promise.resolve(null);
8230
+ }
8231
+ return this._languageService.getDatabaseReferences(document, cursorOffset);
8232
+ };
8047
8233
  KustoWorker.prototype._getTextDocument = function (uri) {
8048
8234
  var models = this._ctx.getMirrorModels();
8049
8235
  for (var _i = 0, models_1 = models; _i < models_1.length; _i++) {
@@ -11,6 +11,22 @@ var KustoWorker = /** @class */ (function () {
11
11
  KustoWorker.prototype.setSchema = function (schema) {
12
12
  return this._languageService.setSchema(schema);
13
13
  };
14
+ KustoWorker.prototype.addClusterToSchema = function (uri, clusterName, databasesNames) {
15
+ var document = this._getTextDocument(uri);
16
+ if (!document) {
17
+ console.error("addClusterToSchema: document is " + document + ". uri is " + uri);
18
+ return Promise.resolve();
19
+ }
20
+ return this._languageService.addClusterToSchema(document, clusterName, databasesNames);
21
+ };
22
+ KustoWorker.prototype.addDatabaseToSchema = function (uri, clusterName, databaseSchema) {
23
+ var document = this._getTextDocument(uri);
24
+ if (!document) {
25
+ console.error("addDatabaseToSchema: document is " + document + ". uri is " + uri);
26
+ return Promise.resolve();
27
+ }
28
+ return this._languageService.addDatabaseToSchema(document, clusterName, databaseSchema);
29
+ };
14
30
  KustoWorker.prototype.setSchemaFromShowSchema = function (schema, clusterConnectionString, databaseInContextName) {
15
31
  return this._languageService.setSchemaFromShowSchema(schema, clusterConnectionString, databaseInContextName);
16
32
  };
@@ -181,6 +197,20 @@ var KustoWorker = /** @class */ (function () {
181
197
  KustoWorker.prototype.setParameters = function (parameters) {
182
198
  return this._languageService.setParameters(parameters);
183
199
  };
200
+ KustoWorker.prototype.getClusterReferences = function (uri, cursorOffset) {
201
+ var document = this._getTextDocument(uri);
202
+ if (!document) {
203
+ return Promise.resolve(null);
204
+ }
205
+ return this._languageService.getClusterReferences(document, cursorOffset);
206
+ };
207
+ KustoWorker.prototype.getDatabaseReferences = function (uri, cursorOffset) {
208
+ var document = this._getTextDocument(uri);
209
+ if (!document) {
210
+ return Promise.resolve(null);
211
+ }
212
+ return this._languageService.getDatabaseReferences(document, cursorOffset);
213
+ };
184
214
  KustoWorker.prototype._getTextDocument = function (uri) {
185
215
  var models = this._ctx.getMirrorModels();
186
216
  for (var _i = 0, models_1 = models; _i < models_1.length; _i++) {
@@ -96,6 +96,7 @@ function toClassifiedRange(k2Classifications) {
96
96
  kind: classification.Kind,
97
97
  }); });
98
98
  }
99
+ ;
99
100
  /**
100
101
  * Kusto Language service translates the kusto object model (transpiled from C# by Bridge.Net)
101
102
  * to the vscode language server types, which are used by vscode language extensions.
@@ -249,12 +250,46 @@ var KustoLanguageService = /** @class */ (function () {
249
250
  _d);
250
251
  this._schemaCache = {};
251
252
  this._kustoJsSchema = KustoLanguageService.convertToKustoJsSchema(schema);
252
- this._kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
253
+ this.__kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
253
254
  this._schema = schema;
255
+ this._clustersSetInGlobalState = new Set();
256
+ this._nonEmptyDatabaseSetInGlobalState = new Set(); // used to remove clusters that are already in the global state
254
257
  this.configure(languageSettings);
255
258
  this._newlineAppendPipePolicy = new Kusto.Data.IntelliSense.ApplyPolicy();
256
259
  this._newlineAppendPipePolicy.Text = '\n| ';
257
260
  }
261
+ KustoLanguageService.prototype.createDatabaseUniqueName = function (clusterName, databaseName) {
262
+ return clusterName + "_" + databaseName;
263
+ };
264
+ Object.defineProperty(KustoLanguageService.prototype, "_kustoJsSchemaV2", {
265
+ /**
266
+ * A getter for __kustoJsSchemaV2
267
+ */
268
+ get: function () {
269
+ return this.__kustoJsSchemaV2;
270
+ },
271
+ /**
272
+ * A setter for _kustoJsSchemaV2. After a schema (global state) is set, create 2 sets of cluster and database names.
273
+ */
274
+ set: function (globalState) {
275
+ this.__kustoJsSchemaV2 = globalState;
276
+ this._clustersSetInGlobalState.clear();
277
+ this._nonEmptyDatabaseSetInGlobalState.clear();
278
+ // create 2 Sets with cluster names and database names based on the updated Global State.
279
+ for (var i = 0; i < globalState.Clusters.Count; i++) {
280
+ var clusterSymbol = this._kustoJsSchemaV2.Clusters.getItem(i);
281
+ this._clustersSetInGlobalState.add(clusterSymbol.Name);
282
+ for (var i2 = 0; i2 < clusterSymbol.Databases.Count; i2++) {
283
+ var databaseSymbol = clusterSymbol.Databases.getItem(i2);
284
+ if (databaseSymbol.Tables.Count > 0) { // only include database with tables
285
+ this._nonEmptyDatabaseSetInGlobalState.add(this.createDatabaseUniqueName(clusterSymbol.Name, databaseSymbol.Name));
286
+ }
287
+ }
288
+ }
289
+ },
290
+ enumerable: false,
291
+ configurable: true
292
+ });
258
293
  KustoLanguageService.prototype.configure = function (languageSettings) {
259
294
  this._languageSettings = languageSettings;
260
295
  // Since we're still reverting to V1 intellisense for control commands, we need to update the rules provider
@@ -264,15 +299,43 @@ var KustoLanguageService = /** @class */ (function () {
264
299
  KustoLanguageService.prototype.doComplete = function (document, position) {
265
300
  return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
266
301
  };
302
+ /**
303
+ * important: Only use during development to test Global State.
304
+ * Prints clusters, databases and tables that are currently in the GlobalState.
305
+ */
306
+ KustoLanguageService.prototype.debugGlobalState = function (globals) {
307
+ // iterate over clusters
308
+ console.log("globals.Clusters.Count: " + globals.Clusters.Count);
309
+ for (var i = 0; i < globals.Clusters.Count; i++) {
310
+ var cluster = globals.Clusters.getItem(i);
311
+ console.log("cluster: " + cluster.Name);
312
+ // iterate over databases
313
+ console.log("cluster.Databases.Count: " + cluster.Databases.Count);
314
+ for (var i2 = 0; i2 < cluster.Databases.Count; i2++) {
315
+ var database = cluster.Databases.getItem(i2);
316
+ console.log("cluster.database: [" + cluster.Name + "].[" + database.Name + "]");
317
+ // iterate over tables
318
+ console.log("cluster.Databases.Tables.Count: " + database.Tables.Count);
319
+ for (var i3 = 0; i3 < database.Tables.Count; i3++) {
320
+ var table = database.Tables.getItem(i3);
321
+ console.log("cluster.database.table: [" + cluster.Name + "].[" + database.Name + "].[" + table.Name + "]");
322
+ }
323
+ }
324
+ }
325
+ };
267
326
  KustoLanguageService.prototype.doCompleteV2 = function (document, position) {
268
327
  var _this = this;
269
328
  if (!document) {
270
329
  return Promise.resolve(ls.CompletionList.create([]));
271
330
  }
272
331
  var script = this.parseDocumentV2(document);
332
+ // print cluster/database/tables from CodeScript.Globals
333
+ // this.debugGlobalState(script.Globals);
334
+ // get current command
273
335
  var cursorOffset = document.offsetAt(position);
274
- var currentcommand = this.getCurrentCommandV2(script, cursorOffset);
275
- var completionItems = currentcommand.Service.GetCompletionItems(cursorOffset);
336
+ var currentCommand = script.GetBlockAtPosition(cursorOffset);
337
+ // get completion items
338
+ var completionItems = currentCommand.Service.GetCompletionItems(cursorOffset);
276
339
  var disabledItems = this.disabledCompletionItemsV2;
277
340
  if (this._languageSettings.disabledCompletionItems) {
278
341
  this._languageSettings.disabledCompletionItems.map(function (item) {
@@ -439,6 +502,62 @@ var KustoLanguageService = /** @class */ (function () {
439
502
  });
440
503
  });
441
504
  };
505
+ KustoLanguageService.prototype.getClusterReferences = function (document, cursorOffset) {
506
+ var _a;
507
+ var script = this.parseDocumentV2(document);
508
+ var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
509
+ var clusterReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetClusterReferences();
510
+ if (!clusterReferences) {
511
+ return Promise.resolve([]);
512
+ }
513
+ var newClustersReferences = [];
514
+ var newClustersReferencesSet = new Set(); // used to remove duplicates
515
+ // Keep only unique clusters that aren't already exist in the Global State
516
+ for (var i = 0; i < clusterReferences.Count; i++) {
517
+ var clusterReference = clusterReferences.getItem(i);
518
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterReference.Cluster);
519
+ // ignore duplicates
520
+ if (newClustersReferencesSet.has(clusterHostName)) {
521
+ continue;
522
+ }
523
+ newClustersReferencesSet.add(clusterHostName);
524
+ // ignore references that are already in the GlobalState.
525
+ if (!this._clustersSetInGlobalState.has(clusterHostName)) {
526
+ newClustersReferences.push({ clusterName: clusterHostName });
527
+ }
528
+ }
529
+ return Promise.resolve(newClustersReferences);
530
+ };
531
+ KustoLanguageService.prototype.getDatabaseReferences = function (document, cursorOffset) {
532
+ var _a;
533
+ var script = this.parseDocumentV2(document);
534
+ var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
535
+ var databasesReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetDatabaseReferences();
536
+ if (!databasesReferences) {
537
+ return Promise.resolve([]);
538
+ }
539
+ var newDatabasesReferences = [];
540
+ var newDatabasesReferencesSet = new Set();
541
+ for (var i1 = 0; i1 < databasesReferences.Count; i1++) {
542
+ var databaseReference = databasesReferences.getItem(i1);
543
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(databaseReference.Cluster);
544
+ // ignore duplicates
545
+ var databaseReferenceUniqueId = this.createDatabaseUniqueName(clusterHostName, databaseReference.Database);
546
+ if (newDatabasesReferencesSet.has(databaseReferenceUniqueId)) {
547
+ continue;
548
+ }
549
+ newDatabasesReferencesSet.add(databaseReferenceUniqueId);
550
+ // ignore references that are already in the GlobalState.
551
+ var foundInGlobalState = this._nonEmptyDatabaseSetInGlobalState.has(databaseReferenceUniqueId);
552
+ if (!foundInGlobalState) {
553
+ newDatabasesReferences.push({
554
+ databaseName: databaseReference.Database,
555
+ clusterName: databaseReference.Cluster
556
+ });
557
+ }
558
+ }
559
+ return Promise.resolve(newDatabasesReferences);
560
+ };
442
561
  KustoLanguageService.prototype.doValidation = function (document, changeIntervals) {
443
562
  var _this = this;
444
563
  // didn't implement validation for v1.
@@ -579,6 +698,43 @@ var KustoLanguageService = /** @class */ (function () {
579
698
  : false;
580
699
  });
581
700
  };
701
+ KustoLanguageService.prototype.addClusterToSchema = function (document, clusterName, databaseNames) {
702
+ var clusterNameOnly = Kusto.Language.KustoFacts.GetHostName(clusterName);
703
+ var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterNameOnly);
704
+ if (cluster) {
705
+ // add databases that are not already in the cluster.
706
+ databaseNames
707
+ .filter(function (databaseName) { return !cluster.GetDatabase(databaseName); })
708
+ .map(function (databaseName) {
709
+ var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
710
+ cluster = cluster.AddDatabase(symbol);
711
+ });
712
+ }
713
+ if (!cluster) {
714
+ var databaseSymbols = databaseNames
715
+ .map(function (databaseName) {
716
+ var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
717
+ return symbol;
718
+ });
719
+ var databaseSymbolsList = KustoLanguageService.toBridgeList(databaseSymbols);
720
+ cluster = new sym.ClusterSymbol.$ctor1(clusterNameOnly, databaseSymbolsList, false);
721
+ }
722
+ this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
723
+ this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
724
+ return Promise.resolve();
725
+ };
726
+ KustoLanguageService.prototype.addDatabaseToSchema = function (document, clusterName, databaseSchema) {
727
+ var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterName);
728
+ var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterHostName);
729
+ if (!cluster) {
730
+ cluster = new sym.ClusterSymbol.$ctor1(clusterHostName, null, false);
731
+ }
732
+ var databaseSymbol = KustoLanguageService.convertToDatabaseSymbol(databaseSchema);
733
+ cluster = cluster.AddOrUpdateDatabase(databaseSymbol);
734
+ this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
735
+ this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
736
+ return Promise.resolve();
737
+ };
582
738
  KustoLanguageService.prototype.setSchema = function (schema) {
583
739
  var _this = this;
584
740
  this._schema = schema;
@@ -1293,7 +1449,7 @@ var KustoLanguageService = /** @class */ (function () {
1293
1449
  var argumentType = new sym.TableSymbol.ctor(param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); }));
1294
1450
  return new sym.Parameter.$ctor2(param.name, argumentType);
1295
1451
  };
1296
- KustoLanguageService.convertToDatabaseSymbol = function (db, globalState, addFunctions) {
1452
+ KustoLanguageService.convertToDatabaseSymbol = function (db) {
1297
1453
  var createFunctionSymbol = function (fn) {
1298
1454
  var parameters = fn.inputParameters.map(function (param) {
1299
1455
  return KustoLanguageService.createParameter(param);
@@ -1350,7 +1506,7 @@ var KustoLanguageService = /** @class */ (function () {
1350
1506
  cachedDb.database.majorVersion < db.majorVersion ||
1351
1507
  (shouldIncludeFunctions && !cachedDb.includesFunctions)) {
1352
1508
  // only add functions for the database in context (it's very time consuming)
1353
- var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db, globalState, shouldIncludeFunctions);
1509
+ var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db);
1354
1510
  cached[db.name] = { database: db, symbol: databaseSymbol_1, includesFunctions: shouldIncludeFunctions };
1355
1511
  }
1356
1512
  var databaseSymbol = cached[db.name].symbol;
@@ -119,6 +119,50 @@ declare module monaco.languages.kusto {
119
119
  doCurrentCommandFormat(uri: string, caretPosition: ls.Position): Promise<ls.TextEdit[]>;
120
120
  doValidation(uri: string, intervals: { start: number; end: number }[]): Promise<ls.Diagnostic[]>;
121
121
  setParameters(parameters: ScalarParameter[]): void;
122
+ /**
123
+ * Get all the database references from the current command.
124
+ * If database's schema is already cached in previous calls to setSchema or addDatabaseToSchema it will not be returned.
125
+ * This method should be used to get all the cross-databases in a command, then schema for the database should be fetched and added with addDatabaseToSchema.
126
+ * @example
127
+ * If the current command includes: cluster('help').database('Samples')
128
+ * getDatabaseReferences will return [{ clusterName: 'help', databaseName 'Samples' }]
129
+ */
130
+ getDatabaseReferences(uri: string, cursorOffset: number): Promise<DatabaseReference[]>;
131
+ /**
132
+ * Get all the cluster references from the current command.
133
+ * If cluster's schema is already cached it will not be returned.
134
+ * This method should be used to get all the cross-clusters in a command, then schema for the cluster should be fetched and added with addClusterToSchema.
135
+ * cluster name is returned exactly as written in the KQL `cluster(<cluster name>)` function.
136
+ * @example
137
+ * If the current command includes: cluster('help')
138
+ * it returns [{ clusterName: 'help' }]
139
+ * @example
140
+ * If the current command includes: cluster('https://demo11.westus.kusto.windows.net')
141
+ * getClusterReferences will return [{ clusterName: 'https://demo11.westus.kusto.windows.net' }]
142
+ */
143
+ getClusterReferences(uri: string, cursorOffset: number): Promise<ClusterReference[]>;
144
+ /**
145
+ * Adds a database's scheme. Useful with getDatabaseReferences to load schema for cross-cluster commands.
146
+ * @param clusterName the name of the cluster as returned from getDatabaseReferences/getClusterReferences.
147
+ * @example
148
+ * - User enters cluster('help').database('Samples')
149
+ * - hosting app calls getDatabaseReferences which returns [{ clusterName: 'help', databaseName: 'Samples' }].
150
+ * - hosting app fetches the database Schema from https://help.kusto.windows.net
151
+ * - hosting app calls 'addDatabaseToSchema' with the database's schema.
152
+ * - now, when user types cluster('help').database('Samples') then the auto complete list will show all the tables.
153
+ */
154
+ addDatabaseToSchema(uri: string, clusterName: string, databaseSchema: Database): Promise<void>;
155
+ /**
156
+ * Adds a cluster's databases to the schema. Useful when used with getClusterReferences in cross-cluster commands.
157
+ * @param clusterName the name of the cluster as returned in getClusterReferences.
158
+ * @example
159
+ * - User enters cluster('help')
160
+ * - hosting app calls getClusterReferences which returns [{ clusterName: 'help' }].
161
+ * - hosting app fetches the list of databases from https://help.kusto.windows.net
162
+ * - hosting app calls addClusterToSchema with the list of databases.
163
+ * - now, when user type `cluster('help').database(` then the auto complete list will show all the databases.
164
+ */
165
+ addClusterToSchema(uri: string, clusterName: string, databasesNames: string[]): Promise<void>;
122
166
  }
123
167
 
124
168
  /**
@@ -234,6 +278,15 @@ declare module monaco.languages.kusto {
234
278
  location: { startOffset: number; endOffset: number };
235
279
  }
236
280
 
281
+ export interface DatabaseReference {
282
+ databaseName: string;
283
+ clusterName: string;
284
+ };
285
+
286
+ export interface ClusterReference {
287
+ clusterName: string;
288
+ }
289
+
237
290
  export type RenderOptionKeys = keyof RenderOptions;
238
291
 
239
292
  export type OnDidProvideCompletionItems = (list: ls.CompletionList) => Promise<ls.CompletionList>;