@kusto/monaco-kusto 8.1.0 → 8.3.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 +16 -16
- package/release/dev/Kusto.Language.Bridge.min.js +1 -1
- package/release/dev/kusto.javascript.client.min.js +1 -1
- package/release/dev/kustoMode.js +21 -21
- package/release/dev/kustoWorker.js +23 -21
- package/release/dev/{main-3a499de0.js → main-e6ef956d.js} +168 -381
- package/release/dev/monaco.contribution.js +6 -9
- package/release/dev/{schema-c5e21c0d.js → schema-7d65ed04.js} +4 -4
- package/release/esm/commandFormatter.js +37 -0
- package/release/esm/commandHighlighter.js +52 -0
- package/release/esm/extendedEditor.js +41 -0
- package/release/esm/kusto.worker.js +2 -2
- package/release/esm/kustoMode.js +139 -1158
- package/release/esm/kustoWorker.js +252 -0
- package/release/esm/languageFeatures.js +1072 -0
- package/release/esm/languageService/kustoLanguageService.js +1923 -0
- package/release/esm/languageService/kustoMonarchLanguageDefinition.js +211 -0
- package/release/esm/languageService/renderInfo.js +1 -0
- package/release/esm/languageService/schema.js +64 -0
- package/release/esm/languageService/settings.js +1 -0
- package/release/esm/monaco.contribution.js +178 -426
- package/release/esm/{schema-76f41b43.js → schema-ee621489.js} +1 -2
- package/release/esm/types.js +1 -0
- package/release/esm/workerManager.js +102 -0
- package/release/min/Kusto.Language.Bridge.min.js +1 -1
- package/release/min/kusto.javascript.client.min.js +1 -1
- package/release/min/kustoMode.js +2 -2
- package/release/min/kustoWorker.js +2 -2
- package/release/min/main-04a9f035.js +7 -0
- package/release/min/monaco.contribution.js +2 -2
- package/release/min/{schema-ac23be64.js → schema-095fdf5a.js} +2 -2
- package/release/min/main-33264011.js +0 -7
|
@@ -0,0 +1,1923 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
var _a;
|
|
22
|
+
import XRegExp from 'xregexp';
|
|
23
|
+
import * as ls from 'vscode-languageserver-types';
|
|
24
|
+
import * as s from './schema';
|
|
25
|
+
// Replaced with @kusto/language-server imports at build time
|
|
26
|
+
import 'language-service';
|
|
27
|
+
var k = Kusto.Data.IntelliSense;
|
|
28
|
+
var parsing = Kusto.Language.Parsing;
|
|
29
|
+
var k2 = Kusto.Language.Editor;
|
|
30
|
+
var sym = Kusto.Language.Symbols;
|
|
31
|
+
var GlobalState = Kusto.Language.GlobalState;
|
|
32
|
+
import { getCslTypeNameFromClrType, getEntityDataTypeFromCslType } from './schema';
|
|
33
|
+
var List = System.Collections.Generic.List$1;
|
|
34
|
+
function assertNever(x) {
|
|
35
|
+
throw new Error('Unexpected object: ' + x);
|
|
36
|
+
}
|
|
37
|
+
var ParseProperties = /** @class */ (function () {
|
|
38
|
+
function ParseProperties(version, uri, rulesProvider, parseMode) {
|
|
39
|
+
this.version = version;
|
|
40
|
+
this.uri = uri;
|
|
41
|
+
this.rulesProvider = rulesProvider;
|
|
42
|
+
this.parseMode = parseMode;
|
|
43
|
+
}
|
|
44
|
+
ParseProperties.prototype.isParseNeeded = function (document, rulesProvider, parseMode) {
|
|
45
|
+
if (document.uri === this.uri &&
|
|
46
|
+
(!rulesProvider || rulesProvider === this.rulesProvider) &&
|
|
47
|
+
document.version <= this.version &&
|
|
48
|
+
parseMode &&
|
|
49
|
+
parseMode <= this.parseMode) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
return ParseProperties;
|
|
55
|
+
}());
|
|
56
|
+
export var TokenKind;
|
|
57
|
+
(function (TokenKind) {
|
|
58
|
+
TokenKind[TokenKind["TableToken"] = 2] = "TableToken";
|
|
59
|
+
TokenKind[TokenKind["TableColumnToken"] = 4] = "TableColumnToken";
|
|
60
|
+
TokenKind[TokenKind["OperatorToken"] = 8] = "OperatorToken";
|
|
61
|
+
TokenKind[TokenKind["SubOperatorToken"] = 16] = "SubOperatorToken";
|
|
62
|
+
TokenKind[TokenKind["CalculatedColumnToken"] = 32] = "CalculatedColumnToken";
|
|
63
|
+
TokenKind[TokenKind["StringLiteralToken"] = 64] = "StringLiteralToken";
|
|
64
|
+
TokenKind[TokenKind["FunctionNameToken"] = 128] = "FunctionNameToken";
|
|
65
|
+
TokenKind[TokenKind["UnknownToken"] = 256] = "UnknownToken";
|
|
66
|
+
TokenKind[TokenKind["CommentToken"] = 512] = "CommentToken";
|
|
67
|
+
TokenKind[TokenKind["PlainTextToken"] = 1024] = "PlainTextToken";
|
|
68
|
+
TokenKind[TokenKind["DataTypeToken"] = 2048] = "DataTypeToken";
|
|
69
|
+
TokenKind[TokenKind["ControlCommandToken"] = 4096] = "ControlCommandToken";
|
|
70
|
+
TokenKind[TokenKind["CommandPartToken"] = 8192] = "CommandPartToken";
|
|
71
|
+
TokenKind[TokenKind["QueryParametersToken"] = 16384] = "QueryParametersToken";
|
|
72
|
+
TokenKind[TokenKind["CslCommandToken"] = 32768] = "CslCommandToken";
|
|
73
|
+
TokenKind[TokenKind["LetVariablesToken"] = 65536] = "LetVariablesToken";
|
|
74
|
+
TokenKind[TokenKind["PluginToken"] = 131072] = "PluginToken";
|
|
75
|
+
TokenKind[TokenKind["BracketRangeToken"] = 262144] = "BracketRangeToken";
|
|
76
|
+
TokenKind[TokenKind["ClientDirectiveToken"] = 524288] = "ClientDirectiveToken";
|
|
77
|
+
})(TokenKind || (TokenKind = {}));
|
|
78
|
+
/**
|
|
79
|
+
* convert the bridge.net object to a plain javascript object that only contains data.
|
|
80
|
+
* @param k2Classifications @kusto/language-service-next bridge.net object
|
|
81
|
+
*/
|
|
82
|
+
function toClassifiedRange(k2Classifications) {
|
|
83
|
+
return k2Classifications.map(function (classification) { return ({
|
|
84
|
+
start: classification.Start,
|
|
85
|
+
end: classification.End,
|
|
86
|
+
length: classification.Length,
|
|
87
|
+
kind: classification.Kind,
|
|
88
|
+
}); });
|
|
89
|
+
}
|
|
90
|
+
var symbolKindToName = (_a = {},
|
|
91
|
+
_a[sym.SymbolKind.Cluster] = 'Cluster',
|
|
92
|
+
_a[sym.SymbolKind.Column] = 'Column',
|
|
93
|
+
_a[sym.SymbolKind.Command] = 'Command',
|
|
94
|
+
_a[sym.SymbolKind.Database] = 'Database',
|
|
95
|
+
_a[sym.SymbolKind.EntityGroup] = 'EntityGroup',
|
|
96
|
+
_a[sym.SymbolKind.EntityGroupElement] = 'EntityGroupElement',
|
|
97
|
+
_a[sym.SymbolKind.Error] = 'Error',
|
|
98
|
+
_a[sym.SymbolKind.Function] = 'Function',
|
|
99
|
+
_a[sym.SymbolKind.Graph] = 'Graph',
|
|
100
|
+
_a[sym.SymbolKind.Group] = 'Group',
|
|
101
|
+
_a[sym.SymbolKind.MaterializedView] = 'MaterializedView',
|
|
102
|
+
_a[sym.SymbolKind.None] = 'None',
|
|
103
|
+
_a[sym.SymbolKind.Operator] = 'Operator',
|
|
104
|
+
_a[sym.SymbolKind.Option] = 'Option',
|
|
105
|
+
_a[sym.SymbolKind.Parameter] = 'Parameter',
|
|
106
|
+
_a[sym.SymbolKind.Pattern] = 'Pattern',
|
|
107
|
+
_a[sym.SymbolKind.QueryOperatorParameter] = 'QueryOperatorParameter',
|
|
108
|
+
_a[sym.SymbolKind.Primitive] = 'Primitive',
|
|
109
|
+
_a[sym.SymbolKind.Table] = 'Table',
|
|
110
|
+
_a[sym.SymbolKind.Tuple] = 'Tuple',
|
|
111
|
+
_a[sym.SymbolKind.Variable] = 'Variable',
|
|
112
|
+
_a[sym.SymbolKind.Void] = 'Void',
|
|
113
|
+
_a);
|
|
114
|
+
/**
|
|
115
|
+
* Kusto Language service translates the kusto object model (transpiled from C# by Bridge.Net)
|
|
116
|
+
* to the vscode language server types, which are used by vscode language extensions.
|
|
117
|
+
* This should make things easier in the future to provide a vscode extension based on this translation layer.
|
|
118
|
+
*
|
|
119
|
+
* Further translations, if needed, to support specific editors (Atom, sublime, Etc)
|
|
120
|
+
* should be done on top of this API, since it is (at least meant to be) a standard that is supported by multiple editors.
|
|
121
|
+
*
|
|
122
|
+
* Note1: Currently monaco isn't using this object model so further translation will be necessary on calling modules.
|
|
123
|
+
*
|
|
124
|
+
* Note2: This file is responsible for interacting with the kusto object model and exposing Microsoft language service types.
|
|
125
|
+
* An exception to that rule is tokenization (and syntax highlighting which depends on it) -
|
|
126
|
+
* since it's not currently part of the Microsoft language service protocol. Thus tokenize() _does_ 'leak' kusto types to the callers.
|
|
127
|
+
*/
|
|
128
|
+
var KustoLanguageService = /** @class */ (function () {
|
|
129
|
+
function KustoLanguageService(schema, languageSettings) {
|
|
130
|
+
var _a, _b, _c, _d;
|
|
131
|
+
var _this = this;
|
|
132
|
+
/**
|
|
133
|
+
* Taken from:
|
|
134
|
+
* 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
|
|
135
|
+
*/
|
|
136
|
+
this._toOptionKind = (_a = {},
|
|
137
|
+
_a[k2.CompletionKind.AggregateFunction] = k.OptionKind.FunctionAggregation,
|
|
138
|
+
_a[k2.CompletionKind.BuiltInFunction] = k.OptionKind.FunctionScalar,
|
|
139
|
+
_a[k2.CompletionKind.Cluster] = k.OptionKind.Database,
|
|
140
|
+
_a[k2.CompletionKind.Column] = k.OptionKind.Column,
|
|
141
|
+
_a[k2.CompletionKind.CommandPrefix] = k.OptionKind.Command,
|
|
142
|
+
_a[k2.CompletionKind.Database] = k.OptionKind.Database,
|
|
143
|
+
_a[k2.CompletionKind.DatabaseFunction] = k.OptionKind.FunctionServerSide,
|
|
144
|
+
_a[k2.CompletionKind.Example] = k.OptionKind.Literal,
|
|
145
|
+
_a[k2.CompletionKind.Identifier] = k.OptionKind.None,
|
|
146
|
+
_a[k2.CompletionKind.Keyword] = k.OptionKind.Option,
|
|
147
|
+
_a[k2.CompletionKind.LocalFunction] = k.OptionKind.FunctionLocal,
|
|
148
|
+
_a[k2.CompletionKind.MaterialiedView] = k.OptionKind.MaterializedView,
|
|
149
|
+
_a[k2.CompletionKind.Parameter] = k.OptionKind.Parameter,
|
|
150
|
+
_a[k2.CompletionKind.Punctuation] = k.OptionKind.None,
|
|
151
|
+
_a[k2.CompletionKind.QueryPrefix] = k.OptionKind.Operator,
|
|
152
|
+
_a[k2.CompletionKind.RenderChart] = k.OptionKind.OptionRender,
|
|
153
|
+
_a[k2.CompletionKind.ScalarInfix] = k.OptionKind.None,
|
|
154
|
+
_a[k2.CompletionKind.ScalarPrefix] = k.OptionKind.Literal,
|
|
155
|
+
_a[k2.CompletionKind.ScalarType] = k.OptionKind.DataType,
|
|
156
|
+
_a[k2.CompletionKind.Syntax] = k.OptionKind.None,
|
|
157
|
+
_a[k2.CompletionKind.Table] = k.OptionKind.Table,
|
|
158
|
+
_a[k2.CompletionKind.TabularPrefix] = k.OptionKind.None,
|
|
159
|
+
_a[k2.CompletionKind.TabularSuffix] = k.OptionKind.None,
|
|
160
|
+
_a[k2.CompletionKind.Unknown] = k.OptionKind.None,
|
|
161
|
+
_a[k2.CompletionKind.Variable] = k.OptionKind.Parameter,
|
|
162
|
+
_a[k2.CompletionKind.Option] = k.OptionKind.Option,
|
|
163
|
+
_a[k2.CompletionKind.Graph] = k.OptionKind.Graph,
|
|
164
|
+
_a);
|
|
165
|
+
this.disabledCompletionItemsV2 = {
|
|
166
|
+
// render charts
|
|
167
|
+
ladderchart: k2.CompletionKind.RenderChart,
|
|
168
|
+
pivotchart: k2.CompletionKind.RenderChart,
|
|
169
|
+
timeline: k2.CompletionKind.RenderChart,
|
|
170
|
+
timepivot: k2.CompletionKind.RenderChart,
|
|
171
|
+
'3Dchart': k2.CompletionKind.RenderChart,
|
|
172
|
+
list: k2.CompletionKind.RenderChart,
|
|
173
|
+
};
|
|
174
|
+
this.isIntellisenseV2 = function () {
|
|
175
|
+
return _this._languageSettings.useIntellisenseV2 && _this._schema && _this._schema.clusterType === 'Engine';
|
|
176
|
+
};
|
|
177
|
+
this.disabledCompletionItemsV1 = {
|
|
178
|
+
capacity: k.OptionKind.Policy,
|
|
179
|
+
callout: k.OptionKind.Policy,
|
|
180
|
+
encoding: k.OptionKind.Policy,
|
|
181
|
+
batching: k.OptionKind.Policy,
|
|
182
|
+
querythrottling: k.OptionKind.Policy,
|
|
183
|
+
merge: k.OptionKind.Policy,
|
|
184
|
+
querylimit: k.OptionKind.Policy,
|
|
185
|
+
rowstore: k.OptionKind.Policy,
|
|
186
|
+
streamingingestion: k.OptionKind.Policy,
|
|
187
|
+
restricted_view_access: k.OptionKind.Policy,
|
|
188
|
+
sharding: k.OptionKind.Policy,
|
|
189
|
+
'restricted-viewers': k.OptionKind.Policy,
|
|
190
|
+
attach: k.OptionKind.Command,
|
|
191
|
+
purge: k.OptionKind.Command,
|
|
192
|
+
};
|
|
193
|
+
this._kustoKindtolsKind = (_b = {},
|
|
194
|
+
_b[k.OptionKind.None] = ls.CompletionItemKind.Interface,
|
|
195
|
+
_b[k.OptionKind.Operator] = ls.CompletionItemKind.Method,
|
|
196
|
+
_b[k.OptionKind.Command] = ls.CompletionItemKind.Method,
|
|
197
|
+
_b[k.OptionKind.Service] = ls.CompletionItemKind.Class,
|
|
198
|
+
_b[k.OptionKind.Policy] = ls.CompletionItemKind.Reference,
|
|
199
|
+
_b[k.OptionKind.Database] = ls.CompletionItemKind.Class,
|
|
200
|
+
_b[k.OptionKind.Table] = ls.CompletionItemKind.Class,
|
|
201
|
+
_b[k.OptionKind.DataType] = ls.CompletionItemKind.Class,
|
|
202
|
+
_b[k.OptionKind.Literal] = ls.CompletionItemKind.Property,
|
|
203
|
+
_b[k.OptionKind.Parameter] = ls.CompletionItemKind.Variable,
|
|
204
|
+
_b[k.OptionKind.IngestionMapping] = ls.CompletionItemKind.Variable,
|
|
205
|
+
_b[k.OptionKind.ExpressionFunction] = ls.CompletionItemKind.Variable,
|
|
206
|
+
_b[k.OptionKind.Option] = ls.CompletionItemKind.Interface,
|
|
207
|
+
_b[k.OptionKind.OptionKind] = ls.CompletionItemKind.Interface,
|
|
208
|
+
_b[k.OptionKind.OptionRender] = ls.CompletionItemKind.Interface,
|
|
209
|
+
_b[k.OptionKind.Column] = ls.CompletionItemKind.Function,
|
|
210
|
+
_b[k.OptionKind.ColumnString] = ls.CompletionItemKind.Field,
|
|
211
|
+
_b[k.OptionKind.ColumnNumeric] = ls.CompletionItemKind.Field,
|
|
212
|
+
_b[k.OptionKind.ColumnDateTime] = ls.CompletionItemKind.Field,
|
|
213
|
+
_b[k.OptionKind.ColumnTimespan] = ls.CompletionItemKind.Field,
|
|
214
|
+
_b[k.OptionKind.FunctionServerSide] = ls.CompletionItemKind.Field,
|
|
215
|
+
_b[k.OptionKind.FunctionAggregation] = ls.CompletionItemKind.Field,
|
|
216
|
+
_b[k.OptionKind.FunctionFilter] = ls.CompletionItemKind.Field,
|
|
217
|
+
_b[k.OptionKind.FunctionScalar] = ls.CompletionItemKind.Field,
|
|
218
|
+
_b[k.OptionKind.ClientDirective] = ls.CompletionItemKind.Enum,
|
|
219
|
+
_b);
|
|
220
|
+
this._kustoKindToLsKindV2 = (_c = {},
|
|
221
|
+
_c[k2.CompletionKind.AggregateFunction] = ls.CompletionItemKind.Field,
|
|
222
|
+
_c[k2.CompletionKind.BuiltInFunction] = ls.CompletionItemKind.Field,
|
|
223
|
+
_c[k2.CompletionKind.Cluster] = ls.CompletionItemKind.Class,
|
|
224
|
+
_c[k2.CompletionKind.Column] = ls.CompletionItemKind.Function,
|
|
225
|
+
_c[k2.CompletionKind.CommandPrefix] = ls.CompletionItemKind.Field,
|
|
226
|
+
_c[k2.CompletionKind.Database] = ls.CompletionItemKind.Class,
|
|
227
|
+
_c[k2.CompletionKind.DatabaseFunction] = ls.CompletionItemKind.Field,
|
|
228
|
+
_c[k2.CompletionKind.Example] = ls.CompletionItemKind.Text,
|
|
229
|
+
_c[k2.CompletionKind.Identifier] = ls.CompletionItemKind.Method,
|
|
230
|
+
_c[k2.CompletionKind.Keyword] = ls.CompletionItemKind.Method,
|
|
231
|
+
_c[k2.CompletionKind.LocalFunction] = ls.CompletionItemKind.Field,
|
|
232
|
+
_c[k2.CompletionKind.MaterialiedView] = ls.CompletionItemKind.Class,
|
|
233
|
+
_c[k2.CompletionKind.Parameter] = ls.CompletionItemKind.Variable,
|
|
234
|
+
_c[k2.CompletionKind.Punctuation] = ls.CompletionItemKind.Interface,
|
|
235
|
+
_c[k2.CompletionKind.QueryPrefix] = ls.CompletionItemKind.Function,
|
|
236
|
+
_c[k2.CompletionKind.RenderChart] = ls.CompletionItemKind.Method,
|
|
237
|
+
_c[k2.CompletionKind.ScalarInfix] = ls.CompletionItemKind.Field,
|
|
238
|
+
_c[k2.CompletionKind.ScalarPrefix] = ls.CompletionItemKind.Field,
|
|
239
|
+
_c[k2.CompletionKind.ScalarType] = ls.CompletionItemKind.TypeParameter,
|
|
240
|
+
_c[k2.CompletionKind.Syntax] = ls.CompletionItemKind.Method,
|
|
241
|
+
_c[k2.CompletionKind.Table] = ls.CompletionItemKind.Class,
|
|
242
|
+
_c[k2.CompletionKind.TabularPrefix] = ls.CompletionItemKind.Field,
|
|
243
|
+
// datatable, externaldata
|
|
244
|
+
_c[k2.CompletionKind.TabularSuffix] = ls.CompletionItemKind.Field,
|
|
245
|
+
_c[k2.CompletionKind.Unknown] = ls.CompletionItemKind.Interface,
|
|
246
|
+
_c[k2.CompletionKind.Variable] = ls.CompletionItemKind.Variable,
|
|
247
|
+
_c[k2.CompletionKind.Option] = ls.CompletionItemKind.Text,
|
|
248
|
+
_c[k2.CompletionKind.Graph] = ls.CompletionItemKind.Class,
|
|
249
|
+
_c);
|
|
250
|
+
this._tokenKindToClassificationKind = (_d = {},
|
|
251
|
+
_d[TokenKind.TableToken] = k2.ClassificationKind.Table,
|
|
252
|
+
_d[TokenKind.TableColumnToken] = k2.ClassificationKind.Column,
|
|
253
|
+
_d[TokenKind.OperatorToken] = k2.ClassificationKind.QueryOperator,
|
|
254
|
+
_d[TokenKind.SubOperatorToken] = k2.ClassificationKind.Function,
|
|
255
|
+
_d[TokenKind.CalculatedColumnToken] = k2.ClassificationKind.Column,
|
|
256
|
+
_d[TokenKind.StringLiteralToken] = k2.ClassificationKind.Literal,
|
|
257
|
+
_d[TokenKind.FunctionNameToken] = k2.ClassificationKind.Function,
|
|
258
|
+
_d[TokenKind.UnknownToken] = k2.ClassificationKind.PlainText,
|
|
259
|
+
_d[TokenKind.CommentToken] = k2.ClassificationKind.Comment,
|
|
260
|
+
_d[TokenKind.PlainTextToken] = k2.ClassificationKind.PlainText,
|
|
261
|
+
_d[TokenKind.DataTypeToken] = k2.ClassificationKind.Type,
|
|
262
|
+
_d[TokenKind.ControlCommandToken] = k2.ClassificationKind.PlainText,
|
|
263
|
+
_d[TokenKind.CommandPartToken] = k2.ClassificationKind.PlainText,
|
|
264
|
+
_d[TokenKind.QueryParametersToken] = k2.ClassificationKind.QueryParameter,
|
|
265
|
+
_d[TokenKind.CslCommandToken] = k2.ClassificationKind.Keyword,
|
|
266
|
+
_d[TokenKind.LetVariablesToken] = k2.ClassificationKind.Identifier,
|
|
267
|
+
_d[TokenKind.PluginToken] = k2.ClassificationKind.Function,
|
|
268
|
+
_d[TokenKind.BracketRangeToken] = k2.ClassificationKind.Keyword,
|
|
269
|
+
_d[TokenKind.ClientDirectiveToken] = k2.ClassificationKind.Keyword,
|
|
270
|
+
_d);
|
|
271
|
+
this._schemaCache = {};
|
|
272
|
+
this._kustoJsSchema = KustoLanguageService.convertToKustoJsSchema(schema);
|
|
273
|
+
this.__kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
|
|
274
|
+
this._schema = schema;
|
|
275
|
+
this._clustersSetInGlobalState = new Set();
|
|
276
|
+
this._nonEmptyDatabaseSetInGlobalState = new Set(); // used to remove clusters that are already in the global state
|
|
277
|
+
this.configure(languageSettings);
|
|
278
|
+
this._newlineAppendPipePolicy = new Kusto.Data.IntelliSense.ApplyPolicy();
|
|
279
|
+
this._newlineAppendPipePolicy.Text = '\n| ';
|
|
280
|
+
}
|
|
281
|
+
KustoLanguageService.prototype.createDatabaseUniqueName = function (clusterName, databaseName) {
|
|
282
|
+
return "".concat(clusterName, "_").concat(databaseName);
|
|
283
|
+
};
|
|
284
|
+
Object.defineProperty(KustoLanguageService.prototype, "_kustoJsSchemaV2", {
|
|
285
|
+
/**
|
|
286
|
+
* A getter for __kustoJsSchemaV2
|
|
287
|
+
*/
|
|
288
|
+
get: function () {
|
|
289
|
+
return this.__kustoJsSchemaV2;
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* A setter for _kustoJsSchemaV2. After a schema (global state) is set, create 2 sets of cluster and database names.
|
|
293
|
+
*/
|
|
294
|
+
set: function (globalState) {
|
|
295
|
+
this.__kustoJsSchemaV2 = globalState;
|
|
296
|
+
this._clustersSetInGlobalState.clear();
|
|
297
|
+
this._nonEmptyDatabaseSetInGlobalState.clear();
|
|
298
|
+
// create 2 Sets with cluster names and database names based on the updated Global State.
|
|
299
|
+
for (var i = 0; i < globalState.Clusters.Count; i++) {
|
|
300
|
+
var clusterSymbol = this._kustoJsSchemaV2.Clusters.getItem(i);
|
|
301
|
+
this._clustersSetInGlobalState.add(clusterSymbol.Name);
|
|
302
|
+
for (var i2 = 0; i2 < clusterSymbol.Databases.Count; i2++) {
|
|
303
|
+
var databaseSymbol = clusterSymbol.Databases.getItem(i2);
|
|
304
|
+
if (databaseSymbol.Tables.Count > 0) {
|
|
305
|
+
// only include database with tables
|
|
306
|
+
this._nonEmptyDatabaseSetInGlobalState.add(this.createDatabaseUniqueName(clusterSymbol.Name, databaseSymbol.Name));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
enumerable: false,
|
|
312
|
+
configurable: true
|
|
313
|
+
});
|
|
314
|
+
KustoLanguageService.prototype.configure = function (languageSettings) {
|
|
315
|
+
this._languageSettings = languageSettings;
|
|
316
|
+
// Since we're still reverting to V1 intellisense for control commands, we need to update the rules provider
|
|
317
|
+
// (which is a notion of V1 intellisense).
|
|
318
|
+
this.createRulesProvider(this._kustoJsSchema, this._schema.clusterType);
|
|
319
|
+
};
|
|
320
|
+
KustoLanguageService.prototype.doComplete = function (document, position) {
|
|
321
|
+
return this.isIntellisenseV2() ? this.doCompleteV2(document, position) : this.doCompleteV1(document, position);
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* important: Only use during development to test Global State.
|
|
325
|
+
* Prints clusters, databases and tables that are currently in the GlobalState.
|
|
326
|
+
*/
|
|
327
|
+
KustoLanguageService.prototype.debugGlobalState = function (globals) {
|
|
328
|
+
// iterate over clusters
|
|
329
|
+
console.log("globals.Clusters.Count: ".concat(globals.Clusters.Count));
|
|
330
|
+
for (var i = 0; i < globals.Clusters.Count; i++) {
|
|
331
|
+
var cluster = globals.Clusters.getItem(i);
|
|
332
|
+
console.log("cluster: ".concat(cluster.Name));
|
|
333
|
+
// iterate over databases
|
|
334
|
+
console.log("cluster.Databases.Count: ".concat(cluster.Databases.Count));
|
|
335
|
+
for (var i2 = 0; i2 < cluster.Databases.Count; i2++) {
|
|
336
|
+
var database = cluster.Databases.getItem(i2);
|
|
337
|
+
console.log("cluster.database: [".concat(cluster.Name, "].[").concat(database.Name, "]"));
|
|
338
|
+
// iterate over tables
|
|
339
|
+
console.log("cluster.Databases.Tables.Count: ".concat(database.Tables.Count));
|
|
340
|
+
for (var i3 = 0; i3 < database.Tables.Count; i3++) {
|
|
341
|
+
var table = database.Tables.getItem(i3);
|
|
342
|
+
console.log("cluster.database.table: [".concat(cluster.Name, "].[").concat(database.Name, "].[").concat(table.Name, "]"));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Prepending the doc of the actual topic at the top
|
|
349
|
+
*/
|
|
350
|
+
KustoLanguageService.prototype.formatHelpTopic = function (helpTopic) {
|
|
351
|
+
return "**".concat(helpTopic.Name, " [(view online)](").concat(helpTopic.Url, ")**\n\n").concat(helpTopic.LongDescription);
|
|
352
|
+
};
|
|
353
|
+
KustoLanguageService.prototype.doCompleteV2 = function (document, position) {
|
|
354
|
+
var _this = this;
|
|
355
|
+
if (!document) {
|
|
356
|
+
return Promise.resolve(ls.CompletionList.create([]));
|
|
357
|
+
}
|
|
358
|
+
var script = this.parseDocumentV2(document);
|
|
359
|
+
// print cluster/database/tables from CodeScript.Globals
|
|
360
|
+
// this.debugGlobalState(script.Globals);
|
|
361
|
+
// get current command
|
|
362
|
+
var cursorOffset = document.offsetAt(position);
|
|
363
|
+
var currentCommand = script.GetBlockAtPosition(cursorOffset);
|
|
364
|
+
// get completion items
|
|
365
|
+
var completionItems = currentCommand.Service.GetCompletionItems(cursorOffset);
|
|
366
|
+
var disabledItems = this.disabledCompletionItemsV2;
|
|
367
|
+
if (this._languageSettings.disabledCompletionItems) {
|
|
368
|
+
this._languageSettings.disabledCompletionItems.map(function (item) {
|
|
369
|
+
// logic will treat unknown as a '*' wildcard, meaning that if the key is in the object
|
|
370
|
+
// the completion item will be suppressed.
|
|
371
|
+
disabledItems[item] = k2.CompletionKind.Unknown;
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
var itemsAsArray = this.toArray(completionItems.Items);
|
|
375
|
+
var items = itemsAsArray
|
|
376
|
+
.filter(function (item) {
|
|
377
|
+
return !(item &&
|
|
378
|
+
item.MatchText &&
|
|
379
|
+
disabledItems[item.MatchText] !== undefined &&
|
|
380
|
+
(disabledItems[item.MatchText] === k2.CompletionKind.Unknown ||
|
|
381
|
+
disabledItems[item.MatchText] === item.Kind));
|
|
382
|
+
})
|
|
383
|
+
.map(function (kItem, i) {
|
|
384
|
+
var v1CompletionOption = new k.CompletionOption(_this._toOptionKind[kItem.Kind] || k.OptionKind.None, kItem.DisplayText);
|
|
385
|
+
var helpTopic = _this.getTopic(v1CompletionOption);
|
|
386
|
+
// If we have AfterText it means that the cursor should no be placed at end of suggested text.
|
|
387
|
+
// In that case we switch to snippet format and represent the point where the cursor should be as
|
|
388
|
+
// as '\$0'
|
|
389
|
+
var _a = kItem.AfterText && kItem.AfterText.length > 0
|
|
390
|
+
? {
|
|
391
|
+
// Need to escape dollar sign since it is used as a placeholder in snippet.
|
|
392
|
+
// Usually dollar sign is not a valid character in a function name, but grafana uses macros that start with dollars.
|
|
393
|
+
textToInsert: "".concat(kItem.EditText.replace('$', '\\$'), "$0").concat(kItem.AfterText),
|
|
394
|
+
format: ls.InsertTextFormat.Snippet,
|
|
395
|
+
}
|
|
396
|
+
: {
|
|
397
|
+
textToInsert: kItem.EditText,
|
|
398
|
+
format: ls.InsertTextFormat.PlainText,
|
|
399
|
+
}, textToInsert = _a.textToInsert, format = _a.format;
|
|
400
|
+
var lsItem = ls.CompletionItem.create(kItem.DisplayText);
|
|
401
|
+
// Adding to columns a prefix to their sortText so they will appear first in the list
|
|
402
|
+
var sortTextPrefix = lsItem.kind === ls.CompletionItemKind.Field ? 0 : itemsAsArray.length;
|
|
403
|
+
var countOfWords = lsItem.label.split('_').filter(function (item) { return !!item; }).length;
|
|
404
|
+
// We always want results with multiple words to show after shorter options.
|
|
405
|
+
// For example: to show "count_distinct" after "count"
|
|
406
|
+
sortTextPrefix = sortTextPrefix * countOfWords;
|
|
407
|
+
var startPosition = document.positionAt(completionItems.EditStart);
|
|
408
|
+
var endPosition = document.positionAt(completionItems.EditStart + completionItems.EditLength);
|
|
409
|
+
lsItem.textEdit = ls.TextEdit.replace(ls.Range.create(startPosition, endPosition), textToInsert);
|
|
410
|
+
lsItem.sortText = _this.getSortText(sortTextPrefix + i + 1);
|
|
411
|
+
// Changing the first letter to be lower case, to ignore case-sensitive matching
|
|
412
|
+
lsItem.filterText = lsItem.label.charAt(0).toLowerCase() + lsItem.label.slice(1);
|
|
413
|
+
lsItem.kind = _this.kustoKindToLsKindV2(kItem.Kind);
|
|
414
|
+
lsItem.insertTextFormat = format;
|
|
415
|
+
lsItem.detail = helpTopic ? helpTopic.ShortDescription : undefined;
|
|
416
|
+
lsItem.documentation = helpTopic
|
|
417
|
+
? { value: _this.formatHelpTopic(helpTopic), kind: ls.MarkupKind.Markdown }
|
|
418
|
+
: undefined;
|
|
419
|
+
return lsItem;
|
|
420
|
+
});
|
|
421
|
+
return Promise.resolve(ls.CompletionList.create(items));
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* when trying to get a topic we need the function name (abs, toLower, ETC).
|
|
425
|
+
* The problem is that the 'Value' string also contains the arguments (e.g abs(number)), which means that we are
|
|
426
|
+
* not able to correlate the option with its documentation.
|
|
427
|
+
* This piece of code tries to strip this hwne getting topic.
|
|
428
|
+
* @param completionOption the Completion option
|
|
429
|
+
*/
|
|
430
|
+
KustoLanguageService.prototype.getTopic = function (completionOption) {
|
|
431
|
+
if (completionOption.Kind == k.OptionKind.FunctionScalar ||
|
|
432
|
+
completionOption.Kind == k.OptionKind.FunctionAggregation) {
|
|
433
|
+
// from a value like 'abs(number)' remove the '(number)' so that only 'abs' will remain
|
|
434
|
+
var indexOfParen = completionOption.Value.indexOf('(');
|
|
435
|
+
if (indexOfParen >= 0) {
|
|
436
|
+
completionOption = new k.CompletionOption(completionOption.Kind, completionOption.Value.substring(0, indexOfParen));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return k.CslDocumentation.Instance.GetTopic(completionOption);
|
|
440
|
+
};
|
|
441
|
+
KustoLanguageService.prototype.doCompleteV1 = function (document, position) {
|
|
442
|
+
var _this = this;
|
|
443
|
+
// TODO: fix typing in CslCommandParser to allow rulesProvider to be query only.
|
|
444
|
+
var caretAbsolutePosition = document.offsetAt(position);
|
|
445
|
+
// find out what's the current command to only parse this one.
|
|
446
|
+
this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
|
|
447
|
+
var currentCommand = this.getCurrentCommand(document, caretAbsolutePosition);
|
|
448
|
+
var commandTextUntilCursor = '';
|
|
449
|
+
if (currentCommand) {
|
|
450
|
+
var commandStartOffset = currentCommand.AbsoluteStart;
|
|
451
|
+
this.parseTextV1(currentCommand.Text, k.ParseMode.TokenizeAllText);
|
|
452
|
+
var caretRelativePosition = caretAbsolutePosition - currentCommand.AbsoluteStart;
|
|
453
|
+
commandTextUntilCursor = currentCommand.Text.substring(currentCommand.CslExpressionStartPosition, caretRelativePosition);
|
|
454
|
+
}
|
|
455
|
+
var commandTextWithoutLastWord = this.getCommandWithoutLastWord(commandTextUntilCursor);
|
|
456
|
+
var context = this._rulesProvider.AnalyzeCommand$1(commandTextUntilCursor, currentCommand).Context;
|
|
457
|
+
var result = { v: null };
|
|
458
|
+
this._rulesProvider.TryMatchAnyRule(commandTextWithoutLastWord, result);
|
|
459
|
+
var rule = result.v;
|
|
460
|
+
if (rule) {
|
|
461
|
+
var completionOptions = this.toArray(rule.GetCompletionOptions(context));
|
|
462
|
+
// TODO once AppendPipePolicy becomes a public static member of ApplyPolicy in our c# code, and bridge.Net transplies this,
|
|
463
|
+
// remove the 'as any' part..
|
|
464
|
+
// Also = DefaultApplyPolicy is internal in c# code, so not exposed in d.ts, so we cast it to any.
|
|
465
|
+
if (this._languageSettings.newlineAfterPipe &&
|
|
466
|
+
rule.DefaultAfterApplyPolicy === Kusto.Data.IntelliSense.ApplyPolicy.AppendPipePolicy) {
|
|
467
|
+
rule.DefaultAfterApplyPolicy = this._newlineAppendPipePolicy;
|
|
468
|
+
}
|
|
469
|
+
var options = completionOptions
|
|
470
|
+
.filter(function (option) {
|
|
471
|
+
return !(option && option.Value && _this.disabledCompletionItemsV1[option.Value] === option.Kind);
|
|
472
|
+
})
|
|
473
|
+
.map(function (option, ordinal) {
|
|
474
|
+
var _a = _this.getTextToInsert(rule, option), insertText = _a.insertText, insertTextFormat = _a.insertTextFormat;
|
|
475
|
+
var helpTopic = k.CslDocumentation.Instance.GetTopic(option);
|
|
476
|
+
var item = ls.CompletionItem.create(option.Value);
|
|
477
|
+
item.kind = _this.kustoKindToLsKind(option.Kind);
|
|
478
|
+
item.insertText = insertText;
|
|
479
|
+
item.insertTextFormat = insertTextFormat;
|
|
480
|
+
item.sortText = _this.getSortText(ordinal + 1);
|
|
481
|
+
item.detail = helpTopic ? helpTopic.ShortDescription : undefined;
|
|
482
|
+
item.documentation = helpTopic
|
|
483
|
+
? { value: helpTopic.LongDescription, kind: ls.MarkupKind.Markdown }
|
|
484
|
+
: undefined;
|
|
485
|
+
return item;
|
|
486
|
+
});
|
|
487
|
+
return Promise.resolve(ls.CompletionList.create(options));
|
|
488
|
+
}
|
|
489
|
+
return Promise.resolve(ls.CompletionList.create([]));
|
|
490
|
+
};
|
|
491
|
+
KustoLanguageService.prototype.doRangeFormat = function (document, range) {
|
|
492
|
+
if (!document) {
|
|
493
|
+
return Promise.resolve([]);
|
|
494
|
+
}
|
|
495
|
+
var rangeStartOffset = document.offsetAt(range.start);
|
|
496
|
+
var rangeEndOffset = document.offsetAt(range.end);
|
|
497
|
+
var commands = this.getFormattedCommandsInDocumentV2(document, rangeStartOffset, rangeEndOffset);
|
|
498
|
+
if (!commands.originalRange || commands.formattedCommands.length === 0) {
|
|
499
|
+
return Promise.resolve([]);
|
|
500
|
+
}
|
|
501
|
+
return Promise.resolve([ls.TextEdit.replace(commands.originalRange, commands.formattedCommands.join(''))]);
|
|
502
|
+
};
|
|
503
|
+
KustoLanguageService.prototype.doDocumentFormat = function (document) {
|
|
504
|
+
if (!document) {
|
|
505
|
+
return Promise.resolve([]);
|
|
506
|
+
}
|
|
507
|
+
var startPos = document.positionAt(0);
|
|
508
|
+
var endPos = document.positionAt(document.getText().length);
|
|
509
|
+
var fullDocRange = ls.Range.create(startPos, endPos);
|
|
510
|
+
var formattedDoc = this.getFormattedCommandsInDocumentV2(document).formattedCommands.join('');
|
|
511
|
+
return Promise.resolve([ls.TextEdit.replace(fullDocRange, formattedDoc)]);
|
|
512
|
+
};
|
|
513
|
+
// Method is not triggered, instead doRangeFormat is invoked with the range of the caret's line.
|
|
514
|
+
KustoLanguageService.prototype.doCurrentCommandFormat = function (document, caretPosition) {
|
|
515
|
+
var offset = document.offsetAt(caretPosition);
|
|
516
|
+
var range = this.createRange(document, offset - 1, offset + 1);
|
|
517
|
+
return this.doRangeFormat(document, range);
|
|
518
|
+
};
|
|
519
|
+
KustoLanguageService.prototype.doFolding = function (document) {
|
|
520
|
+
if (!document) {
|
|
521
|
+
return Promise.resolve([]);
|
|
522
|
+
}
|
|
523
|
+
return this.getCommandsInDocument(document).then(function (commands) {
|
|
524
|
+
return commands.map(function (command) {
|
|
525
|
+
// don't count the last empty line as part of the folded range (consider linux, mac, pc newlines)
|
|
526
|
+
if (command.text.endsWith('\r\n')) {
|
|
527
|
+
command.absoluteEnd -= 2;
|
|
528
|
+
}
|
|
529
|
+
else if (command.text.endsWith('\r') || command.text.endsWith('\n')) {
|
|
530
|
+
--command.absoluteEnd;
|
|
531
|
+
}
|
|
532
|
+
var startPosition = document.positionAt(command.absoluteStart);
|
|
533
|
+
var endPosition = document.positionAt(command.absoluteEnd);
|
|
534
|
+
return {
|
|
535
|
+
startLine: startPosition.line,
|
|
536
|
+
startCharacter: startPosition.character,
|
|
537
|
+
endLine: endPosition.line,
|
|
538
|
+
endCharacter: endPosition.character,
|
|
539
|
+
};
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
KustoLanguageService.prototype.getClusterReferences = function (document, cursorOffset) {
|
|
544
|
+
var _a;
|
|
545
|
+
var script = this.parseDocumentV2(document);
|
|
546
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
547
|
+
var clusterReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetClusterReferences();
|
|
548
|
+
if (!clusterReferences) {
|
|
549
|
+
return Promise.resolve([]);
|
|
550
|
+
}
|
|
551
|
+
var newClustersReferences = [];
|
|
552
|
+
var newClustersReferencesSet = new Set(); // used to remove duplicates
|
|
553
|
+
// Keep only unique clusters that aren't already exist in the Global State
|
|
554
|
+
for (var i = 0; i < clusterReferences.Count; i++) {
|
|
555
|
+
var clusterReference = clusterReferences.getItem(i);
|
|
556
|
+
var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterReference.Cluster);
|
|
557
|
+
// ignore duplicates
|
|
558
|
+
if (newClustersReferencesSet.has(clusterHostName)) {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
newClustersReferencesSet.add(clusterHostName);
|
|
562
|
+
// ignore references that are already in the GlobalState.
|
|
563
|
+
if (!this._clustersSetInGlobalState.has(clusterHostName)) {
|
|
564
|
+
newClustersReferences.push({ clusterName: clusterHostName });
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return Promise.resolve(newClustersReferences);
|
|
568
|
+
};
|
|
569
|
+
KustoLanguageService.prototype.getDatabaseReferences = function (document, cursorOffset) {
|
|
570
|
+
var _a;
|
|
571
|
+
var script = this.parseDocumentV2(document);
|
|
572
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
573
|
+
var databasesReferences = (_a = currentBlock === null || currentBlock === void 0 ? void 0 : currentBlock.Service) === null || _a === void 0 ? void 0 : _a.GetDatabaseReferences();
|
|
574
|
+
if (!databasesReferences) {
|
|
575
|
+
return Promise.resolve([]);
|
|
576
|
+
}
|
|
577
|
+
var newDatabasesReferences = [];
|
|
578
|
+
var newDatabasesReferencesSet = new Set();
|
|
579
|
+
for (var i1 = 0; i1 < databasesReferences.Count; i1++) {
|
|
580
|
+
var databaseReference = databasesReferences.getItem(i1);
|
|
581
|
+
var clusterHostName = Kusto.Language.KustoFacts.GetHostName(databaseReference.Cluster);
|
|
582
|
+
// ignore duplicates
|
|
583
|
+
var databaseReferenceUniqueId = this.createDatabaseUniqueName(clusterHostName, databaseReference.Database);
|
|
584
|
+
if (newDatabasesReferencesSet.has(databaseReferenceUniqueId)) {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
newDatabasesReferencesSet.add(databaseReferenceUniqueId);
|
|
588
|
+
// ignore references that are already in the GlobalState.
|
|
589
|
+
var foundInGlobalState = this._nonEmptyDatabaseSetInGlobalState.has(databaseReferenceUniqueId);
|
|
590
|
+
if (!foundInGlobalState) {
|
|
591
|
+
newDatabasesReferences.push({
|
|
592
|
+
databaseName: databaseReference.Database,
|
|
593
|
+
clusterName: databaseReference.Cluster,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return Promise.resolve(newDatabasesReferences);
|
|
598
|
+
};
|
|
599
|
+
KustoLanguageService.prototype.doValidation = function (document, changeIntervals, includeWarnings, includeSuggestions) {
|
|
600
|
+
var _this = this;
|
|
601
|
+
// didn't implement validation for v1.
|
|
602
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
603
|
+
return Promise.resolve([]);
|
|
604
|
+
}
|
|
605
|
+
var script = this.parseDocumentV2(document);
|
|
606
|
+
var blocks = this.toArray(script.Blocks);
|
|
607
|
+
if (changeIntervals.length > 0) {
|
|
608
|
+
blocks = this.getAffectedBlocks(blocks, changeIntervals);
|
|
609
|
+
}
|
|
610
|
+
var diagnostics = blocks
|
|
611
|
+
.map(function (block) {
|
|
612
|
+
// GetDiagnostics returns the errors in the block
|
|
613
|
+
var diagnostics = _this.toArray(block.Service.GetDiagnostics());
|
|
614
|
+
var enableWarnings = includeWarnings !== null && includeWarnings !== void 0 ? includeWarnings : _this._languageSettings.enableQueryWarnings;
|
|
615
|
+
var enableSuggestions = includeSuggestions !== null && includeSuggestions !== void 0 ? includeSuggestions : _this._languageSettings.enableQuerySuggestions;
|
|
616
|
+
if (enableWarnings || enableSuggestions) {
|
|
617
|
+
// Concat Warnings and suggestions to the diagnostics
|
|
618
|
+
var warningAndSuggestionDiagnostics = block.Service.GetAnalyzerDiagnostics(true);
|
|
619
|
+
var filterredDiagnostics = _this.toArray(warningAndSuggestionDiagnostics).filter(function (d) {
|
|
620
|
+
var _a;
|
|
621
|
+
var allowSeverity = (enableWarnings && d.Severity === 'Warning') ||
|
|
622
|
+
(enableSuggestions && d.Severity === 'Suggestion');
|
|
623
|
+
var allowCode = !((_a = _this._languageSettings.disabledDiagnosticCodes) === null || _a === void 0 ? void 0 : _a.includes(d.Code));
|
|
624
|
+
return allowSeverity && allowCode;
|
|
625
|
+
});
|
|
626
|
+
diagnostics = diagnostics.concat(filterredDiagnostics);
|
|
627
|
+
}
|
|
628
|
+
return diagnostics;
|
|
629
|
+
})
|
|
630
|
+
.reduce(function (prev, curr) { return prev.concat(curr); }, []);
|
|
631
|
+
var lsDiagnostics = this.toLsDiagnostics(diagnostics, document);
|
|
632
|
+
return Promise.resolve(lsDiagnostics);
|
|
633
|
+
};
|
|
634
|
+
KustoLanguageService.prototype.getApplyCodeActions = function (document, start, end) {
|
|
635
|
+
var script = this.parseDocumentV2(document);
|
|
636
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
637
|
+
var codeActionInfo = block.Service.GetCodeActions(start, start, 0, null, true, null, new Kusto.Language.Utils.CancellationToken());
|
|
638
|
+
var codeActions = this.toArray(codeActionInfo.Actions);
|
|
639
|
+
// Some code actions are of type "MenuAction". We want to flat them out, to show them seperately.
|
|
640
|
+
var flatCodeActions = [];
|
|
641
|
+
for (var i = 0; i < codeActions.length; i++) {
|
|
642
|
+
flatCodeActions.push.apply(flatCodeActions, this.flattenCodeActions(codeActions[i], null));
|
|
643
|
+
}
|
|
644
|
+
return flatCodeActions;
|
|
645
|
+
};
|
|
646
|
+
KustoLanguageService.prototype.getResultActions = function (document, start, end) {
|
|
647
|
+
var _this = this;
|
|
648
|
+
var script = this.parseDocumentV2(document);
|
|
649
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
650
|
+
var applyCodeActions = this.getApplyCodeActions(document, start, end);
|
|
651
|
+
var resultActionsMap = applyCodeActions
|
|
652
|
+
.map(function (applyCodeAction) {
|
|
653
|
+
var changes = [];
|
|
654
|
+
var codeActionResults = _this.toArray(block.Service.ApplyCodeAction(applyCodeAction, start).Actions);
|
|
655
|
+
var changeTextAction = codeActionResults.find(function (c) { return c instanceof Kusto.Language.Editor.ChangeTextAction; });
|
|
656
|
+
if (changeTextAction) {
|
|
657
|
+
changes = _this.toArray(changeTextAction.Changes).map(function (change) { return ({
|
|
658
|
+
start: change.Start + block.Start,
|
|
659
|
+
deleteLength: change.DeleteLength,
|
|
660
|
+
insertText: change.InsertText,
|
|
661
|
+
}); });
|
|
662
|
+
}
|
|
663
|
+
return { title: applyCodeAction.Title, changes: changes, kind: applyCodeAction.Kind };
|
|
664
|
+
})
|
|
665
|
+
.filter(function (resultAction) { return resultAction.changes.length; });
|
|
666
|
+
return Promise.resolve(resultActionsMap);
|
|
667
|
+
};
|
|
668
|
+
KustoLanguageService.prototype.transformCodeActionTitle = function (currentActionTitle, parentActionTitle) {
|
|
669
|
+
var title = currentActionTitle;
|
|
670
|
+
switch (title) {
|
|
671
|
+
case 'Apply':
|
|
672
|
+
title = 'Apply once';
|
|
673
|
+
break;
|
|
674
|
+
case 'Fix All':
|
|
675
|
+
title = 'Apply to all';
|
|
676
|
+
break;
|
|
677
|
+
case 'Extract Value':
|
|
678
|
+
title = 'Extract value';
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
if (parentActionTitle) {
|
|
682
|
+
// We want to lower case the first character since it's going to be in brackets
|
|
683
|
+
var parentActionTitleLowerCased = parentActionTitle.charAt(0).toUpperCase() + parentActionTitle.slice(1);
|
|
684
|
+
title = "".concat(title, " (").concat(parentActionTitleLowerCased, ")");
|
|
685
|
+
}
|
|
686
|
+
return title;
|
|
687
|
+
};
|
|
688
|
+
KustoLanguageService.prototype.flattenCodeActions = function (codeAction, parentTitle) {
|
|
689
|
+
var applyActions = [];
|
|
690
|
+
if (codeAction instanceof k2.ApplyAction) {
|
|
691
|
+
codeAction.Title = this.transformCodeActionTitle(codeAction.Title, parentTitle);
|
|
692
|
+
applyActions.push(codeAction);
|
|
693
|
+
}
|
|
694
|
+
else if (codeAction instanceof k2.MenuAction) {
|
|
695
|
+
var nestedCodeActions = this.toArray(codeAction.Actions);
|
|
696
|
+
for (var i = 0; i < nestedCodeActions.length; i++) {
|
|
697
|
+
applyActions.push.apply(applyActions, this.flattenCodeActions(nestedCodeActions[i], codeAction.Title));
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return applyActions;
|
|
701
|
+
};
|
|
702
|
+
KustoLanguageService.prototype.toLsDiagnostics = function (diagnostics, document) {
|
|
703
|
+
return diagnostics
|
|
704
|
+
.filter(function (diag) { return diag.HasLocation; })
|
|
705
|
+
.map(function (diag) {
|
|
706
|
+
var start = document.positionAt(diag.Start);
|
|
707
|
+
var end = document.positionAt(diag.Start + diag.Length);
|
|
708
|
+
var range = ls.Range.create(start, end);
|
|
709
|
+
var severity;
|
|
710
|
+
switch (diag.Severity) {
|
|
711
|
+
case 'Suggestion':
|
|
712
|
+
severity = ls.DiagnosticSeverity.Information;
|
|
713
|
+
break;
|
|
714
|
+
case 'Warning':
|
|
715
|
+
severity = ls.DiagnosticSeverity.Warning;
|
|
716
|
+
break;
|
|
717
|
+
default:
|
|
718
|
+
severity = ls.DiagnosticSeverity.Error;
|
|
719
|
+
}
|
|
720
|
+
return ls.Diagnostic.create(range, diag.Message, severity, diag.Code);
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
/**
|
|
724
|
+
* Colorize one or more kusto blocks (a.k.a commands), or just the entire document.
|
|
725
|
+
* Supports multi-cursor editing (colorizes blocks on multiple changes).
|
|
726
|
+
* @param document The document to colorize
|
|
727
|
+
* @param changeIntervals an array containing 0 or more changed intervals. if the array is empty - just colorize the entire row.
|
|
728
|
+
* if the array contains a single change - just color the kusto blocks that wraps this change. If multiple changes are provided,
|
|
729
|
+
* colorize all blocks that intersect these changes.
|
|
730
|
+
* The code will try to only parse once if this is the same command.
|
|
731
|
+
*/
|
|
732
|
+
KustoLanguageService.prototype.doColorization = function (document, changeIntervals) {
|
|
733
|
+
var _this = this;
|
|
734
|
+
if (!document || !this._languageSettings.useSemanticColorization) {
|
|
735
|
+
return Promise.resolve([]);
|
|
736
|
+
}
|
|
737
|
+
// V1 intellisense
|
|
738
|
+
if (!this.isIntellisenseV2()) {
|
|
739
|
+
// Handle specific ranges changes (and not the whole doc)
|
|
740
|
+
if (changeIntervals.length > 0) {
|
|
741
|
+
this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
|
|
742
|
+
var affectedCommands = this.toArray(this._parser.Results).filter(function (command) {
|
|
743
|
+
// a command is affected if it intersects at least on of changed ranges.
|
|
744
|
+
return command // command can be null. we're filtering all nulls in the array.
|
|
745
|
+
? changeIntervals.some(function (_a) {
|
|
746
|
+
var changeStart = _a.start, changeEnd = _a.end;
|
|
747
|
+
// both intervals intersect if either the start or the end of interval A is inside interval B.
|
|
748
|
+
// If we deleted something at the end of a command, the interval will not intersect the current command.
|
|
749
|
+
// so we also want consider affected commands commands the end where the interval begins.
|
|
750
|
+
// hence the + 1.
|
|
751
|
+
return (command.AbsoluteStart >= changeStart && command.AbsoluteStart <= changeEnd) ||
|
|
752
|
+
(changeStart >= command.AbsoluteStart && changeStart <= command.AbsoluteEnd + 1);
|
|
753
|
+
})
|
|
754
|
+
: false;
|
|
755
|
+
});
|
|
756
|
+
// We're not on any command so don't return any classifications.
|
|
757
|
+
// this can happen if we're at the and of the file and deleting empty rows (for example).
|
|
758
|
+
if (!affectedCommands || affectedCommands.length === 0) {
|
|
759
|
+
return Promise.resolve([
|
|
760
|
+
{
|
|
761
|
+
classifications: [],
|
|
762
|
+
absoluteStart: changeIntervals[0].start,
|
|
763
|
+
absoluteEnd: changeIntervals[0].end,
|
|
764
|
+
},
|
|
765
|
+
]);
|
|
766
|
+
}
|
|
767
|
+
var results = affectedCommands.map(function (command) {
|
|
768
|
+
_this.parseTextV1(command.Text, k.ParseMode.TokenizeAllText);
|
|
769
|
+
var k2Classifications = _this.getClassificationsFromParseResult(command.AbsoluteStart);
|
|
770
|
+
var classifications = toClassifiedRange(k2Classifications);
|
|
771
|
+
return {
|
|
772
|
+
classifications: classifications,
|
|
773
|
+
absoluteStart: command.AbsoluteStart,
|
|
774
|
+
absoluteEnd: command.AbsoluteEnd,
|
|
775
|
+
};
|
|
776
|
+
});
|
|
777
|
+
return Promise.resolve(results);
|
|
778
|
+
}
|
|
779
|
+
// Entire document requested
|
|
780
|
+
this.parseDocumentV1(document, k.ParseMode.TokenizeAllText);
|
|
781
|
+
var classifications_1 = this.getClassificationsFromParseResult();
|
|
782
|
+
return Promise.resolve([
|
|
783
|
+
{
|
|
784
|
+
classifications: toClassifiedRange(classifications_1),
|
|
785
|
+
absoluteStart: 0,
|
|
786
|
+
absoluteEnd: document.getText().length,
|
|
787
|
+
},
|
|
788
|
+
]);
|
|
789
|
+
}
|
|
790
|
+
// V2 intellisense
|
|
791
|
+
var script = this.parseDocumentV2(document);
|
|
792
|
+
if (changeIntervals.length > 0) {
|
|
793
|
+
var blocks_1 = this.toArray(script.Blocks);
|
|
794
|
+
var affectedBlocks = this.getAffectedBlocks(blocks_1, changeIntervals);
|
|
795
|
+
var result = affectedBlocks.map(function (block) { return ({
|
|
796
|
+
classifications: toClassifiedRange(_this.toArray(block.Service.GetClassifications(block.Start, block.End).Classifications)),
|
|
797
|
+
absoluteStart: block.Start,
|
|
798
|
+
absoluteEnd: block.End,
|
|
799
|
+
}); });
|
|
800
|
+
return Promise.resolve(result);
|
|
801
|
+
}
|
|
802
|
+
// Entire document requested
|
|
803
|
+
var blocks = this.toArray(script.Blocks);
|
|
804
|
+
var classifications = blocks
|
|
805
|
+
.map(function (block) {
|
|
806
|
+
return _this.toArray(block.Service.GetClassifications(block.Start, block.Length).Classifications);
|
|
807
|
+
})
|
|
808
|
+
.reduce(function (prev, curr) { return prev.concat(curr); }, []);
|
|
809
|
+
return Promise.resolve([
|
|
810
|
+
{
|
|
811
|
+
classifications: toClassifiedRange(classifications),
|
|
812
|
+
absoluteStart: 0,
|
|
813
|
+
absoluteEnd: document.getText().length,
|
|
814
|
+
},
|
|
815
|
+
]);
|
|
816
|
+
};
|
|
817
|
+
KustoLanguageService.prototype.getAffectedBlocks = function (blocks, changeIntervals) {
|
|
818
|
+
return blocks.filter(function (block) {
|
|
819
|
+
// a command is affected if it intersects at least on of changed ranges.
|
|
820
|
+
return block // command can be null. we're filtering all nulls in the array.
|
|
821
|
+
? changeIntervals.some(function (_a) {
|
|
822
|
+
var changeStart = _a.start, changeEnd = _a.end;
|
|
823
|
+
// both intervals intersect if either the start or the end of interval A is inside interval B.
|
|
824
|
+
return (block.Start >= changeStart && block.Start <= changeEnd) ||
|
|
825
|
+
(changeStart >= block.Start && changeStart <= block.End + 1);
|
|
826
|
+
})
|
|
827
|
+
: false;
|
|
828
|
+
});
|
|
829
|
+
};
|
|
830
|
+
KustoLanguageService.prototype.addClusterToSchema = function (document, clusterName, databaseNames) {
|
|
831
|
+
var clusterNameOnly = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
832
|
+
var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterNameOnly);
|
|
833
|
+
if (cluster) {
|
|
834
|
+
// add databases that are not already in the cluster.
|
|
835
|
+
databaseNames
|
|
836
|
+
.filter(function (databaseName) { return !cluster.GetDatabase(databaseName); })
|
|
837
|
+
.map(function (databaseName) {
|
|
838
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
839
|
+
cluster = cluster.AddDatabase(symbol);
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
if (!cluster) {
|
|
843
|
+
var databaseSymbols = databaseNames.map(function (databaseName) {
|
|
844
|
+
var symbol = new sym.DatabaseSymbol.$ctor1(databaseName, undefined, false);
|
|
845
|
+
return symbol;
|
|
846
|
+
});
|
|
847
|
+
var databaseSymbolsList = new (List(sym.DatabaseSymbol).$ctor1)(databaseSymbols);
|
|
848
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterNameOnly, databaseSymbolsList, false);
|
|
849
|
+
}
|
|
850
|
+
this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
851
|
+
this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
|
|
852
|
+
return Promise.resolve();
|
|
853
|
+
};
|
|
854
|
+
KustoLanguageService.prototype.addDatabaseToSchema = function (document, clusterName, databaseSchema) {
|
|
855
|
+
var clusterHostName = Kusto.Language.KustoFacts.GetHostName(clusterName);
|
|
856
|
+
var cluster = this._kustoJsSchemaV2.GetCluster$1(clusterHostName);
|
|
857
|
+
if (!cluster) {
|
|
858
|
+
cluster = new sym.ClusterSymbol.$ctor1(clusterHostName, null, false);
|
|
859
|
+
}
|
|
860
|
+
var databaseSymbol = KustoLanguageService.convertToDatabaseSymbol(databaseSchema);
|
|
861
|
+
cluster = cluster.AddOrUpdateDatabase(databaseSymbol);
|
|
862
|
+
this._kustoJsSchemaV2 = this._kustoJsSchemaV2.AddOrReplaceCluster(cluster);
|
|
863
|
+
this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
|
|
864
|
+
return Promise.resolve();
|
|
865
|
+
};
|
|
866
|
+
KustoLanguageService.prototype.setSchema = function (schema) {
|
|
867
|
+
var _this = this;
|
|
868
|
+
this._schema = schema;
|
|
869
|
+
// We support intellisenseV2 only if the clusterType is "Engine", even if the setting is enabled
|
|
870
|
+
if (this._languageSettings.useIntellisenseV2 && schema && schema.clusterType === 'Engine') {
|
|
871
|
+
var kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
|
|
872
|
+
this._kustoJsSchemaV2 = kustoJsSchemaV2;
|
|
873
|
+
this._script = undefined;
|
|
874
|
+
this._parsePropertiesV2 = undefined;
|
|
875
|
+
}
|
|
876
|
+
// since V2 doesn't support control commands, we're initializing V1 intellisense for both cases and we'll going to use V1 intellisense for control commands.
|
|
877
|
+
return new Promise(function (resolve, reject) {
|
|
878
|
+
var kustoJsSchema = schema ? KustoLanguageService.convertToKustoJsSchema(schema) : undefined;
|
|
879
|
+
_this._kustoJsSchema = kustoJsSchema;
|
|
880
|
+
_this.createRulesProvider(kustoJsSchema, schema.clusterType);
|
|
881
|
+
resolve(undefined);
|
|
882
|
+
});
|
|
883
|
+
};
|
|
884
|
+
KustoLanguageService.prototype.setParameters = function (scalarParameters, tabularParameters) {
|
|
885
|
+
var _a;
|
|
886
|
+
if (!this._languageSettings.useIntellisenseV2 || this._schema.clusterType !== 'Engine') {
|
|
887
|
+
throw new Error('setParameters requires intellisense V2 and Engine cluster');
|
|
888
|
+
}
|
|
889
|
+
this._schema.globalScalarParameters = scalarParameters;
|
|
890
|
+
this._schema.globalTabularParameters = tabularParameters;
|
|
891
|
+
var scalarSymbols = scalarParameters.map(function (param) { return KustoLanguageService.createParameterSymbol(param); });
|
|
892
|
+
var tabularSymbols = tabularParameters.map(function (param) {
|
|
893
|
+
return KustoLanguageService.createTabularParameterSymbol(param);
|
|
894
|
+
});
|
|
895
|
+
this._kustoJsSchemaV2 = this._kustoJsSchemaV2.WithParameters(KustoLanguageService.toBridgeList(__spreadArray(__spreadArray([], scalarSymbols, true), tabularSymbols, true)));
|
|
896
|
+
this._script = (_a = this._script) === null || _a === void 0 ? void 0 : _a.WithGlobals(this._kustoJsSchemaV2);
|
|
897
|
+
return Promise.resolve(undefined);
|
|
898
|
+
};
|
|
899
|
+
/**
|
|
900
|
+
* A combination of normalizeSchema and setSchema
|
|
901
|
+
* @param schema schema json as received from .show schema as json
|
|
902
|
+
* @param clusterConnectionString cluster connection string
|
|
903
|
+
* @param databaseInContextName name of database in context
|
|
904
|
+
*/
|
|
905
|
+
KustoLanguageService.prototype.setSchemaFromShowSchema = function (schema, clusterConnectionString, databaseInContextName, globalScalarParameters, globalTabularParameters) {
|
|
906
|
+
var _this = this;
|
|
907
|
+
return this.normalizeSchema(schema, clusterConnectionString, databaseInContextName).then(function (normalized) {
|
|
908
|
+
return _this.setSchema(__assign(__assign({}, normalized), { globalScalarParameters: globalScalarParameters, globalTabularParameters: globalTabularParameters }));
|
|
909
|
+
});
|
|
910
|
+
};
|
|
911
|
+
/**
|
|
912
|
+
* Converts the result of .show schema as json to a normalized schema used by kusto language service.
|
|
913
|
+
* @param schema result of show schema
|
|
914
|
+
* @param clusterConnectionString cluster connection string`
|
|
915
|
+
* @param databaseInContextName database in context name
|
|
916
|
+
*/
|
|
917
|
+
KustoLanguageService.prototype.normalizeSchema = function (schema, clusterConnectionString, databaseInContextName) {
|
|
918
|
+
var databases = Object.keys(schema.Databases)
|
|
919
|
+
.map(function (key) { return schema.Databases[key]; })
|
|
920
|
+
.map(function (_a) {
|
|
921
|
+
var Name = _a.Name, Tables = _a.Tables, ExternalTables = _a.ExternalTables, MaterializedViews = _a.MaterializedViews, Functions = _a.Functions, MinorVersion = _a.MinorVersion, MajorVersion = _a.MajorVersion;
|
|
922
|
+
return ({
|
|
923
|
+
name: Name,
|
|
924
|
+
minorVersion: MinorVersion,
|
|
925
|
+
majorVersion: MajorVersion,
|
|
926
|
+
tables: [].concat.apply([], [
|
|
927
|
+
[Tables, 'Table'],
|
|
928
|
+
[MaterializedViews, 'MaterializedView'],
|
|
929
|
+
[ExternalTables, 'ExternalTable'],
|
|
930
|
+
]
|
|
931
|
+
.filter(function (_a) {
|
|
932
|
+
var tableContainer = _a[0];
|
|
933
|
+
return tableContainer;
|
|
934
|
+
})
|
|
935
|
+
.map(function (_a) {
|
|
936
|
+
var tableContainer = _a[0], tableEntity = _a[1];
|
|
937
|
+
return Object.values(tableContainer).map(function (_a) {
|
|
938
|
+
var Name = _a.Name, OrderedColumns = _a.OrderedColumns, DocString = _a.DocString;
|
|
939
|
+
return ({
|
|
940
|
+
name: Name,
|
|
941
|
+
docstring: DocString,
|
|
942
|
+
entityType: tableEntity,
|
|
943
|
+
columns: OrderedColumns.map(function (_a) {
|
|
944
|
+
var Name = _a.Name, Type = _a.Type, DocString = _a.DocString, CslType = _a.CslType, Examples = _a.Examples;
|
|
945
|
+
return ({
|
|
946
|
+
name: Name,
|
|
947
|
+
type: CslType,
|
|
948
|
+
docstring: DocString,
|
|
949
|
+
examples: Examples,
|
|
950
|
+
});
|
|
951
|
+
}),
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
})),
|
|
955
|
+
functions: Object.keys(Functions)
|
|
956
|
+
.map(function (key) { return Functions[key]; })
|
|
957
|
+
.map(function (_a) {
|
|
958
|
+
var Name = _a.Name, Body = _a.Body, DocString = _a.DocString, InputParameters = _a.InputParameters;
|
|
959
|
+
return ({
|
|
960
|
+
name: Name,
|
|
961
|
+
body: Body,
|
|
962
|
+
docstring: DocString,
|
|
963
|
+
inputParameters: InputParameters.map(function (inputParam) { return ({
|
|
964
|
+
name: inputParam.Name,
|
|
965
|
+
type: inputParam.Type,
|
|
966
|
+
cslType: inputParam.CslType,
|
|
967
|
+
cslDefaultValue: inputParam.CslDefaultValue,
|
|
968
|
+
columns: inputParam.Columns
|
|
969
|
+
? inputParam.Columns.map(function (col) { return ({
|
|
970
|
+
name: col.Name,
|
|
971
|
+
type: col.Type,
|
|
972
|
+
cslType: col.CslType,
|
|
973
|
+
}); })
|
|
974
|
+
: inputParam.Columns,
|
|
975
|
+
}); }),
|
|
976
|
+
});
|
|
977
|
+
}),
|
|
978
|
+
});
|
|
979
|
+
});
|
|
980
|
+
var result = {
|
|
981
|
+
clusterType: 'Engine',
|
|
982
|
+
cluster: {
|
|
983
|
+
connectionString: clusterConnectionString,
|
|
984
|
+
databases: databases,
|
|
985
|
+
},
|
|
986
|
+
database: databases.filter(function (db) { return db.name === databaseInContextName; })[0],
|
|
987
|
+
};
|
|
988
|
+
return Promise.resolve(result);
|
|
989
|
+
};
|
|
990
|
+
KustoLanguageService.prototype.getSchema = function () {
|
|
991
|
+
return Promise.resolve(this._schema);
|
|
992
|
+
};
|
|
993
|
+
KustoLanguageService.prototype.getCommandInContext = function (document, cursorOffset) {
|
|
994
|
+
return this.isIntellisenseV2()
|
|
995
|
+
? this.getCommandInContextV2(document, cursorOffset)
|
|
996
|
+
: this.getCommandInContextV1(document, cursorOffset);
|
|
997
|
+
};
|
|
998
|
+
KustoLanguageService.prototype.getCommandAndLocationInContext = function (document, cursorOffset) {
|
|
999
|
+
// We are going to remove v1 intellisense. no use to keep parity.
|
|
1000
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1001
|
+
return Promise.resolve(null);
|
|
1002
|
+
}
|
|
1003
|
+
var script = this.parseDocumentV2(document);
|
|
1004
|
+
var block = this.getCurrentCommandV2(script, cursorOffset);
|
|
1005
|
+
if (!block) {
|
|
1006
|
+
return Promise.resolve(null);
|
|
1007
|
+
}
|
|
1008
|
+
var start = document.positionAt(block.Start);
|
|
1009
|
+
var end = document.positionAt(block.End);
|
|
1010
|
+
var location = ls.Location.create(document.uri, ls.Range.create(start, end));
|
|
1011
|
+
var text = block.Text;
|
|
1012
|
+
return Promise.resolve({
|
|
1013
|
+
text: text,
|
|
1014
|
+
location: location,
|
|
1015
|
+
});
|
|
1016
|
+
};
|
|
1017
|
+
KustoLanguageService.prototype.getCommandInContextV1 = function (document, cursorOffset) {
|
|
1018
|
+
this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
|
|
1019
|
+
var command = this.getCurrentCommand(document, cursorOffset);
|
|
1020
|
+
if (!command) {
|
|
1021
|
+
return Promise.resolve(null);
|
|
1022
|
+
}
|
|
1023
|
+
return Promise.resolve(command.Text);
|
|
1024
|
+
};
|
|
1025
|
+
KustoLanguageService.prototype.getCommandInContextV2 = function (document, cursorOffset) {
|
|
1026
|
+
if (!document) {
|
|
1027
|
+
return Promise.resolve(null);
|
|
1028
|
+
}
|
|
1029
|
+
var script = this.parseDocumentV2(document);
|
|
1030
|
+
var block = this.getCurrentCommandV2(script, cursorOffset);
|
|
1031
|
+
if (!block) {
|
|
1032
|
+
return Promise.resolve(null);
|
|
1033
|
+
}
|
|
1034
|
+
// TODO: do we need to do tricks like V1 is doing in this.getCurrentCommand?
|
|
1035
|
+
return Promise.resolve(block.Text);
|
|
1036
|
+
};
|
|
1037
|
+
/**
|
|
1038
|
+
* Return an array of commands in document. each command contains the range and text.
|
|
1039
|
+
*/
|
|
1040
|
+
KustoLanguageService.prototype.getCommandsInDocument = function (document) {
|
|
1041
|
+
if (!document) {
|
|
1042
|
+
return Promise.resolve([]);
|
|
1043
|
+
}
|
|
1044
|
+
return this.isIntellisenseV2()
|
|
1045
|
+
? this.getCommandsInDocumentV2(document)
|
|
1046
|
+
: this.getCommandsInDocumentV1(document);
|
|
1047
|
+
};
|
|
1048
|
+
KustoLanguageService.prototype.getCommandsInDocumentV1 = function (document) {
|
|
1049
|
+
this.parseDocumentV1(document, k.ParseMode.CommandTokensOnly);
|
|
1050
|
+
var commands = this.toArray(this._parser.Results);
|
|
1051
|
+
return Promise.resolve(commands.map(function (_a) {
|
|
1052
|
+
var AbsoluteStart = _a.AbsoluteStart, AbsoluteEnd = _a.AbsoluteEnd, Text = _a.Text;
|
|
1053
|
+
return ({
|
|
1054
|
+
absoluteStart: AbsoluteStart,
|
|
1055
|
+
absoluteEnd: AbsoluteEnd,
|
|
1056
|
+
text: Text,
|
|
1057
|
+
});
|
|
1058
|
+
}));
|
|
1059
|
+
};
|
|
1060
|
+
KustoLanguageService.prototype.toPlacementStyle = function (formatterPlacementStyle) {
|
|
1061
|
+
if (!formatterPlacementStyle) {
|
|
1062
|
+
return undefined;
|
|
1063
|
+
}
|
|
1064
|
+
switch (formatterPlacementStyle) {
|
|
1065
|
+
case 'None':
|
|
1066
|
+
return k2.PlacementStyle.None;
|
|
1067
|
+
case 'NewLine':
|
|
1068
|
+
return k2.PlacementStyle.NewLine;
|
|
1069
|
+
case 'Smart':
|
|
1070
|
+
return k2.PlacementStyle.Smart;
|
|
1071
|
+
default:
|
|
1072
|
+
throw new Error('Unknown PlacementStyle');
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
KustoLanguageService.prototype.getFormattedCommandsInDocumentV2 = function (document, rangeStart, rangeEnd) {
|
|
1076
|
+
var _this = this;
|
|
1077
|
+
var script = this.parseDocumentV2(document);
|
|
1078
|
+
var commands = this.toArray(script.Blocks).filter(function (command) {
|
|
1079
|
+
if (!command.Text || command.Text.trim() == '')
|
|
1080
|
+
return false;
|
|
1081
|
+
if (rangeStart == null || rangeEnd == null)
|
|
1082
|
+
return true;
|
|
1083
|
+
// calculate command end position without \r\n.
|
|
1084
|
+
var commandEnd = command.End;
|
|
1085
|
+
var commandText = command.Text;
|
|
1086
|
+
for (var i = commandText.length - 1; i >= 0; i--) {
|
|
1087
|
+
if (commandText[i] != '\r' && commandText[i] != '\n') {
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
commandEnd--;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (command.Start > rangeStart && command.Start < rangeEnd)
|
|
1095
|
+
return true;
|
|
1096
|
+
if (commandEnd > rangeStart && commandEnd < rangeEnd)
|
|
1097
|
+
return true;
|
|
1098
|
+
if (command.Start <= rangeStart && commandEnd >= rangeEnd)
|
|
1099
|
+
return true;
|
|
1100
|
+
});
|
|
1101
|
+
if (commands.length === 0) {
|
|
1102
|
+
return { formattedCommands: [] };
|
|
1103
|
+
}
|
|
1104
|
+
var formattedCommands = commands.map(function (command) {
|
|
1105
|
+
var _a, _b;
|
|
1106
|
+
var formatterOptions = _this._languageSettings.formatter;
|
|
1107
|
+
var formatter = Kusto.Language.Editor.FormattingOptions.Default.WithIndentationSize((_a = formatterOptions === null || formatterOptions === void 0 ? void 0 : formatterOptions.indentationSize) !== null && _a !== void 0 ? _a : 4)
|
|
1108
|
+
.WithInsertMissingTokens(false)
|
|
1109
|
+
.WithPipeOperatorStyle((_b = _this.toPlacementStyle(formatterOptions === null || formatterOptions === void 0 ? void 0 : formatterOptions.pipeOperatorStyle)) !== null && _b !== void 0 ? _b : k2.PlacementStyle.Smart)
|
|
1110
|
+
.WithSemicolonStyle(Kusto.Language.Editor.PlacementStyle.None)
|
|
1111
|
+
.WithBrackettingStyle(k2.BrackettingStyle.Diagonal);
|
|
1112
|
+
if (rangeStart == null || rangeEnd == null || (rangeStart === command.Start && rangeEnd === command.End)) {
|
|
1113
|
+
var result = command.Service.GetFormattedText(formatter);
|
|
1114
|
+
return result.Text;
|
|
1115
|
+
}
|
|
1116
|
+
return command.Service.GetFormattedText(formatter).Text;
|
|
1117
|
+
});
|
|
1118
|
+
var originalRange = this.createRange(document, commands[0].Start, commands[commands.length - 1].End);
|
|
1119
|
+
return { formattedCommands: formattedCommands, originalRange: originalRange };
|
|
1120
|
+
};
|
|
1121
|
+
KustoLanguageService.prototype.getCommandsInDocumentV2 = function (document) {
|
|
1122
|
+
var script = this.parseDocumentV2(document);
|
|
1123
|
+
var commands = this.toArray(script.Blocks).filter(function (command) { return command.Text.trim() != ''; });
|
|
1124
|
+
return Promise.resolve(commands.map(function (_a) {
|
|
1125
|
+
var Start = _a.Start, End = _a.End, Text = _a.Text;
|
|
1126
|
+
return ({ absoluteStart: Start, absoluteEnd: End, text: Text });
|
|
1127
|
+
}));
|
|
1128
|
+
};
|
|
1129
|
+
KustoLanguageService.prototype.getClientDirective = function (text) {
|
|
1130
|
+
var outParam = { v: null };
|
|
1131
|
+
var isClientDirective = k.CslCommandParser.IsClientDirective(text, outParam);
|
|
1132
|
+
return Promise.resolve({
|
|
1133
|
+
isClientDirective: isClientDirective,
|
|
1134
|
+
directiveWithoutLeadingComments: outParam.v,
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
KustoLanguageService.prototype.getAdminCommand = function (text) {
|
|
1138
|
+
var outParam = { v: null };
|
|
1139
|
+
var isAdminCommand = k.CslCommandParser.IsAdminCommand$1(text, outParam);
|
|
1140
|
+
return Promise.resolve({
|
|
1141
|
+
isAdminCommand: isAdminCommand,
|
|
1142
|
+
adminCommandWithoutLeadingComments: outParam.v,
|
|
1143
|
+
});
|
|
1144
|
+
};
|
|
1145
|
+
KustoLanguageService.prototype.findDefinition = function (document, position) {
|
|
1146
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1147
|
+
return Promise.resolve([]);
|
|
1148
|
+
}
|
|
1149
|
+
var script = this.parseDocumentV2(document);
|
|
1150
|
+
var cursorOffset = document.offsetAt(position);
|
|
1151
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
1152
|
+
if (!currentBlock) {
|
|
1153
|
+
return Promise.resolve([]);
|
|
1154
|
+
}
|
|
1155
|
+
var relatedInfo = currentBlock.Service.GetRelatedElements(document.offsetAt(position));
|
|
1156
|
+
var relatedElements = this.toArray(relatedInfo.Elements);
|
|
1157
|
+
var definition = relatedElements[0];
|
|
1158
|
+
if (!definition) {
|
|
1159
|
+
return Promise.resolve([]);
|
|
1160
|
+
}
|
|
1161
|
+
var start = document.positionAt(definition.Start);
|
|
1162
|
+
var end = document.positionAt(definition.End);
|
|
1163
|
+
var range = ls.Range.create(start, end);
|
|
1164
|
+
var location = ls.Location.create(document.uri, range);
|
|
1165
|
+
return Promise.resolve([location]);
|
|
1166
|
+
};
|
|
1167
|
+
KustoLanguageService.prototype.findReferences = function (document, position) {
|
|
1168
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1169
|
+
return Promise.resolve([]);
|
|
1170
|
+
}
|
|
1171
|
+
var script = this.parseDocumentV2(document);
|
|
1172
|
+
var cursorOffset = document.offsetAt(position);
|
|
1173
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
1174
|
+
if (!currentBlock) {
|
|
1175
|
+
return Promise.resolve([]);
|
|
1176
|
+
}
|
|
1177
|
+
var relatedInfo = currentBlock.Service.GetRelatedElements(document.offsetAt(position));
|
|
1178
|
+
var relatedElements = this.toArray(relatedInfo.Elements);
|
|
1179
|
+
if (!relatedElements || relatedElements.length == 0) {
|
|
1180
|
+
return Promise.resolve([]);
|
|
1181
|
+
}
|
|
1182
|
+
var references = relatedElements.map(function (relatedElement) {
|
|
1183
|
+
var start = document.positionAt(relatedElement.Start);
|
|
1184
|
+
var end = document.positionAt(relatedElement.End);
|
|
1185
|
+
var range = ls.Range.create(start, end);
|
|
1186
|
+
var location = ls.Location.create(document.uri, range);
|
|
1187
|
+
return location;
|
|
1188
|
+
});
|
|
1189
|
+
return Promise.resolve(references);
|
|
1190
|
+
};
|
|
1191
|
+
KustoLanguageService.prototype.getQueryParams = function (document, cursorOffset) {
|
|
1192
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1193
|
+
return Promise.resolve([]);
|
|
1194
|
+
}
|
|
1195
|
+
var script = this.parseDocumentV2(document);
|
|
1196
|
+
var parsedAndAnalyzed = this.parseAndAnalyze(document, cursorOffset);
|
|
1197
|
+
var queryParamStatements = this.toArray(parsedAndAnalyzed.Syntax.GetDescendants(Kusto.Language.Syntax.QueryParametersStatement));
|
|
1198
|
+
if (!queryParamStatements || queryParamStatements.length == 0) {
|
|
1199
|
+
return Promise.resolve([]);
|
|
1200
|
+
}
|
|
1201
|
+
var queryParams = [];
|
|
1202
|
+
queryParamStatements.forEach(function (paramStatement) {
|
|
1203
|
+
paramStatement.WalkElements(function (el) {
|
|
1204
|
+
return el.ReferencedSymbol && el.ReferencedSymbol.Type
|
|
1205
|
+
? queryParams.push({ name: el.ReferencedSymbol.Name, type: el.ReferencedSymbol.Type.Name })
|
|
1206
|
+
: undefined;
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
return Promise.resolve(queryParams);
|
|
1210
|
+
};
|
|
1211
|
+
KustoLanguageService.prototype.getRenderInfo = function (document, cursorOffset) {
|
|
1212
|
+
var _this = this;
|
|
1213
|
+
var parsedAndAnalyzed = this.parseAndAnalyze(document, cursorOffset);
|
|
1214
|
+
if (!parsedAndAnalyzed) {
|
|
1215
|
+
return Promise.resolve(undefined);
|
|
1216
|
+
}
|
|
1217
|
+
var renderStatements = this.toArray(parsedAndAnalyzed.Syntax.GetDescendants(Kusto.Language.Syntax.RenderOperator));
|
|
1218
|
+
if (!renderStatements || renderStatements.length === 0) {
|
|
1219
|
+
return Promise.resolve(undefined);
|
|
1220
|
+
}
|
|
1221
|
+
// assuming a single render statement
|
|
1222
|
+
var renderStatement = renderStatements[0];
|
|
1223
|
+
// Start and end relative to block start.
|
|
1224
|
+
var startOffset = renderStatement.TextStart;
|
|
1225
|
+
var endOffset = renderStatement.End;
|
|
1226
|
+
var visualization = renderStatement.ChartType.ValueText;
|
|
1227
|
+
var withClause = renderStatement.WithClause;
|
|
1228
|
+
if (!withClause) {
|
|
1229
|
+
var info = {
|
|
1230
|
+
options: {
|
|
1231
|
+
visualization: visualization,
|
|
1232
|
+
},
|
|
1233
|
+
location: { startOffset: startOffset, endOffset: endOffset },
|
|
1234
|
+
};
|
|
1235
|
+
return Promise.resolve(info);
|
|
1236
|
+
}
|
|
1237
|
+
var properties = this.toArray(withClause.Properties);
|
|
1238
|
+
var props = properties.reduce(function (prev, property) {
|
|
1239
|
+
var name = property.Element$1.Name.SimpleName;
|
|
1240
|
+
switch (name) {
|
|
1241
|
+
case 'xcolumn':
|
|
1242
|
+
var value = property.Element$1.Expression.ReferencedSymbol.Name;
|
|
1243
|
+
prev[name] = value;
|
|
1244
|
+
break;
|
|
1245
|
+
case 'ycolumns':
|
|
1246
|
+
case 'anomalycolumns':
|
|
1247
|
+
var nameNodes = _this.toArray(property.Element$1.Expression.Names);
|
|
1248
|
+
var values = nameNodes.map(function (nameNode) { return nameNode.Element$1.SimpleName; });
|
|
1249
|
+
prev[name] = values;
|
|
1250
|
+
break;
|
|
1251
|
+
case 'ymin':
|
|
1252
|
+
case 'ymax':
|
|
1253
|
+
var numericVal = parseFloat(property.Element$1.Expression.ConstantValue);
|
|
1254
|
+
prev[name] = numericVal;
|
|
1255
|
+
break;
|
|
1256
|
+
case 'title':
|
|
1257
|
+
case 'xtitle':
|
|
1258
|
+
case 'ytitle':
|
|
1259
|
+
case 'visualization':
|
|
1260
|
+
case 'series':
|
|
1261
|
+
var strVal = property.Element$1.Expression.ConstantValue;
|
|
1262
|
+
prev[name] = strVal;
|
|
1263
|
+
break;
|
|
1264
|
+
case 'xaxis':
|
|
1265
|
+
case 'yaxis':
|
|
1266
|
+
var scale = property.Element$1.Expression.ConstantValue;
|
|
1267
|
+
prev[name] = scale;
|
|
1268
|
+
break;
|
|
1269
|
+
case 'legend':
|
|
1270
|
+
var legend = property.Element$1.Expression.ConstantValue;
|
|
1271
|
+
prev[name] = legend;
|
|
1272
|
+
break;
|
|
1273
|
+
case 'ysplit':
|
|
1274
|
+
var split = property.Element$1.Expression.ConstantValue;
|
|
1275
|
+
prev[name] = split;
|
|
1276
|
+
break;
|
|
1277
|
+
case 'accumulate':
|
|
1278
|
+
var accumulate = property.Element$1.Expression.ConstantValue;
|
|
1279
|
+
prev[name] = accumulate;
|
|
1280
|
+
break;
|
|
1281
|
+
case 'kind':
|
|
1282
|
+
var val = property.Element$1.Expression.ConstantValue;
|
|
1283
|
+
prev[name] = val;
|
|
1284
|
+
break;
|
|
1285
|
+
default:
|
|
1286
|
+
assertNever(name);
|
|
1287
|
+
}
|
|
1288
|
+
return prev;
|
|
1289
|
+
}, {});
|
|
1290
|
+
var renderOptions = __assign({ visualization: visualization }, props);
|
|
1291
|
+
var renderInfo = {
|
|
1292
|
+
options: renderOptions,
|
|
1293
|
+
location: { startOffset: startOffset, endOffset: endOffset },
|
|
1294
|
+
};
|
|
1295
|
+
return Promise.resolve(renderInfo);
|
|
1296
|
+
};
|
|
1297
|
+
KustoLanguageService.prototype.getReferencedSymbols = function (document, offset) {
|
|
1298
|
+
var parsedAndAnalyzed = this.parseAndAnalyze(document, offset);
|
|
1299
|
+
if (!parsedAndAnalyzed) {
|
|
1300
|
+
Promise.resolve([]);
|
|
1301
|
+
}
|
|
1302
|
+
// We take all referenced symbols in the query
|
|
1303
|
+
var referencedSymbols = this.toArray(parsedAndAnalyzed.Syntax.GetDescendants(Kusto.Language.Syntax.Expression))
|
|
1304
|
+
.filter(function (expression) { return expression.ReferencedSymbol !== null; })
|
|
1305
|
+
.map(function (x) { return x.ReferencedSymbol; });
|
|
1306
|
+
var result = referencedSymbols.map(function (sym) {
|
|
1307
|
+
var _a;
|
|
1308
|
+
return ({
|
|
1309
|
+
name: sym.Name,
|
|
1310
|
+
kind: (_a = symbolKindToName[sym.Kind]) !== null && _a !== void 0 ? _a : "".concat(sym.Kind),
|
|
1311
|
+
display: "".concat(sym.Name, " (").concat(sym.AlternateName, ")"),
|
|
1312
|
+
});
|
|
1313
|
+
});
|
|
1314
|
+
return Promise.resolve(result);
|
|
1315
|
+
};
|
|
1316
|
+
KustoLanguageService.prototype.getReferencedGlobalParams = function (document, cursorOffset) {
|
|
1317
|
+
var parsedAndAnalyzed = this.parseAndAnalyze(document, cursorOffset);
|
|
1318
|
+
if (!parsedAndAnalyzed) {
|
|
1319
|
+
Promise.resolve([]);
|
|
1320
|
+
}
|
|
1321
|
+
// We take the ambient parameters
|
|
1322
|
+
var ambientParameters = this.toArray(this._kustoJsSchemaV2.Parameters);
|
|
1323
|
+
// We take all referenced symbols in the query
|
|
1324
|
+
var referencedSymbols = this.toArray(parsedAndAnalyzed.Syntax.GetDescendants(Kusto.Language.Syntax.Expression))
|
|
1325
|
+
.filter(function (expression) { return expression.ReferencedSymbol !== null; })
|
|
1326
|
+
.map(function (x) { return x.ReferencedSymbol; });
|
|
1327
|
+
// The Intersection between them is the ambient parameters that are used in the query.
|
|
1328
|
+
// Note: Ideally we would use Set here (or at least array.Include), but were' compiling down to es2015.
|
|
1329
|
+
var intersection = referencedSymbols.filter(function (referencedSymbol) {
|
|
1330
|
+
return ambientParameters.filter(function (ambientParameter) { return ambientParameter === referencedSymbol; }).length > 0;
|
|
1331
|
+
});
|
|
1332
|
+
var result = intersection.map(function (param) { return ({ name: param.Name, type: param.Type.Name }); });
|
|
1333
|
+
return Promise.resolve(result);
|
|
1334
|
+
};
|
|
1335
|
+
KustoLanguageService.prototype.getGlobalParams = function (document) {
|
|
1336
|
+
if (!this.isIntellisenseV2()) {
|
|
1337
|
+
return Promise.resolve([]);
|
|
1338
|
+
}
|
|
1339
|
+
var params = this.toArray(this._kustoJsSchemaV2.Parameters);
|
|
1340
|
+
var result = params.map(function (param) { return ({ name: param.Name, type: param.Type.Name }); });
|
|
1341
|
+
return Promise.resolve(result);
|
|
1342
|
+
};
|
|
1343
|
+
KustoLanguageService.prototype.doRename = function (document, position, newName) {
|
|
1344
|
+
var _a;
|
|
1345
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1346
|
+
return Promise.resolve(undefined);
|
|
1347
|
+
}
|
|
1348
|
+
var script = this.parseDocumentV2(document);
|
|
1349
|
+
var cursorOffset = document.offsetAt(position);
|
|
1350
|
+
var currentBLock = this.getCurrentCommandV2(script, cursorOffset);
|
|
1351
|
+
if (!currentBLock) {
|
|
1352
|
+
return Promise.resolve(undefined);
|
|
1353
|
+
}
|
|
1354
|
+
var relatedInfo = currentBLock.Service.GetRelatedElements(document.offsetAt(position));
|
|
1355
|
+
var relatedElements = this.toArray(relatedInfo.Elements);
|
|
1356
|
+
var declarations = relatedElements.filter(function (e) { return e.Kind == k2.RelatedElementKind.Declaration; });
|
|
1357
|
+
// A declaration must be one of the elements
|
|
1358
|
+
if (!declarations || declarations.length == 0) {
|
|
1359
|
+
return Promise.resolve(undefined);
|
|
1360
|
+
}
|
|
1361
|
+
var edits = relatedElements.map(function (edit) {
|
|
1362
|
+
var start = document.positionAt(edit.Start);
|
|
1363
|
+
var end = document.positionAt(edit.End);
|
|
1364
|
+
var range = ls.Range.create(start, end);
|
|
1365
|
+
return ls.TextEdit.replace(range, newName);
|
|
1366
|
+
});
|
|
1367
|
+
// create a workspace edit
|
|
1368
|
+
var workspaceEdit = { changes: (_a = {}, _a[document.uri] = edits, _a) };
|
|
1369
|
+
return Promise.resolve(workspaceEdit);
|
|
1370
|
+
};
|
|
1371
|
+
KustoLanguageService.prototype.doHover = function (document, position) {
|
|
1372
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1373
|
+
return Promise.resolve(undefined);
|
|
1374
|
+
}
|
|
1375
|
+
var script = this.parseDocumentV2(document);
|
|
1376
|
+
var cursorOffset = document.offsetAt(position);
|
|
1377
|
+
var currentBLock = this.getCurrentCommandV2(script, cursorOffset);
|
|
1378
|
+
if (!currentBLock) {
|
|
1379
|
+
return Promise.resolve(undefined);
|
|
1380
|
+
}
|
|
1381
|
+
var isSupported = currentBLock.Service.IsFeatureSupported(k2.CodeServiceFeatures.QuickInfo, cursorOffset);
|
|
1382
|
+
if (!isSupported) {
|
|
1383
|
+
return Promise.resolve(undefined);
|
|
1384
|
+
}
|
|
1385
|
+
var quickInfo = currentBLock.Service.GetQuickInfo(cursorOffset);
|
|
1386
|
+
if (!quickInfo || !quickInfo.Items) {
|
|
1387
|
+
return Promise.resolve(undefined);
|
|
1388
|
+
}
|
|
1389
|
+
var items = this.toArray(quickInfo.Items);
|
|
1390
|
+
if (!items) {
|
|
1391
|
+
return Promise.resolve(undefined);
|
|
1392
|
+
}
|
|
1393
|
+
// Errors, Warnings and Suggestions are already shown in getDiagnostics. we don't want them in doHover.
|
|
1394
|
+
items = items.filter(function (item) {
|
|
1395
|
+
return item.Kind !== k2.QuickInfoKind.Error &&
|
|
1396
|
+
item.Kind !== k2.QuickInfoKind.Suggestion &&
|
|
1397
|
+
item.Kind !== k2.QuickInfoKind.Warning;
|
|
1398
|
+
});
|
|
1399
|
+
var itemsText = items.map(function (item) { return item.Text.replace('\n\n', '\n* * *\n'); });
|
|
1400
|
+
// separate items by horizontal line.
|
|
1401
|
+
var text = itemsText.join('\n* * *\n');
|
|
1402
|
+
// Instead of just an empty line between the first line (the signature) and the second line (the description)
|
|
1403
|
+
// add an horizontal line (* * * in markdown) between them.
|
|
1404
|
+
return Promise.resolve({ contents: text });
|
|
1405
|
+
};
|
|
1406
|
+
Object.defineProperty(KustoLanguageService, "dummySchema", {
|
|
1407
|
+
//#region dummy schema for manual testing
|
|
1408
|
+
get: function () {
|
|
1409
|
+
var database = {
|
|
1410
|
+
majorVersion: 0,
|
|
1411
|
+
minorVersion: 0,
|
|
1412
|
+
name: 'Kuskus',
|
|
1413
|
+
tables: [
|
|
1414
|
+
{
|
|
1415
|
+
name: 'KustoLogs',
|
|
1416
|
+
columns: [
|
|
1417
|
+
{
|
|
1418
|
+
name: 'Source',
|
|
1419
|
+
type: 'string',
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
name: 'Timestamp',
|
|
1423
|
+
type: 'datetime',
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
name: 'Directory',
|
|
1427
|
+
type: 'string',
|
|
1428
|
+
},
|
|
1429
|
+
],
|
|
1430
|
+
docstring: 'A dummy description to test that docstring shows as expected when hovering over a table',
|
|
1431
|
+
},
|
|
1432
|
+
],
|
|
1433
|
+
functions: [
|
|
1434
|
+
{
|
|
1435
|
+
name: 'HowBig',
|
|
1436
|
+
inputParameters: [
|
|
1437
|
+
{
|
|
1438
|
+
name: 'T',
|
|
1439
|
+
columns: [
|
|
1440
|
+
{
|
|
1441
|
+
name: 'Timestamp',
|
|
1442
|
+
type: 'System.DateTime',
|
|
1443
|
+
cslType: 'datetime',
|
|
1444
|
+
},
|
|
1445
|
+
],
|
|
1446
|
+
},
|
|
1447
|
+
],
|
|
1448
|
+
docstring: 'A dummy description to test that docstring shows as expected when hovering over a function',
|
|
1449
|
+
body: "{\r\n union \r\n (T | count | project V='Volume', Metric = strcat(Count/1e9, ' Billion records')),\r\n (T | summarize FirstRecord=min(Timestamp)| project V='Volume', Metric = strcat(toint((now()-FirstRecord)/1d), ' Days of data (from: ', format_datetime(FirstRecord, 'yyyy-MM-dd'),')')),\r\n (T | where Timestamp > ago(1h) | count | project V='Velocity', Metric = strcat(Count/1e6, ' Million records / hour')),\r\n (T | summarize Latency=now()-max(Timestamp) | project V='Velocity', Metric = strcat(Latency / 1sec, ' seconds latency')),\r\n (T | take 1 | project V='Variety', Metric=tostring(pack_all()))\r\n | order by V \r\n}",
|
|
1450
|
+
},
|
|
1451
|
+
{
|
|
1452
|
+
name: 'FindCIDPast24h',
|
|
1453
|
+
inputParameters: [
|
|
1454
|
+
{
|
|
1455
|
+
name: 'clientActivityId',
|
|
1456
|
+
type: 'System.String',
|
|
1457
|
+
cslType: 'string',
|
|
1458
|
+
},
|
|
1459
|
+
],
|
|
1460
|
+
body: '{ KustoLogs | where Timestamp > now(-1d) | where ClientActivityId == clientActivityId} ',
|
|
1461
|
+
},
|
|
1462
|
+
],
|
|
1463
|
+
};
|
|
1464
|
+
var languageServiceSchema = {
|
|
1465
|
+
clusterType: 'Engine',
|
|
1466
|
+
cluster: {
|
|
1467
|
+
connectionString: 'https://kuskus.kusto.windows.net;fed=true',
|
|
1468
|
+
databases: [database],
|
|
1469
|
+
},
|
|
1470
|
+
database: database,
|
|
1471
|
+
};
|
|
1472
|
+
return languageServiceSchema;
|
|
1473
|
+
},
|
|
1474
|
+
enumerable: false,
|
|
1475
|
+
configurable: true
|
|
1476
|
+
});
|
|
1477
|
+
//#endregion
|
|
1478
|
+
KustoLanguageService.convertToEntityDataType = function (kustoType) { };
|
|
1479
|
+
/**
|
|
1480
|
+
* We do not want to expose Bridge.Net generated schema, so we expose a cleaner javascript schema.
|
|
1481
|
+
* Here it gets converted to the bridge.Net schema
|
|
1482
|
+
* @param schema Language Service schema
|
|
1483
|
+
*/
|
|
1484
|
+
KustoLanguageService.convertToKustoJsSchema = function (schema) {
|
|
1485
|
+
switch (schema.clusterType) {
|
|
1486
|
+
case 'Engine':
|
|
1487
|
+
var currentDatabaseName_1 = schema.database ? schema.database.name : undefined;
|
|
1488
|
+
var kCluster = new k.KustoIntelliSenseClusterEntity();
|
|
1489
|
+
var kDatabaseInContext_1 = undefined;
|
|
1490
|
+
kCluster.ConnectionString = schema.cluster.connectionString;
|
|
1491
|
+
var databases_1 = [];
|
|
1492
|
+
schema.cluster.databases.forEach(function (database) {
|
|
1493
|
+
var kDatabase = new k.KustoIntelliSenseDatabaseEntity();
|
|
1494
|
+
kDatabase.Name = database.name;
|
|
1495
|
+
var tables = [];
|
|
1496
|
+
database.tables.forEach(function (table) {
|
|
1497
|
+
var kTable = new k.KustoIntelliSenseTableEntity();
|
|
1498
|
+
kTable.Name = table.name;
|
|
1499
|
+
var cols = [];
|
|
1500
|
+
table.columns.forEach(function (column) {
|
|
1501
|
+
var kColumn = new k.KustoIntelliSenseColumnEntity();
|
|
1502
|
+
kColumn.Name = column.name;
|
|
1503
|
+
kColumn.TypeCode = k.EntityDataType[getEntityDataTypeFromCslType(column.type)];
|
|
1504
|
+
cols.push(kColumn);
|
|
1505
|
+
});
|
|
1506
|
+
kTable.Columns = new Bridge.ArrayEnumerable(cols);
|
|
1507
|
+
tables.push(kTable);
|
|
1508
|
+
});
|
|
1509
|
+
var functions = [];
|
|
1510
|
+
database.functions.forEach(function (fn) {
|
|
1511
|
+
var kFunction = new k.KustoIntelliSenseFunctionEntity();
|
|
1512
|
+
(kFunction.Name = fn.name),
|
|
1513
|
+
(kFunction.CallName = s.getCallName(fn)),
|
|
1514
|
+
(kFunction.Expression = s.getExpression(fn)),
|
|
1515
|
+
functions.push(kFunction);
|
|
1516
|
+
});
|
|
1517
|
+
kDatabase.Tables = new Bridge.ArrayEnumerable(tables);
|
|
1518
|
+
kDatabase.Functions = new Bridge.ArrayEnumerable(functions);
|
|
1519
|
+
databases_1.push(kDatabase);
|
|
1520
|
+
if (database.name == currentDatabaseName_1) {
|
|
1521
|
+
kDatabaseInContext_1 = kDatabase;
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
kCluster.Databases = new Bridge.ArrayEnumerable(databases_1);
|
|
1525
|
+
var kSchema = new k.KustoIntelliSenseQuerySchema(kCluster, kDatabaseInContext_1);
|
|
1526
|
+
return kSchema;
|
|
1527
|
+
case 'ClusterManager':
|
|
1528
|
+
var accounts = schema.accounts.map(function (account) {
|
|
1529
|
+
var kAccount = new k.KustoIntelliSenseAccountEntity();
|
|
1530
|
+
kAccount.Name = account;
|
|
1531
|
+
return kAccount;
|
|
1532
|
+
});
|
|
1533
|
+
var services = schema.services.map(function (service) {
|
|
1534
|
+
var kService = new k.KustoIntelliSenseServiceEntity();
|
|
1535
|
+
kService.Name = service;
|
|
1536
|
+
return kService;
|
|
1537
|
+
});
|
|
1538
|
+
var connectionString = schema.connectionString;
|
|
1539
|
+
var result = {
|
|
1540
|
+
accounts: accounts,
|
|
1541
|
+
services: services,
|
|
1542
|
+
connectionString: connectionString,
|
|
1543
|
+
};
|
|
1544
|
+
return result;
|
|
1545
|
+
case 'DataManagement':
|
|
1546
|
+
return undefined;
|
|
1547
|
+
default:
|
|
1548
|
+
return assertNever(schema);
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
/**
|
|
1552
|
+
* Returns something like '(x: string, y: datetime)'
|
|
1553
|
+
* @param params scalar parameters
|
|
1554
|
+
*/
|
|
1555
|
+
KustoLanguageService.scalarParametersToSignature = function (params) {
|
|
1556
|
+
var signatureWithoutParens = params.map(function (param) { return "".concat(param.name, ": ").concat(param.cslType); }).join(', ');
|
|
1557
|
+
return "(".concat(signatureWithoutParens, ")");
|
|
1558
|
+
};
|
|
1559
|
+
/**
|
|
1560
|
+
* Returns something like '(x: string, T: (y: int))'
|
|
1561
|
+
* @param params input parameters (tabular or scalar)
|
|
1562
|
+
*/
|
|
1563
|
+
KustoLanguageService.inputParameterToSignature = function (params) {
|
|
1564
|
+
var _this = this;
|
|
1565
|
+
var signatureWithoutParens = params
|
|
1566
|
+
.map(function (param) {
|
|
1567
|
+
if (param.columns) {
|
|
1568
|
+
var tableSignature = _this.scalarParametersToSignature(param.columns);
|
|
1569
|
+
return "".concat(param.name, ": ").concat(tableSignature);
|
|
1570
|
+
}
|
|
1571
|
+
else {
|
|
1572
|
+
return "".concat(param.name, ": ").concat(param.cslType);
|
|
1573
|
+
}
|
|
1574
|
+
})
|
|
1575
|
+
.join(', ');
|
|
1576
|
+
return "(".concat(signatureWithoutParens, ")");
|
|
1577
|
+
};
|
|
1578
|
+
/**
|
|
1579
|
+
* converts a function definition to a let statement.
|
|
1580
|
+
* @param fn function
|
|
1581
|
+
*/
|
|
1582
|
+
KustoLanguageService.toLetStatement = function (fn) {
|
|
1583
|
+
var signature = this.inputParameterToSignature(fn.inputParameters);
|
|
1584
|
+
return "let ".concat(fn.name, " = ").concat(signature, " ").concat(fn.body);
|
|
1585
|
+
};
|
|
1586
|
+
KustoLanguageService.createColumnSymbol = function (col) {
|
|
1587
|
+
return new sym.ColumnSymbol(col.name, sym.ScalarTypes.GetSymbol(getCslTypeNameFromClrType(col.type)), col.docstring, null, null, col.examples ? KustoLanguageService.toBridgeList(col.examples) : null);
|
|
1588
|
+
};
|
|
1589
|
+
KustoLanguageService.createParameterSymbol = function (param) {
|
|
1590
|
+
var paramSymbol = Kusto.Language.Symbols.ScalarTypes.GetSymbol(getCslTypeNameFromClrType(param.type));
|
|
1591
|
+
return new sym.ParameterSymbol(param.name, paramSymbol, null);
|
|
1592
|
+
};
|
|
1593
|
+
KustoLanguageService.createTabularParameterSymbol = function (param) {
|
|
1594
|
+
var columnSymbols = param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); });
|
|
1595
|
+
var para = new Kusto.Language.Symbols.TableSymbol.$ctor4(param.name, columnSymbols);
|
|
1596
|
+
return new sym.ParameterSymbol(param.name, para, param.docstring);
|
|
1597
|
+
};
|
|
1598
|
+
KustoLanguageService.createParameter = function (param) {
|
|
1599
|
+
if (!param.columns) {
|
|
1600
|
+
var paramSymbol = Kusto.Language.Symbols.ScalarTypes.GetSymbol(getCslTypeNameFromClrType(param.type));
|
|
1601
|
+
var expression = param.cslDefaultValue && typeof param.cslDefaultValue === 'string'
|
|
1602
|
+
? parsing.QueryParser.ParseLiteral$1(param.cslDefaultValue)
|
|
1603
|
+
: undefined;
|
|
1604
|
+
return new sym.Parameter.$ctor3(param.name, paramSymbol, null, null, null, false, null, 1, 1, expression, null);
|
|
1605
|
+
}
|
|
1606
|
+
if (param.columns.length == 0) {
|
|
1607
|
+
return new sym.Parameter.ctor(param.name, sym.ParameterTypeKind.Tabular, sym.ArgumentKind.Expression, null, null, false, null, 1, 1, null, null);
|
|
1608
|
+
}
|
|
1609
|
+
var argumentType = new sym.TableSymbol.ctor(param.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); }));
|
|
1610
|
+
return new sym.Parameter.$ctor2(param.name, argumentType);
|
|
1611
|
+
};
|
|
1612
|
+
KustoLanguageService.convertToDatabaseSymbol = function (db) {
|
|
1613
|
+
var createFunctionSymbol = function (fn) {
|
|
1614
|
+
var parameters = fn.inputParameters.map(function (param) {
|
|
1615
|
+
return KustoLanguageService.createParameter(param);
|
|
1616
|
+
});
|
|
1617
|
+
// TODO: handle outputColumns (right now it doesn't seem to be implemented for any function).
|
|
1618
|
+
return new sym.FunctionSymbol.$ctor14(fn.name, fn.body, KustoLanguageService.toBridgeList(parameters), fn.docstring);
|
|
1619
|
+
};
|
|
1620
|
+
var createTableSymbol = function (tbl) {
|
|
1621
|
+
var _a;
|
|
1622
|
+
var columnSymbols = tbl.columns.map(function (col) { return KustoLanguageService.createColumnSymbol(col); });
|
|
1623
|
+
var symbol = new sym.TableSymbol.$ctor4(tbl.name, columnSymbols);
|
|
1624
|
+
symbol.Description = tbl.docstring;
|
|
1625
|
+
switch (tbl.entityType) {
|
|
1626
|
+
case 'MaterializedViewTable':
|
|
1627
|
+
var mvQuery = (_a = tbl.mvQuery) !== null && _a !== void 0 ? _a : null;
|
|
1628
|
+
symbol = new sym.MaterializedViewSymbol.$ctor2(tbl.name, symbol.Columns, mvQuery, tbl.docstring);
|
|
1629
|
+
symbol = symbol.WithIsMaterializedView(true);
|
|
1630
|
+
break;
|
|
1631
|
+
case 'ExternalTable':
|
|
1632
|
+
symbol = symbol.WithIsExternal(true);
|
|
1633
|
+
break;
|
|
1634
|
+
default:
|
|
1635
|
+
}
|
|
1636
|
+
return symbol;
|
|
1637
|
+
};
|
|
1638
|
+
var createDatabaseSymbol = function (db) {
|
|
1639
|
+
var tableSymbols = db.tables ? db.tables.map(function (tbl) { return createTableSymbol(tbl); }) : [];
|
|
1640
|
+
var functionSymbols = db.functions ? db.functions.map(function (fun) { return createFunctionSymbol(fun); }) : [];
|
|
1641
|
+
return new sym.DatabaseSymbol.ctor(db.name, tableSymbols.concat(functionSymbols));
|
|
1642
|
+
};
|
|
1643
|
+
var databaseSymbol = createDatabaseSymbol(db);
|
|
1644
|
+
return databaseSymbol;
|
|
1645
|
+
};
|
|
1646
|
+
KustoLanguageService.prototype.convertToKustoJsSchemaV2 = function (schema) {
|
|
1647
|
+
var _a, _b;
|
|
1648
|
+
var cached = this._schemaCache[schema.cluster.connectionString];
|
|
1649
|
+
// create a cache entry for the cluster if non yet exists.
|
|
1650
|
+
if (!cached) {
|
|
1651
|
+
this._schemaCache[schema.cluster.connectionString] = {};
|
|
1652
|
+
cached = this._schemaCache[schema.cluster.connectionString];
|
|
1653
|
+
}
|
|
1654
|
+
// Remove deleted databases from cache
|
|
1655
|
+
var schemaDbLookup = schema.cluster.databases.reduce(function (prev, curr) { return (prev[curr.name] = curr); }, {});
|
|
1656
|
+
Object.keys(cached).map(function (dbName) {
|
|
1657
|
+
if (!schemaDbLookup[dbName]) {
|
|
1658
|
+
delete cached.dbName;
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
var globalState = GlobalState.Default;
|
|
1662
|
+
var currentDatabaseName = schema.database ? schema.database.name : undefined;
|
|
1663
|
+
var databaseInContext = undefined;
|
|
1664
|
+
// Update out-of-data databases to cache
|
|
1665
|
+
var databases = schema.cluster.databases.map(function (db) {
|
|
1666
|
+
var shouldIncludeFunctions = db.name === currentDatabaseName;
|
|
1667
|
+
var cachedDb = cached[db.name];
|
|
1668
|
+
// This is an older version than we have, or we need to parse functions.
|
|
1669
|
+
if (!cachedDb ||
|
|
1670
|
+
cachedDb.database.majorVersion < db.majorVersion ||
|
|
1671
|
+
(shouldIncludeFunctions && !cachedDb.includesFunctions)) {
|
|
1672
|
+
// only add functions for the database in context (it's very time consuming)
|
|
1673
|
+
var databaseSymbol_1 = KustoLanguageService.convertToDatabaseSymbol(db);
|
|
1674
|
+
cached[db.name] = { database: db, symbol: databaseSymbol_1, includesFunctions: shouldIncludeFunctions };
|
|
1675
|
+
}
|
|
1676
|
+
var databaseSymbol = cached[db.name].symbol;
|
|
1677
|
+
if (db.name === currentDatabaseName) {
|
|
1678
|
+
databaseInContext = databaseSymbol;
|
|
1679
|
+
}
|
|
1680
|
+
return databaseSymbol;
|
|
1681
|
+
});
|
|
1682
|
+
// Replace new URL due to polyfill issue in IE
|
|
1683
|
+
// const hostname = new URL(schema.cluster.connectionString.split(';')[0]).hostname;
|
|
1684
|
+
var hostname = schema.cluster.connectionString.match(/(.*\/\/)?([^\/;]*)/)[2];
|
|
1685
|
+
var clusterName = hostname.split('.')[0];
|
|
1686
|
+
var clusterSymbol = new sym.ClusterSymbol.ctor(clusterName, databases);
|
|
1687
|
+
globalState = globalState.WithCluster(clusterSymbol);
|
|
1688
|
+
if (databaseInContext) {
|
|
1689
|
+
globalState = globalState.WithDatabase(databaseInContext);
|
|
1690
|
+
}
|
|
1691
|
+
// Inject global scalar parameters to global scope.
|
|
1692
|
+
var scalarParameters = ((_a = schema.globalScalarParameters) !== null && _a !== void 0 ? _a : []).map(function (param) {
|
|
1693
|
+
return KustoLanguageService.createParameterSymbol(param);
|
|
1694
|
+
});
|
|
1695
|
+
// Inject global tabular parameters to global scope.
|
|
1696
|
+
var tabularParameters = ((_b = schema.globalTabularParameters) !== null && _b !== void 0 ? _b : []).map(function (param) {
|
|
1697
|
+
return KustoLanguageService.createTabularParameterSymbol(param);
|
|
1698
|
+
});
|
|
1699
|
+
if (tabularParameters.length || scalarParameters.length) {
|
|
1700
|
+
globalState = globalState.WithParameters(KustoLanguageService.toBridgeList(__spreadArray(__spreadArray([], scalarParameters, true), tabularParameters, true)));
|
|
1701
|
+
}
|
|
1702
|
+
return globalState;
|
|
1703
|
+
};
|
|
1704
|
+
KustoLanguageService.prototype.getClassificationsFromParseResult = function (offset) {
|
|
1705
|
+
var _this = this;
|
|
1706
|
+
if (offset === void 0) { offset = 0; }
|
|
1707
|
+
var classifications = this.toArray(this._parser.Results)
|
|
1708
|
+
.map(function (command) { return _this.toArray(command.Tokens); })
|
|
1709
|
+
.reduce(function (prev, curr) { return prev.concat(curr); }, [])
|
|
1710
|
+
.map(function (cslCommandToken) {
|
|
1711
|
+
var range = new k2.ClassifiedRange(_this.tokenKindToClassificationKind(cslCommandToken.TokenKind), cslCommandToken.AbsoluteStart + offset, cslCommandToken.Length);
|
|
1712
|
+
return range;
|
|
1713
|
+
});
|
|
1714
|
+
return classifications;
|
|
1715
|
+
};
|
|
1716
|
+
/**
|
|
1717
|
+
* trim trailing newlines from range
|
|
1718
|
+
*/
|
|
1719
|
+
KustoLanguageService.trimTrailingNewlineFromRange = function (textInRange, rangeStartOffset, document, range) {
|
|
1720
|
+
var currentIndex = textInRange.length - 1;
|
|
1721
|
+
while (textInRange[currentIndex] === '\r' || textInRange[currentIndex] === '\n') {
|
|
1722
|
+
--currentIndex;
|
|
1723
|
+
}
|
|
1724
|
+
var newEndOffset = rangeStartOffset + currentIndex + 1;
|
|
1725
|
+
var newEndPosition = document.positionAt(newEndOffset);
|
|
1726
|
+
var newRange = ls.Range.create(range.start, newEndPosition);
|
|
1727
|
+
return newRange;
|
|
1728
|
+
};
|
|
1729
|
+
/**
|
|
1730
|
+
* Maps numbers to strings, such that if a>b numerically, f(a)>f(b) lexicographically.
|
|
1731
|
+
* 1 -> "a", 26 -> "z", 27 -> "za", 28 -> "zb", 52 -> "zz", 53 ->"zza"
|
|
1732
|
+
* @param order - The number to be converted to a sorting-string. order should start at 1.
|
|
1733
|
+
* @returns A string repenting the order.
|
|
1734
|
+
*/
|
|
1735
|
+
KustoLanguageService.prototype.getSortText = function (order) {
|
|
1736
|
+
if (order <= 0) {
|
|
1737
|
+
throw new RangeError("order should be a number >= 1. instead got ".concat(order));
|
|
1738
|
+
}
|
|
1739
|
+
var sortText = '';
|
|
1740
|
+
var numCharacters = 26; // "z" - "a" + 1;
|
|
1741
|
+
var div = Math.floor(order / numCharacters);
|
|
1742
|
+
for (var i = 0; i < div; ++i) {
|
|
1743
|
+
sortText += 'z';
|
|
1744
|
+
}
|
|
1745
|
+
var reminder = order % numCharacters;
|
|
1746
|
+
if (reminder > 0) {
|
|
1747
|
+
sortText += String.fromCharCode(96 + reminder);
|
|
1748
|
+
}
|
|
1749
|
+
return sortText;
|
|
1750
|
+
};
|
|
1751
|
+
/**
|
|
1752
|
+
* ParseTextV1 parses the given text with the given parse mode.
|
|
1753
|
+
* Additionally - it will make sure not to provide rules provider for non-engine clusters
|
|
1754
|
+
* since the only rules provider parse can handle is the engine's. It will try to look for function
|
|
1755
|
+
* definitions to colorize and will throw since they're not there.
|
|
1756
|
+
* @param text
|
|
1757
|
+
* @param parseMode
|
|
1758
|
+
*/
|
|
1759
|
+
KustoLanguageService.prototype.parseTextV1 = function (text, parseMode) {
|
|
1760
|
+
this._parser.Parse(this._schema.clusterType === 'Engine' ? this._rulesProvider : null, text, parseMode);
|
|
1761
|
+
};
|
|
1762
|
+
KustoLanguageService.prototype.parseDocumentV1 = function (document, parseMode) {
|
|
1763
|
+
// already parsed a later version, or better parse mode for this uri
|
|
1764
|
+
if (this._parsePropertiesV1 &&
|
|
1765
|
+
!this._parsePropertiesV1.isParseNeeded(document, this._rulesProvider, parseMode)) {
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
this.parseTextV1(document.getText(), parseMode);
|
|
1769
|
+
this._parsePropertiesV1 = new ParseProperties(document.version, document.uri, this._rulesProvider, parseMode);
|
|
1770
|
+
};
|
|
1771
|
+
KustoLanguageService.prototype.parseDocumentV2 = function (document) {
|
|
1772
|
+
if (this._parsePropertiesV2 && !this._parsePropertiesV2.isParseNeeded(document, this._rulesProvider)) {
|
|
1773
|
+
return this._script;
|
|
1774
|
+
}
|
|
1775
|
+
if (!this._script) {
|
|
1776
|
+
this._script = k2.CodeScript.From$1(document.getText(), this._kustoJsSchemaV2);
|
|
1777
|
+
}
|
|
1778
|
+
else {
|
|
1779
|
+
this._script = this._script.WithText(document.getText());
|
|
1780
|
+
}
|
|
1781
|
+
this._parsePropertiesV2 = new ParseProperties(document.version, document.uri);
|
|
1782
|
+
return this._script;
|
|
1783
|
+
};
|
|
1784
|
+
/**
|
|
1785
|
+
* Return the CslCommand that wraps the caret location, or undefined if caret is outside any command
|
|
1786
|
+
* @param document the document to extract the current command from
|
|
1787
|
+
* @param caretAbsolutePosition absolute caret position
|
|
1788
|
+
*/
|
|
1789
|
+
KustoLanguageService.prototype.getCurrentCommand = function (document, caretAbsolutePosition) {
|
|
1790
|
+
var commands = this.toArray(this._parser.Results);
|
|
1791
|
+
var command = commands.filter(function (command) { return command.AbsoluteStart <= caretAbsolutePosition && command.AbsoluteEnd >= caretAbsolutePosition; })[0];
|
|
1792
|
+
// There is an edge case when cursor appears at the end of the command
|
|
1793
|
+
// which is not yet considered to be part of the parsed command (therefore: +1 for the AbsoluteEdit property)
|
|
1794
|
+
if (!command) {
|
|
1795
|
+
command = commands.filter(function (command) {
|
|
1796
|
+
return command.AbsoluteStart <= caretAbsolutePosition && command.AbsoluteEnd + 1 >= caretAbsolutePosition;
|
|
1797
|
+
})[0];
|
|
1798
|
+
// If we have 2 newlines in the end of the text the cursor is _probably_ at the end of the text
|
|
1799
|
+
// which this means that we're not actually standing on any command. Thus return null.
|
|
1800
|
+
if (!command || command.Text.endsWith('\r\n\r\n')) {
|
|
1801
|
+
return null;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
return command;
|
|
1805
|
+
};
|
|
1806
|
+
KustoLanguageService.prototype.getCurrentCommandV2 = function (script, offset) {
|
|
1807
|
+
var block = script.GetBlockAtPosition(offset);
|
|
1808
|
+
return block;
|
|
1809
|
+
};
|
|
1810
|
+
KustoLanguageService.prototype.getTextToInsert = function (rule, option) {
|
|
1811
|
+
var beforeApplyInfo = rule.GetBeforeApplyInfo(option.Value);
|
|
1812
|
+
var afterApplyInfo = rule.GetAfterApplyInfo(option.Value);
|
|
1813
|
+
// this is the basic text to be inserted,
|
|
1814
|
+
// but we still need to figure out where the cursor will end up after completion is applied.
|
|
1815
|
+
var insertText = beforeApplyInfo.Text || '' + option.Value + afterApplyInfo.Text || '';
|
|
1816
|
+
var insertTextFormat = ls.InsertTextFormat.PlainText;
|
|
1817
|
+
var snippetFinalTabStop = '$0';
|
|
1818
|
+
if (afterApplyInfo.OffsetToken && afterApplyInfo.OffsetPosition) {
|
|
1819
|
+
var tokenOffset = insertText.indexOf(afterApplyInfo.OffsetToken);
|
|
1820
|
+
if (tokenOffset >= 0) {
|
|
1821
|
+
insertText = this.insertToString(insertText, snippetFinalTabStop, tokenOffset - insertText.length + afterApplyInfo.OffsetPosition);
|
|
1822
|
+
insertTextFormat = ls.InsertTextFormat.Snippet;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
else if (afterApplyInfo.OffsetPosition) {
|
|
1826
|
+
// We only handle negative offsets
|
|
1827
|
+
insertText = this.insertToString(insertText, snippetFinalTabStop, afterApplyInfo.OffsetPosition);
|
|
1828
|
+
insertTextFormat = ls.InsertTextFormat.Snippet;
|
|
1829
|
+
}
|
|
1830
|
+
return { insertText: insertText, insertTextFormat: insertTextFormat };
|
|
1831
|
+
};
|
|
1832
|
+
/**
|
|
1833
|
+
* create a new string with stringToInsert inserted at offsetFromEnd in originalString.
|
|
1834
|
+
* @param originalString string to insert to
|
|
1835
|
+
* @param stringToInsert string to insert
|
|
1836
|
+
* @param offsetFromEnd a negative number that will represent offset to the left. 0 means simple concat
|
|
1837
|
+
*/
|
|
1838
|
+
KustoLanguageService.prototype.insertToString = function (originalString, stringToInsert, offsetFromEnd) {
|
|
1839
|
+
var index = originalString.length + offsetFromEnd;
|
|
1840
|
+
if (offsetFromEnd >= 0 || index < 0) {
|
|
1841
|
+
return originalString; // Cannot insert before or after the string
|
|
1842
|
+
}
|
|
1843
|
+
var before = originalString.substring(0, index);
|
|
1844
|
+
var after = originalString.substring(index);
|
|
1845
|
+
return before + stringToInsert + after;
|
|
1846
|
+
};
|
|
1847
|
+
KustoLanguageService.prototype.getCommandWithoutLastWord = function (text) {
|
|
1848
|
+
var lastWordRegex = XRegExp('[\\w_]*$', 's');
|
|
1849
|
+
return text.replace(lastWordRegex, '');
|
|
1850
|
+
};
|
|
1851
|
+
KustoLanguageService.prototype.createRulesProvider = function (schema, clusterType) {
|
|
1852
|
+
var queryParameters = new (List(String))();
|
|
1853
|
+
var availableClusters = new (List(String))();
|
|
1854
|
+
this._parser = new k.CslCommandParser();
|
|
1855
|
+
if (clusterType == 'Engine') {
|
|
1856
|
+
var engineSchema = schema;
|
|
1857
|
+
this._rulesProvider =
|
|
1858
|
+
this._languageSettings && this._languageSettings.includeControlCommands
|
|
1859
|
+
? new k.CslIntelliSenseRulesProvider.$ctor1(engineSchema.Cluster, engineSchema, queryParameters, availableClusters, null, true, true)
|
|
1860
|
+
: new k.CslQueryIntelliSenseRulesProvider.$ctor1(engineSchema.Cluster, engineSchema, queryParameters, availableClusters, null, null, null);
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
if (clusterType === 'DataManagement') {
|
|
1864
|
+
this._rulesProvider = new k.DataManagerIntelliSenseRulesProvider(null);
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
// This is a cluster manger
|
|
1868
|
+
var _a = schema, accounts = _a.accounts, services = _a.services, connectionString = _a.connectionString;
|
|
1869
|
+
new k.KustoIntelliSenseAccountEntity();
|
|
1870
|
+
new k.KustoIntelliSenseServiceEntity();
|
|
1871
|
+
this._rulesProvider = new k.ClusterManagerIntelliSenseRulesProvider.$ctor1(new Bridge.ArrayEnumerable(accounts), new Bridge.ArrayEnumerable(services), connectionString);
|
|
1872
|
+
};
|
|
1873
|
+
KustoLanguageService.prototype.kustoKindToLsKind = function (kustoKind) {
|
|
1874
|
+
var res = this._kustoKindtolsKind[kustoKind];
|
|
1875
|
+
return res ? res : ls.CompletionItemKind.Variable;
|
|
1876
|
+
};
|
|
1877
|
+
KustoLanguageService.prototype.kustoKindToLsKindV2 = function (kustoKind) {
|
|
1878
|
+
var res = this._kustoKindToLsKindV2[kustoKind];
|
|
1879
|
+
return res ? res : ls.CompletionItemKind.Variable;
|
|
1880
|
+
};
|
|
1881
|
+
KustoLanguageService.prototype.createRange = function (document, start, end) {
|
|
1882
|
+
return ls.Range.create(document.positionAt(start), document.positionAt(end));
|
|
1883
|
+
};
|
|
1884
|
+
KustoLanguageService.prototype.toArray = function (bridgeList) {
|
|
1885
|
+
return Bridge.toArray(bridgeList);
|
|
1886
|
+
};
|
|
1887
|
+
KustoLanguageService.toBridgeList = function (array) {
|
|
1888
|
+
// copied from bridge.js from the implementation of Enumerable.prototype.toList
|
|
1889
|
+
return new (System.Collections.Generic.List$1(System.Object).$ctor1)(array);
|
|
1890
|
+
};
|
|
1891
|
+
KustoLanguageService.prototype.tokenKindToClassificationKind = function (token) {
|
|
1892
|
+
var conversion = this._tokenKindToClassificationKind[token];
|
|
1893
|
+
return conversion || k2.ClassificationKind.PlainText;
|
|
1894
|
+
};
|
|
1895
|
+
KustoLanguageService.prototype.parseAndAnalyze = function (document, cursorOffset) {
|
|
1896
|
+
if (!document || !this.isIntellisenseV2()) {
|
|
1897
|
+
return undefined;
|
|
1898
|
+
}
|
|
1899
|
+
var script = this.parseDocumentV2(document);
|
|
1900
|
+
var text = script.Text;
|
|
1901
|
+
if (cursorOffset !== undefined) {
|
|
1902
|
+
var currentBlock = this.getCurrentCommandV2(script, cursorOffset);
|
|
1903
|
+
if (!currentBlock) {
|
|
1904
|
+
return undefined;
|
|
1905
|
+
}
|
|
1906
|
+
text = currentBlock.Text;
|
|
1907
|
+
}
|
|
1908
|
+
var parsedAndAnalyzed = Kusto.Language.KustoCode.ParseAndAnalyze(text, this._kustoJsSchemaV2);
|
|
1909
|
+
return parsedAndAnalyzed;
|
|
1910
|
+
};
|
|
1911
|
+
return KustoLanguageService;
|
|
1912
|
+
}());
|
|
1913
|
+
var languageService = new KustoLanguageService(KustoLanguageService.dummySchema, {
|
|
1914
|
+
includeControlCommands: true,
|
|
1915
|
+
useIntellisenseV2: true,
|
|
1916
|
+
useSemanticColorization: true,
|
|
1917
|
+
});
|
|
1918
|
+
/**
|
|
1919
|
+
* Obtain an instance of the kusto language service.
|
|
1920
|
+
*/
|
|
1921
|
+
export function getKustoLanguageService() {
|
|
1922
|
+
return languageService;
|
|
1923
|
+
}
|