@kusto/monaco-kusto 4.0.3 → 4.1.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.
- package/package.json +2 -2
- package/release/dev/kustoWorker.js +210 -22
- package/release/esm/kustoWorker.js +24 -0
- package/release/esm/languageService/kustoLanguageService.js +186 -22
- package/release/esm/monaco.d.ts +36 -0
- package/release/min/Kusto.Language.Bridge.min.js +1 -1
- package/release/min/kustoMode.js +1 -1
- package/release/min/kustoWorker.js +3 -3
- package/release/min/monaco.contribution.js +1 -1
- package/release/min/monaco.d.ts +36 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kusto/monaco-kusto",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
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.
|
|
58
|
+
"@kusto/language-service-next": "0.0.51"
|
|
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,44 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
6511
6512
|
_d);
|
|
6512
6513
|
this._schemaCache = {};
|
|
6513
6514
|
this._kustoJsSchema = KustoLanguageService.convertToKustoJsSchema(schema);
|
|
6514
|
-
this.
|
|
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
|
+
// create 2 Sets with cluster names and database names based on the updated Global State.
|
|
6539
|
+
for (var i = 0; i < globalState.Clusters.Count; i++) {
|
|
6540
|
+
var clusterSymbol = this._kustoJsSchemaV2.Clusters.getItem(i);
|
|
6541
|
+
this._clustersSetInGlobalState.add(clusterSymbol.Name);
|
|
6542
|
+
for (var i2 = 0; i2 < clusterSymbol.Databases.Count; i2++) {
|
|
6543
|
+
var databaseSymbol = clusterSymbol.Databases.getItem(i2);
|
|
6544
|
+
if (databaseSymbol.Tables.Count > 0) { // only include database with tables
|
|
6545
|
+
this._nonEmptyDatabaseSetInGlobalState.add(this.createDatabaseUniqueName(clusterSymbol.Name, databaseSymbol.Name));
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
}
|
|
6549
|
+
},
|
|
6550
|
+
enumerable: false,
|
|
6551
|
+
configurable: true
|
|
6552
|
+
});
|
|
6520
6553
|
KustoLanguageService.prototype.configure = function (languageSettings) {
|
|
6521
6554
|
this._languageSettings = languageSettings;
|
|
6522
6555
|
// Since we're still reverting to V1 intellisense for control commands, we need to update the rules provider
|
|
@@ -6526,15 +6559,43 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
6526
6559
|
KustoLanguageService.prototype.doComplete = function (document, position) {
|
|
6527
6560
|
return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
|
|
6528
6561
|
};
|
|
6562
|
+
/**
|
|
6563
|
+
* important: Only use during development to test Global State.
|
|
6564
|
+
* Prints clusters, databases and tables that are currently in the GlobalState.
|
|
6565
|
+
*/
|
|
6566
|
+
KustoLanguageService.prototype.debugGlobalState = function (globals) {
|
|
6567
|
+
// iterate over clusters
|
|
6568
|
+
console.log("globals.Clusters.Count: " + globals.Clusters.Count);
|
|
6569
|
+
for (var i = 0; i < globals.Clusters.Count; i++) {
|
|
6570
|
+
var cluster = globals.Clusters.getItem(i);
|
|
6571
|
+
console.log("cluster: " + cluster.Name);
|
|
6572
|
+
// iterate over databases
|
|
6573
|
+
console.log("cluster.Databases.Count: " + cluster.Databases.Count);
|
|
6574
|
+
for (var i2 = 0; i2 < cluster.Databases.Count; i2++) {
|
|
6575
|
+
var database = cluster.Databases.getItem(i2);
|
|
6576
|
+
console.log("cluster.database: [" + cluster.Name + "].[" + database.Name + "]");
|
|
6577
|
+
// iterate over tables
|
|
6578
|
+
console.log("cluster.Databases.Tables.Count: " + database.Tables.Count);
|
|
6579
|
+
for (var i3 = 0; i3 < database.Tables.Count; i3++) {
|
|
6580
|
+
var table = database.Tables.getItem(i3);
|
|
6581
|
+
console.log("cluster.database.table: [" + cluster.Name + "].[" + database.Name + "].[" + table.Name + "]");
|
|
6582
|
+
}
|
|
6583
|
+
}
|
|
6584
|
+
}
|
|
6585
|
+
};
|
|
6529
6586
|
KustoLanguageService.prototype.doCompleteV2 = function (document, position) {
|
|
6530
6587
|
var _this = this;
|
|
6531
6588
|
if (!document) {
|
|
6532
6589
|
return Promise.resolve(ls.CompletionList.create([]));
|
|
6533
6590
|
}
|
|
6534
6591
|
var script = this.parseDocumentV2(document);
|
|
6592
|
+
// print cluster/database/tables from CodeScript.Globals
|
|
6593
|
+
// this.debugGlobalState(script.Globals);
|
|
6594
|
+
// get current command
|
|
6535
6595
|
var cursorOffset = document.offsetAt(position);
|
|
6536
|
-
var
|
|
6537
|
-
|
|
6596
|
+
var currentCommand = script.GetBlockAtPosition(cursorOffset);
|
|
6597
|
+
// get completion items
|
|
6598
|
+
var completionItems = currentCommand.Service.GetCompletionItems(cursorOffset);
|
|
6538
6599
|
var disabledItems = this.disabledCompletionItemsV2;
|
|
6539
6600
|
if (this._languageSettings.disabledCompletionItems) {
|
|
6540
6601
|
this._languageSettings.disabledCompletionItems.map(function (item) {
|
|
@@ -6701,6 +6762,61 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
6701
6762
|
});
|
|
6702
6763
|
});
|
|
6703
6764
|
};
|
|
6765
|
+
KustoLanguageService.prototype.getClusterReferences = function (document, cursorOffset) {
|
|
6766
|
+
var _a;
|
|
6767
|
+
var script = this.parseDocumentV2(document);
|
|
6768
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
6769
|
+
var clusterReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetClusterReferences();
|
|
6770
|
+
if (!clusterReferences) {
|
|
6771
|
+
return Promise.resolve([]);
|
|
6772
|
+
}
|
|
6773
|
+
var newClustersReferences = [];
|
|
6774
|
+
var newClustersReferencesSet = new Set(); // used to remove duplicates
|
|
6775
|
+
// Keep only unique clusters that aren't already exist in the Global State
|
|
6776
|
+
for (var i = 0; i < clusterReferences.Count; i++) {
|
|
6777
|
+
var clusterReference = clusterReferences.getItem(i);
|
|
6778
|
+
var clusterHostName = clusterReference.Cluster;
|
|
6779
|
+
// ignore duplicates
|
|
6780
|
+
if (newClustersReferencesSet.has(clusterHostName)) {
|
|
6781
|
+
continue;
|
|
6782
|
+
}
|
|
6783
|
+
newClustersReferencesSet.add(clusterHostName);
|
|
6784
|
+
// ignore references that are already in the GlobalState.
|
|
6785
|
+
if (!this._clustersSetInGlobalState.has(clusterHostName.toLowerCase())) {
|
|
6786
|
+
newClustersReferences.push({ clusterName: clusterHostName });
|
|
6787
|
+
}
|
|
6788
|
+
}
|
|
6789
|
+
return Promise.resolve(newClustersReferences);
|
|
6790
|
+
};
|
|
6791
|
+
KustoLanguageService.prototype.getDatabaseReferences = function (document, cursorOffset) {
|
|
6792
|
+
var _a;
|
|
6793
|
+
var script = this.parseDocumentV2(document);
|
|
6794
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
6795
|
+
var databasesReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetDatabaseReferences();
|
|
6796
|
+
if (!databasesReferences) {
|
|
6797
|
+
return Promise.resolve([]);
|
|
6798
|
+
}
|
|
6799
|
+
var newDatabasesReferences = [];
|
|
6800
|
+
var newDatabasesReferencesSet = new Set();
|
|
6801
|
+
for (var i1 = 0; i1 < databasesReferences.Count; i1++) {
|
|
6802
|
+
var databaseReference = databasesReferences.getItem(i1);
|
|
6803
|
+
// ignore duplicates
|
|
6804
|
+
var databaseReferenceUniqueId = this.createDatabaseUniqueName(databaseReference.Cluster, databaseReference.Database);
|
|
6805
|
+
if (newDatabasesReferencesSet.has(databaseReferenceUniqueId)) {
|
|
6806
|
+
continue;
|
|
6807
|
+
}
|
|
6808
|
+
newDatabasesReferencesSet.add(databaseReferenceUniqueId);
|
|
6809
|
+
// ignore references that are already in the GlobalState.
|
|
6810
|
+
var foundInGlobalState = this._nonEmptyDatabaseSetInGlobalState.has(databaseReferenceUniqueId);
|
|
6811
|
+
if (!foundInGlobalState) {
|
|
6812
|
+
newDatabasesReferences.push({
|
|
6813
|
+
databaseName: databaseReference.Database,
|
|
6814
|
+
clusterName: databaseReference.Cluster
|
|
6815
|
+
});
|
|
6816
|
+
}
|
|
6817
|
+
}
|
|
6818
|
+
return Promise.resolve(newDatabasesReferences);
|
|
6819
|
+
};
|
|
6704
6820
|
KustoLanguageService.prototype.doValidation = function (document, changeIntervals) {
|
|
6705
6821
|
var _this = this;
|
|
6706
6822
|
// didn't implement validation for v1.
|
|
@@ -6841,6 +6957,46 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
6841
6957
|
: false;
|
|
6842
6958
|
});
|
|
6843
6959
|
};
|
|
6960
|
+
KustoLanguageService.prototype.addClusterToSchema = function (document, clusterName, databaseNames) {
|
|
6961
|
+
var clusterNameOnly = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
6962
|
+
var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterNameOnly);
|
|
6963
|
+
if (cluster) {
|
|
6964
|
+
// add databases that are not already in the cluster.
|
|
6965
|
+
databaseNames
|
|
6966
|
+
.filter(function (databaseName) { return !cluster.GetDatabase(databaseName); })
|
|
6967
|
+
.map(function (databaseName) {
|
|
6968
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
6969
|
+
cluster = cluster.AddDatabase(symbol);
|
|
6970
|
+
});
|
|
6971
|
+
}
|
|
6972
|
+
if (!cluster) {
|
|
6973
|
+
var databaseSymbols = databaseNames
|
|
6974
|
+
.map(function (databaseName) {
|
|
6975
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
6976
|
+
return symbol;
|
|
6977
|
+
});
|
|
6978
|
+
var databaseSymbolsList = KustoLanguageService.toBridgeList(databaseSymbols);
|
|
6979
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterNameOnly, databaseSymbolsList, false);
|
|
6980
|
+
}
|
|
6981
|
+
this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
6982
|
+
this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
|
|
6983
|
+
return Promise.resolve();
|
|
6984
|
+
};
|
|
6985
|
+
KustoLanguageService.prototype.addDatabaseToSchema = function (document, clusterName, databaseSchema) {
|
|
6986
|
+
var _this = this;
|
|
6987
|
+
return new Promise(function (resolve) {
|
|
6988
|
+
var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
6989
|
+
var cluster = _this._kustoJsSchemaV2.GetCluster$1(clusterHostName);
|
|
6990
|
+
if (!cluster) {
|
|
6991
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterHostName, null, false);
|
|
6992
|
+
}
|
|
6993
|
+
var databaseSymbol = KustoLanguageService.convertToDatabaseSymbol(databaseSchema);
|
|
6994
|
+
cluster = cluster.AddOrUpdateDatabase(databaseSymbol);
|
|
6995
|
+
_this._kustoJsSchemaV2 = _this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
6996
|
+
_this._script = k2.CodeScript.From$1(document.getText(), _this._kustoJsSchemaV2);
|
|
6997
|
+
resolve();
|
|
6998
|
+
});
|
|
6999
|
+
};
|
|
6844
7000
|
KustoLanguageService.prototype.setSchema = function (schema) {
|
|
6845
7001
|
var _this = this;
|
|
6846
7002
|
this._schema = schema;
|
|
@@ -6889,29 +7045,37 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
6889
7045
|
var databases = Object.keys(schema.Databases)
|
|
6890
7046
|
.map(function (key) { return schema.Databases[key]; })
|
|
6891
7047
|
.map(function (_a) {
|
|
6892
|
-
var Name = _a.Name, Tables = _a.Tables, Functions = _a.Functions, MinorVersion = _a.MinorVersion, MajorVersion = _a.MajorVersion;
|
|
7048
|
+
var Name = _a.Name, Tables = _a.Tables, ExternalTables = _a.ExternalTables, MaterializedViews = _a.MaterializedViews, Functions = _a.Functions, MinorVersion = _a.MinorVersion, MajorVersion = _a.MajorVersion;
|
|
6893
7049
|
return ({
|
|
6894
7050
|
name: Name,
|
|
6895
7051
|
minorVersion: MinorVersion,
|
|
6896
7052
|
majorVersion: MajorVersion,
|
|
6897
|
-
tables:
|
|
6898
|
-
.
|
|
7053
|
+
tables: [].concat.apply([], [[Tables, 'Table'], [MaterializedViews, 'MaterializedView'], [ExternalTables, 'ExternalTable']]
|
|
7054
|
+
.filter(function (_a) {
|
|
7055
|
+
var tableContainer = _a[0];
|
|
7056
|
+
return tableContainer;
|
|
7057
|
+
})
|
|
6899
7058
|
.map(function (_a) {
|
|
6900
|
-
var
|
|
6901
|
-
return
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
7059
|
+
var tableContainer = _a[0], tableEntity = _a[1];
|
|
7060
|
+
return Object
|
|
7061
|
+
.values(tableContainer)
|
|
7062
|
+
.map(function (_a) {
|
|
7063
|
+
var Name = _a.Name, OrderedColumns = _a.OrderedColumns, DocString = _a.DocString;
|
|
7064
|
+
return ({
|
|
7065
|
+
name: Name,
|
|
7066
|
+
docstring: DocString,
|
|
7067
|
+
entityType: tableEntity,
|
|
7068
|
+
columns: OrderedColumns.map(function (_a) {
|
|
7069
|
+
var Name = _a.Name, Type = _a.Type, DocString = _a.DocString, CslType = _a.CslType;
|
|
7070
|
+
return ({
|
|
7071
|
+
name: Name,
|
|
7072
|
+
type: CslType,
|
|
7073
|
+
docstring: DocString,
|
|
7074
|
+
});
|
|
7075
|
+
}),
|
|
7076
|
+
});
|
|
6913
7077
|
});
|
|
6914
|
-
}),
|
|
7078
|
+
})),
|
|
6915
7079
|
functions: Object.keys(Functions)
|
|
6916
7080
|
.map(function (key) { return Functions[key]; })
|
|
6917
7081
|
.map(function (_a) {
|
|
@@ -7547,7 +7711,7 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
7547
7711
|
var argumentType = new sym.TableSymbol.ctor(param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); }));
|
|
7548
7712
|
return new sym.Parameter.$ctor2(param.name, argumentType);
|
|
7549
7713
|
};
|
|
7550
|
-
KustoLanguageService.convertToDatabaseSymbol = function (db
|
|
7714
|
+
KustoLanguageService.convertToDatabaseSymbol = function (db) {
|
|
7551
7715
|
var createFunctionSymbol = function (fn) {
|
|
7552
7716
|
var parameters = fn.inputParameters.map(function (param) {
|
|
7553
7717
|
return KustoLanguageService.createParameter(param);
|
|
@@ -7604,7 +7768,7 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
7604
7768
|
cachedDb.database.majorVersion < db.majorVersion ||
|
|
7605
7769
|
(shouldIncludeFunctions && !cachedDb.includesFunctions)) {
|
|
7606
7770
|
// only add functions for the database in context (it's very time consuming)
|
|
7607
|
-
var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db
|
|
7771
|
+
var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db);
|
|
7608
7772
|
cached[db.name] = { database: db, symbol: databaseSymbol_1, includesFunctions: shouldIncludeFunctions };
|
|
7609
7773
|
}
|
|
7610
7774
|
var databaseSymbol = cached[db.name].symbol;
|
|
@@ -7866,6 +8030,22 @@ define('vs/language/kusto/kustoWorker',["require", "exports", "./languageService
|
|
|
7866
8030
|
KustoWorker.prototype.setSchema = function (schema) {
|
|
7867
8031
|
return this._languageService.setSchema(schema);
|
|
7868
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 null;
|
|
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 null;
|
|
8046
|
+
}
|
|
8047
|
+
return this._languageService.addDatabaseToSchema(document, clusterName, databaseSchema);
|
|
8048
|
+
};
|
|
7869
8049
|
KustoWorker.prototype.setSchemaFromShowSchema = function (schema, clusterConnectionString, databaseInContextName) {
|
|
7870
8050
|
return this._languageService.setSchemaFromShowSchema(schema, clusterConnectionString, databaseInContextName);
|
|
7871
8051
|
};
|
|
@@ -8036,6 +8216,14 @@ define('vs/language/kusto/kustoWorker',["require", "exports", "./languageService
|
|
|
8036
8216
|
KustoWorker.prototype.setParameters = function (parameters) {
|
|
8037
8217
|
return this._languageService.setParameters(parameters);
|
|
8038
8218
|
};
|
|
8219
|
+
KustoWorker.prototype.getClusterReferences = function (uri, cursorOffset) {
|
|
8220
|
+
var document = this._getTextDocument(uri);
|
|
8221
|
+
return this._languageService.getClusterReferences(document, cursorOffset);
|
|
8222
|
+
};
|
|
8223
|
+
KustoWorker.prototype.getDatabaseReferences = function (uri, cursorOffset) {
|
|
8224
|
+
var document = this._getTextDocument(uri);
|
|
8225
|
+
return this._languageService.getDatabaseReferences(document, cursorOffset);
|
|
8226
|
+
};
|
|
8039
8227
|
KustoWorker.prototype._getTextDocument = function (uri) {
|
|
8040
8228
|
var models = this._ctx.getMirrorModels();
|
|
8041
8229
|
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 null;
|
|
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 null;
|
|
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,14 @@ 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
|
+
return this._languageService.getClusterReferences(document, cursorOffset);
|
|
203
|
+
};
|
|
204
|
+
KustoWorker.prototype.getDatabaseReferences = function (uri, cursorOffset) {
|
|
205
|
+
var document = this._getTextDocument(uri);
|
|
206
|
+
return this._languageService.getDatabaseReferences(document, cursorOffset);
|
|
207
|
+
};
|
|
184
208
|
KustoWorker.prototype._getTextDocument = function (uri) {
|
|
185
209
|
var models = this._ctx.getMirrorModels();
|
|
186
210
|
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,44 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
249
250
|
_d);
|
|
250
251
|
this._schemaCache = {};
|
|
251
252
|
this._kustoJsSchema = KustoLanguageService.convertToKustoJsSchema(schema);
|
|
252
|
-
this.
|
|
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
|
+
// create 2 Sets with cluster names and database names based on the updated Global State.
|
|
277
|
+
for (var i = 0; i < globalState.Clusters.Count; i++) {
|
|
278
|
+
var clusterSymbol = this._kustoJsSchemaV2.Clusters.getItem(i);
|
|
279
|
+
this._clustersSetInGlobalState.add(clusterSymbol.Name);
|
|
280
|
+
for (var i2 = 0; i2 < clusterSymbol.Databases.Count; i2++) {
|
|
281
|
+
var databaseSymbol = clusterSymbol.Databases.getItem(i2);
|
|
282
|
+
if (databaseSymbol.Tables.Count > 0) { // only include database with tables
|
|
283
|
+
this._nonEmptyDatabaseSetInGlobalState.add(this.createDatabaseUniqueName(clusterSymbol.Name, databaseSymbol.Name));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
enumerable: false,
|
|
289
|
+
configurable: true
|
|
290
|
+
});
|
|
258
291
|
KustoLanguageService.prototype.configure = function (languageSettings) {
|
|
259
292
|
this._languageSettings = languageSettings;
|
|
260
293
|
// Since we're still reverting to V1 intellisense for control commands, we need to update the rules provider
|
|
@@ -264,15 +297,43 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
264
297
|
KustoLanguageService.prototype.doComplete = function (document, position) {
|
|
265
298
|
return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
|
|
266
299
|
};
|
|
300
|
+
/**
|
|
301
|
+
* important: Only use during development to test Global State.
|
|
302
|
+
* Prints clusters, databases and tables that are currently in the GlobalState.
|
|
303
|
+
*/
|
|
304
|
+
KustoLanguageService.prototype.debugGlobalState = function (globals) {
|
|
305
|
+
// iterate over clusters
|
|
306
|
+
console.log("globals.Clusters.Count: " + globals.Clusters.Count);
|
|
307
|
+
for (var i = 0; i < globals.Clusters.Count; i++) {
|
|
308
|
+
var cluster = globals.Clusters.getItem(i);
|
|
309
|
+
console.log("cluster: " + cluster.Name);
|
|
310
|
+
// iterate over databases
|
|
311
|
+
console.log("cluster.Databases.Count: " + cluster.Databases.Count);
|
|
312
|
+
for (var i2 = 0; i2 < cluster.Databases.Count; i2++) {
|
|
313
|
+
var database = cluster.Databases.getItem(i2);
|
|
314
|
+
console.log("cluster.database: [" + cluster.Name + "].[" + database.Name + "]");
|
|
315
|
+
// iterate over tables
|
|
316
|
+
console.log("cluster.Databases.Tables.Count: " + database.Tables.Count);
|
|
317
|
+
for (var i3 = 0; i3 < database.Tables.Count; i3++) {
|
|
318
|
+
var table = database.Tables.getItem(i3);
|
|
319
|
+
console.log("cluster.database.table: [" + cluster.Name + "].[" + database.Name + "].[" + table.Name + "]");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
267
324
|
KustoLanguageService.prototype.doCompleteV2 = function (document, position) {
|
|
268
325
|
var _this = this;
|
|
269
326
|
if (!document) {
|
|
270
327
|
return Promise.resolve(ls.CompletionList.create([]));
|
|
271
328
|
}
|
|
272
329
|
var script = this.parseDocumentV2(document);
|
|
330
|
+
// print cluster/database/tables from CodeScript.Globals
|
|
331
|
+
// this.debugGlobalState(script.Globals);
|
|
332
|
+
// get current command
|
|
273
333
|
var cursorOffset = document.offsetAt(position);
|
|
274
|
-
var
|
|
275
|
-
|
|
334
|
+
var currentCommand = script.GetBlockAtPosition(cursorOffset);
|
|
335
|
+
// get completion items
|
|
336
|
+
var completionItems = currentCommand.Service.GetCompletionItems(cursorOffset);
|
|
276
337
|
var disabledItems = this.disabledCompletionItemsV2;
|
|
277
338
|
if (this._languageSettings.disabledCompletionItems) {
|
|
278
339
|
this._languageSettings.disabledCompletionItems.map(function (item) {
|
|
@@ -439,6 +500,61 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
439
500
|
});
|
|
440
501
|
});
|
|
441
502
|
};
|
|
503
|
+
KustoLanguageService.prototype.getClusterReferences = function (document, cursorOffset) {
|
|
504
|
+
var _a;
|
|
505
|
+
var script = this.parseDocumentV2(document);
|
|
506
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
507
|
+
var clusterReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetClusterReferences();
|
|
508
|
+
if (!clusterReferences) {
|
|
509
|
+
return Promise.resolve([]);
|
|
510
|
+
}
|
|
511
|
+
var newClustersReferences = [];
|
|
512
|
+
var newClustersReferencesSet = new Set(); // used to remove duplicates
|
|
513
|
+
// Keep only unique clusters that aren't already exist in the Global State
|
|
514
|
+
for (var i = 0; i < clusterReferences.Count; i++) {
|
|
515
|
+
var clusterReference = clusterReferences.getItem(i);
|
|
516
|
+
var clusterHostName = clusterReference.Cluster;
|
|
517
|
+
// ignore duplicates
|
|
518
|
+
if (newClustersReferencesSet.has(clusterHostName)) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
newClustersReferencesSet.add(clusterHostName);
|
|
522
|
+
// ignore references that are already in the GlobalState.
|
|
523
|
+
if (!this._clustersSetInGlobalState.has(clusterHostName.toLowerCase())) {
|
|
524
|
+
newClustersReferences.push({ clusterName: clusterHostName });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return Promise.resolve(newClustersReferences);
|
|
528
|
+
};
|
|
529
|
+
KustoLanguageService.prototype.getDatabaseReferences = function (document, cursorOffset) {
|
|
530
|
+
var _a;
|
|
531
|
+
var script = this.parseDocumentV2(document);
|
|
532
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
533
|
+
var databasesReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetDatabaseReferences();
|
|
534
|
+
if (!databasesReferences) {
|
|
535
|
+
return Promise.resolve([]);
|
|
536
|
+
}
|
|
537
|
+
var newDatabasesReferences = [];
|
|
538
|
+
var newDatabasesReferencesSet = new Set();
|
|
539
|
+
for (var i1 = 0; i1 < databasesReferences.Count; i1++) {
|
|
540
|
+
var databaseReference = databasesReferences.getItem(i1);
|
|
541
|
+
// ignore duplicates
|
|
542
|
+
var databaseReferenceUniqueId = this.createDatabaseUniqueName(databaseReference.Cluster, databaseReference.Database);
|
|
543
|
+
if (newDatabasesReferencesSet.has(databaseReferenceUniqueId)) {
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
newDatabasesReferencesSet.add(databaseReferenceUniqueId);
|
|
547
|
+
// ignore references that are already in the GlobalState.
|
|
548
|
+
var foundInGlobalState = this._nonEmptyDatabaseSetInGlobalState.has(databaseReferenceUniqueId);
|
|
549
|
+
if (!foundInGlobalState) {
|
|
550
|
+
newDatabasesReferences.push({
|
|
551
|
+
databaseName: databaseReference.Database,
|
|
552
|
+
clusterName: databaseReference.Cluster
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return Promise.resolve(newDatabasesReferences);
|
|
557
|
+
};
|
|
442
558
|
KustoLanguageService.prototype.doValidation = function (document, changeIntervals) {
|
|
443
559
|
var _this = this;
|
|
444
560
|
// didn't implement validation for v1.
|
|
@@ -579,6 +695,46 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
579
695
|
: false;
|
|
580
696
|
});
|
|
581
697
|
};
|
|
698
|
+
KustoLanguageService.prototype.addClusterToSchema = function (document, clusterName, databaseNames) {
|
|
699
|
+
var clusterNameOnly = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
700
|
+
var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterNameOnly);
|
|
701
|
+
if (cluster) {
|
|
702
|
+
// add databases that are not already in the cluster.
|
|
703
|
+
databaseNames
|
|
704
|
+
.filter(function (databaseName) { return !cluster.GetDatabase(databaseName); })
|
|
705
|
+
.map(function (databaseName) {
|
|
706
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
707
|
+
cluster = cluster.AddDatabase(symbol);
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
if (!cluster) {
|
|
711
|
+
var databaseSymbols = databaseNames
|
|
712
|
+
.map(function (databaseName) {
|
|
713
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
714
|
+
return symbol;
|
|
715
|
+
});
|
|
716
|
+
var databaseSymbolsList = KustoLanguageService.toBridgeList(databaseSymbols);
|
|
717
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterNameOnly, databaseSymbolsList, false);
|
|
718
|
+
}
|
|
719
|
+
this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
720
|
+
this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
|
|
721
|
+
return Promise.resolve();
|
|
722
|
+
};
|
|
723
|
+
KustoLanguageService.prototype.addDatabaseToSchema = function (document, clusterName, databaseSchema) {
|
|
724
|
+
var _this = this;
|
|
725
|
+
return new Promise(function (resolve) {
|
|
726
|
+
var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
727
|
+
var cluster = _this._kustoJsSchemaV2.GetCluster$1(clusterHostName);
|
|
728
|
+
if (!cluster) {
|
|
729
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterHostName, null, false);
|
|
730
|
+
}
|
|
731
|
+
var databaseSymbol = KustoLanguageService.convertToDatabaseSymbol(databaseSchema);
|
|
732
|
+
cluster = cluster.AddOrUpdateDatabase(databaseSymbol);
|
|
733
|
+
_this._kustoJsSchemaV2 = _this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
734
|
+
_this._script = k2.CodeScript.From$1(document.getText(), _this._kustoJsSchemaV2);
|
|
735
|
+
resolve();
|
|
736
|
+
});
|
|
737
|
+
};
|
|
582
738
|
KustoLanguageService.prototype.setSchema = function (schema) {
|
|
583
739
|
var _this = this;
|
|
584
740
|
this._schema = schema;
|
|
@@ -627,29 +783,37 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
627
783
|
var databases = Object.keys(schema.Databases)
|
|
628
784
|
.map(function (key) { return schema.Databases[key]; })
|
|
629
785
|
.map(function (_a) {
|
|
630
|
-
var Name = _a.Name, Tables = _a.Tables, Functions = _a.Functions, MinorVersion = _a.MinorVersion, MajorVersion = _a.MajorVersion;
|
|
786
|
+
var Name = _a.Name, Tables = _a.Tables, ExternalTables = _a.ExternalTables, MaterializedViews = _a.MaterializedViews, Functions = _a.Functions, MinorVersion = _a.MinorVersion, MajorVersion = _a.MajorVersion;
|
|
631
787
|
return ({
|
|
632
788
|
name: Name,
|
|
633
789
|
minorVersion: MinorVersion,
|
|
634
790
|
majorVersion: MajorVersion,
|
|
635
|
-
tables:
|
|
636
|
-
.
|
|
791
|
+
tables: [].concat.apply([], [[Tables, 'Table'], [MaterializedViews, 'MaterializedView'], [ExternalTables, 'ExternalTable']]
|
|
792
|
+
.filter(function (_a) {
|
|
793
|
+
var tableContainer = _a[0];
|
|
794
|
+
return tableContainer;
|
|
795
|
+
})
|
|
637
796
|
.map(function (_a) {
|
|
638
|
-
var
|
|
639
|
-
return
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
797
|
+
var tableContainer = _a[0], tableEntity = _a[1];
|
|
798
|
+
return Object
|
|
799
|
+
.values(tableContainer)
|
|
800
|
+
.map(function (_a) {
|
|
801
|
+
var Name = _a.Name, OrderedColumns = _a.OrderedColumns, DocString = _a.DocString;
|
|
802
|
+
return ({
|
|
803
|
+
name: Name,
|
|
804
|
+
docstring: DocString,
|
|
805
|
+
entityType: tableEntity,
|
|
806
|
+
columns: OrderedColumns.map(function (_a) {
|
|
807
|
+
var Name = _a.Name, Type = _a.Type, DocString = _a.DocString, CslType = _a.CslType;
|
|
808
|
+
return ({
|
|
809
|
+
name: Name,
|
|
810
|
+
type: CslType,
|
|
811
|
+
docstring: DocString,
|
|
812
|
+
});
|
|
813
|
+
}),
|
|
814
|
+
});
|
|
651
815
|
});
|
|
652
|
-
}),
|
|
816
|
+
})),
|
|
653
817
|
functions: Object.keys(Functions)
|
|
654
818
|
.map(function (key) { return Functions[key]; })
|
|
655
819
|
.map(function (_a) {
|
|
@@ -1285,7 +1449,7 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
1285
1449
|
var argumentType = new sym.TableSymbol.ctor(param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); }));
|
|
1286
1450
|
return new sym.Parameter.$ctor2(param.name, argumentType);
|
|
1287
1451
|
};
|
|
1288
|
-
KustoLanguageService.convertToDatabaseSymbol = function (db
|
|
1452
|
+
KustoLanguageService.convertToDatabaseSymbol = function (db) {
|
|
1289
1453
|
var createFunctionSymbol = function (fn) {
|
|
1290
1454
|
var parameters = fn.inputParameters.map(function (param) {
|
|
1291
1455
|
return KustoLanguageService.createParameter(param);
|
|
@@ -1342,7 +1506,7 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
1342
1506
|
cachedDb.database.majorVersion < db.majorVersion ||
|
|
1343
1507
|
(shouldIncludeFunctions && !cachedDb.includesFunctions)) {
|
|
1344
1508
|
// only add functions for the database in context (it's very time consuming)
|
|
1345
|
-
var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db
|
|
1509
|
+
var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db);
|
|
1346
1510
|
cached[db.name] = { database: db, symbol: databaseSymbol_1, includesFunctions: shouldIncludeFunctions };
|
|
1347
1511
|
}
|
|
1348
1512
|
var databaseSymbol = cached[db.name].symbol;
|