@kusto/monaco-kusto 5.3.11 → 5.4.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 +3 -3
- package/release/dev/kustoMode.js +123 -0
- package/release/dev/kustoWorker.js +50 -2
- package/release/dev/monaco.contribution.js +1 -0
- package/release/esm/kustoWorker.js +4 -0
- package/release/esm/languageFeatures.js +123 -0
- package/release/esm/languageService/kustoLanguageService.js +46 -2
- package/release/esm/monaco.contribution.js +1 -0
- package/release/esm/monaco.d.ts +3 -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 +1 -1
- package/release/min/kustoWorker.js +1 -1
- package/release/min/monaco.contribution.js +1 -1
- package/release/min/monaco.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kusto/monaco-kusto",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "CSL, KQL plugin for the Monaco Editor",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft"
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"xregexp": "^3.2.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@kusto/language-service": "0.0.
|
|
58
|
-
"@kusto/language-service-next": "0.0.
|
|
57
|
+
"@kusto/language-service": "0.0.40",
|
|
58
|
+
"@kusto/language-service-next": "0.0.63"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"monaco-editor": "0.34.1"
|
package/release/dev/kustoMode.js
CHANGED
|
@@ -2304,6 +2304,51 @@ var t=_l[n],r=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",e=/^(?:pop|shift)$/
|
|
|
2304
2304
|
Z.prototype.chain=tf,Z.prototype.commit=rf,Z.prototype.next=ef,Z.prototype.plant=of,Z.prototype.reverse=ff,Z.prototype.toJSON=Z.prototype.valueOf=Z.prototype.value=cf,Z.prototype.first=Z.prototype.head,Ul&&(Z.prototype[Ul]=uf),Z},be=de();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(re._=be,define('lodash/lodash.min',[],function(){return be})):ue?((ue.exports=be)._=be,ee._=be):re._=be}).call(this);
|
|
2305
2305
|
define('lodash', ['lodash/lodash.min'], function (main) { return main; });
|
|
2306
2306
|
|
|
2307
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2308
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2309
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2310
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2311
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2312
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2313
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2314
|
+
});
|
|
2315
|
+
};
|
|
2316
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
2317
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2318
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2319
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2320
|
+
function step(op) {
|
|
2321
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2322
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
2323
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2324
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2325
|
+
switch (op[0]) {
|
|
2326
|
+
case 0: case 1: t = op; break;
|
|
2327
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2328
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2329
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2330
|
+
default:
|
|
2331
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2332
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2333
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2334
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2335
|
+
if (t[2]) _.ops.pop();
|
|
2336
|
+
_.trys.pop(); continue;
|
|
2337
|
+
}
|
|
2338
|
+
op = body.call(thisArg, _);
|
|
2339
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2340
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2341
|
+
}
|
|
2342
|
+
};
|
|
2343
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2344
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
2345
|
+
if (ar || !(i in from)) {
|
|
2346
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
2347
|
+
ar[i] = from[i];
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2351
|
+
};
|
|
2307
2352
|
define('vs/language/kusto/languageFeatures',["require", "exports", "vscode-languageserver-types", "lodash"], function (require, exports, ls, _) {
|
|
2308
2353
|
"use strict";
|
|
2309
2354
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -2386,6 +2431,26 @@ define('vs/language/kusto/languageFeatures',["require", "exports", "vscode-langu
|
|
|
2386
2431
|
delete _this._debouncedValidations[uriStr];
|
|
2387
2432
|
}
|
|
2388
2433
|
};
|
|
2434
|
+
this._disposables.push(monaco.languages.registerCodeActionProvider(this._languageId, {
|
|
2435
|
+
provideCodeActions: function (model, range, context, _token) { return __awaiter(_this, void 0, void 0, function () {
|
|
2436
|
+
var startOffset, endOffset, showQuickFix, actions;
|
|
2437
|
+
return __generator(this, function (_a) {
|
|
2438
|
+
switch (_a.label) {
|
|
2439
|
+
case 0:
|
|
2440
|
+
startOffset = model.getOffsetAt(range.getStartPosition());
|
|
2441
|
+
endOffset = model.getOffsetAt(range.getEndPosition());
|
|
2442
|
+
showQuickFix = context.markers.length > 0;
|
|
2443
|
+
return [4 /*yield*/, this.getMonacoCodeActions(model, startOffset, endOffset, showQuickFix)];
|
|
2444
|
+
case 1:
|
|
2445
|
+
actions = _a.sent();
|
|
2446
|
+
return [2 /*return*/, {
|
|
2447
|
+
actions: actions,
|
|
2448
|
+
dispose: function () { }
|
|
2449
|
+
}];
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
}); }
|
|
2453
|
+
}));
|
|
2389
2454
|
this._disposables.push(this._monacoInstance.editor.onDidCreateEditor(onEditorAdd));
|
|
2390
2455
|
this._disposables.push(this._monacoInstance.editor.onDidCreateModel(onModelAdd));
|
|
2391
2456
|
this._disposables.push(this._monacoInstance.editor.onWillDisposeModel(onModelRemoved));
|
|
@@ -2409,6 +2474,64 @@ define('vs/language/kusto/languageFeatures',["require", "exports", "vscode-langu
|
|
|
2409
2474
|
this._monacoInstance.editor.getModels().forEach(onModelAdd);
|
|
2410
2475
|
this._monacoInstance.editor.getEditors().forEach(onEditorAdd);
|
|
2411
2476
|
}
|
|
2477
|
+
DiagnosticsAdapter.prototype.getMonacoCodeActions = function (model, startOffset, endOffset, enableQuickFix) {
|
|
2478
|
+
var _a;
|
|
2479
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2480
|
+
var actions, worker, resource, codeActions, _loop_1, this_1, i, state_1;
|
|
2481
|
+
return __generator(this, function (_b) {
|
|
2482
|
+
switch (_b.label) {
|
|
2483
|
+
case 0:
|
|
2484
|
+
actions = [];
|
|
2485
|
+
return [4 /*yield*/, this._worker(model.uri)];
|
|
2486
|
+
case 1:
|
|
2487
|
+
worker = _b.sent();
|
|
2488
|
+
resource = model.uri;
|
|
2489
|
+
return [4 /*yield*/, worker.getResultActions(resource.toString(), startOffset, endOffset)];
|
|
2490
|
+
case 2:
|
|
2491
|
+
codeActions = _b.sent();
|
|
2492
|
+
_loop_1 = function (i) {
|
|
2493
|
+
var codeAction = codeActions[i];
|
|
2494
|
+
if (codeAction.title.includes('Extract Function')) {
|
|
2495
|
+
return "continue";
|
|
2496
|
+
}
|
|
2497
|
+
var codeActionKind = ((_a = this_1.defaults.languageSettings.quickFixCodeActions) === null || _a === void 0 ? void 0 : _a.find(function (actionTitle) { return codeAction.title.includes(actionTitle); })) ? 'quickfix' : 'custom';
|
|
2498
|
+
if (codeActionKind === 'quickfix' && !enableQuickFix) {
|
|
2499
|
+
return { value: void 0 };
|
|
2500
|
+
}
|
|
2501
|
+
var changes = codeAction.changes;
|
|
2502
|
+
var edits = changes.map(function (change) {
|
|
2503
|
+
var _a;
|
|
2504
|
+
var startPosition = model.getPositionAt(change.start);
|
|
2505
|
+
var endPosition = model.getPositionAt(change.start + change.deleteLength);
|
|
2506
|
+
return {
|
|
2507
|
+
resource: model.uri,
|
|
2508
|
+
textEdit: {
|
|
2509
|
+
range: { startLineNumber: startPosition.lineNumber, startColumn: startPosition.column, endLineNumber: endPosition.lineNumber, endColumn: endPosition.column },
|
|
2510
|
+
text: (_a = change.insertText) !== null && _a !== void 0 ? _a : ''
|
|
2511
|
+
}
|
|
2512
|
+
};
|
|
2513
|
+
});
|
|
2514
|
+
actions.push({
|
|
2515
|
+
title: codeAction.title,
|
|
2516
|
+
diagnostics: [],
|
|
2517
|
+
kind: codeActionKind,
|
|
2518
|
+
edit: {
|
|
2519
|
+
edits: __spreadArray([], edits, true)
|
|
2520
|
+
},
|
|
2521
|
+
isPreferred: true
|
|
2522
|
+
});
|
|
2523
|
+
};
|
|
2524
|
+
this_1 = this;
|
|
2525
|
+
for (i = 0; i < codeActions.length; i++) {
|
|
2526
|
+
state_1 = _loop_1(i);
|
|
2527
|
+
if (typeof state_1 === "object")
|
|
2528
|
+
return [2 /*return*/, state_1.value];
|
|
2529
|
+
}
|
|
2530
|
+
return [2 /*return*/, actions];
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
});
|
|
2534
|
+
};
|
|
2412
2535
|
DiagnosticsAdapter.prototype.getOrCreateDebouncedValidation = function (model, languageId) {
|
|
2413
2536
|
var _this = this;
|
|
2414
2537
|
var modelUri = model.uri.toString();
|
|
@@ -7270,6 +7270,49 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
7270
7270
|
var lsDiagnostics = this.toLsDiagnostics(diagnostics, document);
|
|
7271
7271
|
return Promise.resolve(lsDiagnostics);
|
|
7272
7272
|
};
|
|
7273
|
+
KustoLanguageService.prototype.getApplyCodeActions = function (document, start, end) {
|
|
7274
|
+
var script = this.parseDocumentV2(document);
|
|
7275
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
7276
|
+
var codeActionInfo = block.Service.GetCodeActions(start, start, end - start + 1, null, true, null, new Kusto.Language.Utils.CancellationToken());
|
|
7277
|
+
var codeActions = this.toArray(codeActionInfo.Actions);
|
|
7278
|
+
// Some code actions are of type "MenuAction". We want to flat them out, to show them seperately.
|
|
7279
|
+
var flatCodeActions = [];
|
|
7280
|
+
for (var i = 0; i < codeActions.length; i++) {
|
|
7281
|
+
flatCodeActions.push.apply(flatCodeActions, this.flattenCodeActions(codeActions[i]));
|
|
7282
|
+
}
|
|
7283
|
+
return flatCodeActions;
|
|
7284
|
+
};
|
|
7285
|
+
KustoLanguageService.prototype.getResultActions = function (document, start, end) {
|
|
7286
|
+
var _this = this;
|
|
7287
|
+
var script = this.parseDocumentV2(document);
|
|
7288
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
7289
|
+
var applyCodeActions = this.getApplyCodeActions(document, start, end);
|
|
7290
|
+
var resultActionsMap = applyCodeActions.map(function (applyCodeAction) {
|
|
7291
|
+
var changes = [];
|
|
7292
|
+
var codeActionResults = _this.toArray(block.Service.ApplyCodeAction(applyCodeAction, start).Actions);
|
|
7293
|
+
var changeTextAction = codeActionResults.find(function (c) { return c instanceof Kusto.Language.Editor.ChangeTextAction; });
|
|
7294
|
+
if (changeTextAction) {
|
|
7295
|
+
changes = _this.toArray(changeTextAction.Changes)
|
|
7296
|
+
.map(function (change) { return ({ start: change.Start + block.Start, deleteLength: change.DeleteLength, insertText: change.InsertText }); });
|
|
7297
|
+
}
|
|
7298
|
+
return { title: applyCodeAction.Title, changes: changes };
|
|
7299
|
+
})
|
|
7300
|
+
.filter(function (resultAction) { return resultAction.changes.length; });
|
|
7301
|
+
return Promise.resolve(resultActionsMap);
|
|
7302
|
+
};
|
|
7303
|
+
KustoLanguageService.prototype.flattenCodeActions = function (codeAction) {
|
|
7304
|
+
var applyActions = [];
|
|
7305
|
+
if (codeAction instanceof k2.ApplyAction) {
|
|
7306
|
+
applyActions.push(codeAction);
|
|
7307
|
+
}
|
|
7308
|
+
else if (codeAction instanceof k2.MenuAction) {
|
|
7309
|
+
var nestedCodeActions = this.toArray(codeAction.Actions);
|
|
7310
|
+
for (var i = 0; i < nestedCodeActions.length; i++) {
|
|
7311
|
+
applyActions.push.apply(applyActions, this.flattenCodeActions(nestedCodeActions[i]));
|
|
7312
|
+
}
|
|
7313
|
+
}
|
|
7314
|
+
return applyActions;
|
|
7315
|
+
};
|
|
7273
7316
|
KustoLanguageService.prototype.toLsDiagnostics = function (diagnostics, document) {
|
|
7274
7317
|
return diagnostics
|
|
7275
7318
|
.filter(function (diag) { return diag.HasLocation; })
|
|
@@ -7437,8 +7480,9 @@ define('vs/language/kusto/languageService/kustoLanguageService',["require", "exp
|
|
|
7437
7480
|
KustoLanguageService.prototype.setSchema = function (schema) {
|
|
7438
7481
|
var _this = this;
|
|
7439
7482
|
this._schema = schema;
|
|
7440
|
-
if
|
|
7441
|
-
|
|
7483
|
+
// We support intellisenseV2 only if the clusterType is "Engine", even if the setting is enabled
|
|
7484
|
+
if (this._languageSettings.useIntellisenseV2 && schema && schema.clusterType === 'Engine') {
|
|
7485
|
+
var kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
|
|
7442
7486
|
this._kustoJsSchemaV2 = kustoJsSchemaV2;
|
|
7443
7487
|
this._script = undefined;
|
|
7444
7488
|
this._parsePropertiesV2 = undefined;
|
|
@@ -8622,6 +8666,10 @@ define('vs/language/kusto/kustoWorker',["require", "exports", "./languageService
|
|
|
8622
8666
|
var diagnostics = this._languageService.doValidation(document, intervals, includeWarnings, includeSuggestions);
|
|
8623
8667
|
return diagnostics;
|
|
8624
8668
|
};
|
|
8669
|
+
KustoWorker.prototype.getResultActions = function (uri, start, end) {
|
|
8670
|
+
var document = this._getTextDocument(uri);
|
|
8671
|
+
return this._languageService.getResultActions(document, start, end);
|
|
8672
|
+
};
|
|
8625
8673
|
KustoWorker.prototype.doRangeFormat = function (uri, range) {
|
|
8626
8674
|
var document = this._getTextDocument(uri);
|
|
8627
8675
|
var formatted = this._languageService.doRangeFormat(document, range);
|
|
@@ -205,6 +205,7 @@ define('vs/language/kusto/monaco.contribution',["require", "exports", "./command
|
|
|
205
205
|
enableQueryWarnings: false,
|
|
206
206
|
enableQuerySuggestions: false,
|
|
207
207
|
disabledDiagnosticCodes: [],
|
|
208
|
+
quickFixCodeActions: ['Change to'],
|
|
208
209
|
};
|
|
209
210
|
function getKustoWorker() {
|
|
210
211
|
return new Promise(function (resolve, reject) {
|
|
@@ -142,6 +142,10 @@ var KustoWorker = /** @class */ (function () {
|
|
|
142
142
|
var diagnostics = this._languageService.doValidation(document, intervals, includeWarnings, includeSuggestions);
|
|
143
143
|
return diagnostics;
|
|
144
144
|
};
|
|
145
|
+
KustoWorker.prototype.getResultActions = function (uri, start, end) {
|
|
146
|
+
var document = this._getTextDocument(uri);
|
|
147
|
+
return this._languageService.getResultActions(document, start, end);
|
|
148
|
+
};
|
|
145
149
|
KustoWorker.prototype.doRangeFormat = function (uri, range) {
|
|
146
150
|
var document = this._getTextDocument(uri);
|
|
147
151
|
var formatted = this._languageService.doRangeFormat(document, range);
|
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
1
46
|
import * as ls from './_deps/vscode-languageserver-types/main';
|
|
2
47
|
import * as _ from './_deps/lodash/lodash';
|
|
3
48
|
var Uri = monaco.Uri;
|
|
@@ -78,6 +123,26 @@ var DiagnosticsAdapter = /** @class */ (function () {
|
|
|
78
123
|
delete _this._debouncedValidations[uriStr];
|
|
79
124
|
}
|
|
80
125
|
};
|
|
126
|
+
this._disposables.push(monaco.languages.registerCodeActionProvider(this._languageId, {
|
|
127
|
+
provideCodeActions: function (model, range, context, _token) { return __awaiter(_this, void 0, void 0, function () {
|
|
128
|
+
var startOffset, endOffset, showQuickFix, actions;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
switch (_a.label) {
|
|
131
|
+
case 0:
|
|
132
|
+
startOffset = model.getOffsetAt(range.getStartPosition());
|
|
133
|
+
endOffset = model.getOffsetAt(range.getEndPosition());
|
|
134
|
+
showQuickFix = context.markers.length > 0;
|
|
135
|
+
return [4 /*yield*/, this.getMonacoCodeActions(model, startOffset, endOffset, showQuickFix)];
|
|
136
|
+
case 1:
|
|
137
|
+
actions = _a.sent();
|
|
138
|
+
return [2 /*return*/, {
|
|
139
|
+
actions: actions,
|
|
140
|
+
dispose: function () { }
|
|
141
|
+
}];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); }
|
|
145
|
+
}));
|
|
81
146
|
this._disposables.push(this._monacoInstance.editor.onDidCreateEditor(onEditorAdd));
|
|
82
147
|
this._disposables.push(this._monacoInstance.editor.onDidCreateModel(onModelAdd));
|
|
83
148
|
this._disposables.push(this._monacoInstance.editor.onWillDisposeModel(onModelRemoved));
|
|
@@ -101,6 +166,64 @@ var DiagnosticsAdapter = /** @class */ (function () {
|
|
|
101
166
|
this._monacoInstance.editor.getModels().forEach(onModelAdd);
|
|
102
167
|
this._monacoInstance.editor.getEditors().forEach(onEditorAdd);
|
|
103
168
|
}
|
|
169
|
+
DiagnosticsAdapter.prototype.getMonacoCodeActions = function (model, startOffset, endOffset, enableQuickFix) {
|
|
170
|
+
var _a;
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var actions, worker, resource, codeActions, _loop_1, this_1, i, state_1;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
actions = [];
|
|
177
|
+
return [4 /*yield*/, this._worker(model.uri)];
|
|
178
|
+
case 1:
|
|
179
|
+
worker = _b.sent();
|
|
180
|
+
resource = model.uri;
|
|
181
|
+
return [4 /*yield*/, worker.getResultActions(resource.toString(), startOffset, endOffset)];
|
|
182
|
+
case 2:
|
|
183
|
+
codeActions = _b.sent();
|
|
184
|
+
_loop_1 = function (i) {
|
|
185
|
+
var codeAction = codeActions[i];
|
|
186
|
+
if (codeAction.title.includes('Extract Function')) {
|
|
187
|
+
return "continue";
|
|
188
|
+
}
|
|
189
|
+
var codeActionKind = ((_a = this_1.defaults.languageSettings.quickFixCodeActions) === null || _a === void 0 ? void 0 : _a.find(function (actionTitle) { return codeAction.title.includes(actionTitle); })) ? 'quickfix' : 'custom';
|
|
190
|
+
if (codeActionKind === 'quickfix' && !enableQuickFix) {
|
|
191
|
+
return { value: void 0 };
|
|
192
|
+
}
|
|
193
|
+
var changes = codeAction.changes;
|
|
194
|
+
var edits = changes.map(function (change) {
|
|
195
|
+
var _a;
|
|
196
|
+
var startPosition = model.getPositionAt(change.start);
|
|
197
|
+
var endPosition = model.getPositionAt(change.start + change.deleteLength);
|
|
198
|
+
return {
|
|
199
|
+
resource: model.uri,
|
|
200
|
+
textEdit: {
|
|
201
|
+
range: { startLineNumber: startPosition.lineNumber, startColumn: startPosition.column, endLineNumber: endPosition.lineNumber, endColumn: endPosition.column },
|
|
202
|
+
text: (_a = change.insertText) !== null && _a !== void 0 ? _a : ''
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
actions.push({
|
|
207
|
+
title: codeAction.title,
|
|
208
|
+
diagnostics: [],
|
|
209
|
+
kind: codeActionKind,
|
|
210
|
+
edit: {
|
|
211
|
+
edits: __spreadArray([], edits, true)
|
|
212
|
+
},
|
|
213
|
+
isPreferred: true
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
this_1 = this;
|
|
217
|
+
for (i = 0; i < codeActions.length; i++) {
|
|
218
|
+
state_1 = _loop_1(i);
|
|
219
|
+
if (typeof state_1 === "object")
|
|
220
|
+
return [2 /*return*/, state_1.value];
|
|
221
|
+
}
|
|
222
|
+
return [2 /*return*/, actions];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
104
227
|
DiagnosticsAdapter.prototype.getOrCreateDebouncedValidation = function (model, languageId) {
|
|
105
228
|
var _this = this;
|
|
106
229
|
var modelUri = model.uri.toString();
|
|
@@ -618,6 +618,49 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
618
618
|
var lsDiagnostics = this.toLsDiagnostics(diagnostics, document);
|
|
619
619
|
return Promise.resolve(lsDiagnostics);
|
|
620
620
|
};
|
|
621
|
+
KustoLanguageService.prototype.getApplyCodeActions = function (document, start, end) {
|
|
622
|
+
var script = this.parseDocumentV2(document);
|
|
623
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
624
|
+
var codeActionInfo = block.Service.GetCodeActions(start, start, end - start + 1, null, true, null, new Kusto.Language.Utils.CancellationToken());
|
|
625
|
+
var codeActions = this.toArray(codeActionInfo.Actions);
|
|
626
|
+
// Some code actions are of type "MenuAction". We want to flat them out, to show them seperately.
|
|
627
|
+
var flatCodeActions = [];
|
|
628
|
+
for (var i = 0; i < codeActions.length; i++) {
|
|
629
|
+
flatCodeActions.push.apply(flatCodeActions, this.flattenCodeActions(codeActions[i]));
|
|
630
|
+
}
|
|
631
|
+
return flatCodeActions;
|
|
632
|
+
};
|
|
633
|
+
KustoLanguageService.prototype.getResultActions = function (document, start, end) {
|
|
634
|
+
var _this = this;
|
|
635
|
+
var script = this.parseDocumentV2(document);
|
|
636
|
+
var block = this.getAffectedBlocks(this.toArray(script.Blocks), [{ start: start, end: end }])[0];
|
|
637
|
+
var applyCodeActions = this.getApplyCodeActions(document, start, end);
|
|
638
|
+
var resultActionsMap = applyCodeActions.map(function (applyCodeAction) {
|
|
639
|
+
var changes = [];
|
|
640
|
+
var codeActionResults = _this.toArray(block.Service.ApplyCodeAction(applyCodeAction, start).Actions);
|
|
641
|
+
var changeTextAction = codeActionResults.find(function (c) { return c instanceof Kusto.Language.Editor.ChangeTextAction; });
|
|
642
|
+
if (changeTextAction) {
|
|
643
|
+
changes = _this.toArray(changeTextAction.Changes)
|
|
644
|
+
.map(function (change) { return ({ start: change.Start + block.Start, deleteLength: change.DeleteLength, insertText: change.InsertText }); });
|
|
645
|
+
}
|
|
646
|
+
return { title: applyCodeAction.Title, changes: changes };
|
|
647
|
+
})
|
|
648
|
+
.filter(function (resultAction) { return resultAction.changes.length; });
|
|
649
|
+
return Promise.resolve(resultActionsMap);
|
|
650
|
+
};
|
|
651
|
+
KustoLanguageService.prototype.flattenCodeActions = function (codeAction) {
|
|
652
|
+
var applyActions = [];
|
|
653
|
+
if (codeAction instanceof k2.ApplyAction) {
|
|
654
|
+
applyActions.push(codeAction);
|
|
655
|
+
}
|
|
656
|
+
else if (codeAction instanceof k2.MenuAction) {
|
|
657
|
+
var nestedCodeActions = this.toArray(codeAction.Actions);
|
|
658
|
+
for (var i = 0; i < nestedCodeActions.length; i++) {
|
|
659
|
+
applyActions.push.apply(applyActions, this.flattenCodeActions(nestedCodeActions[i]));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return applyActions;
|
|
663
|
+
};
|
|
621
664
|
KustoLanguageService.prototype.toLsDiagnostics = function (diagnostics, document) {
|
|
622
665
|
return diagnostics
|
|
623
666
|
.filter(function (diag) { return diag.HasLocation; })
|
|
@@ -785,8 +828,9 @@ var KustoLanguageService = /** @class */ (function () {
|
|
|
785
828
|
KustoLanguageService.prototype.setSchema = function (schema) {
|
|
786
829
|
var _this = this;
|
|
787
830
|
this._schema = schema;
|
|
788
|
-
if
|
|
789
|
-
|
|
831
|
+
// We support intellisenseV2 only if the clusterType is "Engine", even if the setting is enabled
|
|
832
|
+
if (this._languageSettings.useIntellisenseV2 && schema && schema.clusterType === 'Engine') {
|
|
833
|
+
var kustoJsSchemaV2 = this.convertToKustoJsSchemaV2(schema);
|
|
790
834
|
this._kustoJsSchemaV2 = kustoJsSchemaV2;
|
|
791
835
|
this._script = undefined;
|
|
792
836
|
this._parsePropertiesV2 = undefined;
|
package/release/esm/monaco.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ declare module monaco.languages.kusto {
|
|
|
26
26
|
enableQueryWarnings?: boolean;
|
|
27
27
|
enableQuerySuggestions?: boolean;
|
|
28
28
|
disabledDiagnosticCodes?: string[];
|
|
29
|
+
quickFixCodeActions?: QuickFixCodeActionOptions[];
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export interface SyntaxErrorAsMarkDownOptions {
|
|
@@ -34,6 +35,8 @@ declare module monaco.languages.kusto {
|
|
|
34
35
|
enableSyntaxErrorAsMarkDown?: boolean;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
export type QuickFixCodeActionOptions = 'Extract Expression' | 'Extract Function' | 'Change to';
|
|
39
|
+
|
|
37
40
|
export interface FormatterOptions {
|
|
38
41
|
indentationSize?: number;
|
|
39
42
|
pipeOperatorStyle?: FormatterPlacementStyle;
|