@kusto/monaco-kusto 3.2.4 → 3.2.7

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.
@@ -1,32 +1,32 @@
1
- var KustoCommandFormatter = /** @class */ (function () {
2
- function KustoCommandFormatter(editor) {
3
- var _this = this;
4
- this.editor = editor;
5
- this.actionAdded = false;
6
- // selection also represents no selection - for example the event gets triggered when moving cursor from point
7
- // a to point b. in the case start position will equal end position.
8
- editor.onDidChangeCursorSelection(function (changeEvent) {
9
- _this.cursorPosition = changeEvent.selection.getStartPosition();
10
- // Theoretically you would expect this code to run only once in onDidCreateEditor.
11
- // Turns out that onDidCreateEditor is fired before the IStandaloneEditor is completely created (it is emmited by
12
- // the super ctor before the child ctor was able to fully run).
13
- // Thus we don't have a key binding provided yet when onDidCreateEditor is run, which is essential to call addAction.
14
- // By adding the action here in onDidChangeCursorSelection we're making sure that the editor has a key binding provider,
15
- // and we just need to make sure that this happens only once.
16
- if (!_this.actionAdded) {
17
- editor.addAction({
18
- id: 'editor.action.kusto.formatCurrentCommand',
19
- label: 'Format Command Under Cursor',
20
- keybindings: [monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_K, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_F)],
21
- run: function (ed) {
22
- editor.trigger('KustoCommandFormatter', 'editor.action.formatSelection', null);
23
- },
24
- contextMenuGroupId: '1_modification'
25
- });
26
- _this.actionAdded = true;
27
- }
28
- });
29
- }
30
- return KustoCommandFormatter;
31
- }());
32
- export default KustoCommandFormatter;
1
+ var KustoCommandFormatter = /** @class */ (function () {
2
+ function KustoCommandFormatter(editor) {
3
+ var _this = this;
4
+ this.editor = editor;
5
+ this.actionAdded = false;
6
+ // selection also represents no selection - for example the event gets triggered when moving cursor from point
7
+ // a to point b. in the case start position will equal end position.
8
+ editor.onDidChangeCursorSelection(function (changeEvent) {
9
+ _this.cursorPosition = changeEvent.selection.getStartPosition();
10
+ // Theoretically you would expect this code to run only once in onDidCreateEditor.
11
+ // Turns out that onDidCreateEditor is fired before the IStandaloneEditor is completely created (it is emmited by
12
+ // the super ctor before the child ctor was able to fully run).
13
+ // Thus we don't have a key binding provided yet when onDidCreateEditor is run, which is essential to call addAction.
14
+ // By adding the action here in onDidChangeCursorSelection we're making sure that the editor has a key binding provider,
15
+ // and we just need to make sure that this happens only once.
16
+ if (!_this.actionAdded) {
17
+ editor.addAction({
18
+ id: 'editor.action.kusto.formatCurrentCommand',
19
+ label: 'Format Command Under Cursor',
20
+ keybindings: [monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_K, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_F)],
21
+ run: function (ed) {
22
+ editor.trigger('KustoCommandFormatter', 'editor.action.formatSelection', null);
23
+ },
24
+ contextMenuGroupId: '1_modification'
25
+ });
26
+ _this.actionAdded = true;
27
+ }
28
+ });
29
+ }
30
+ return KustoCommandFormatter;
31
+ }());
32
+ export default KustoCommandFormatter;
@@ -1,44 +1,44 @@
1
- /**
2
- * Highlights the command that surround cursor location
3
- */
4
- var KustoCommandHighlighter = /** @class */ (function () {
5
- /**
6
- * Register to cursor movement and seleciton events.
7
- * @param editor monaco editor instance
8
- */
9
- function KustoCommandHighlighter(editor) {
10
- var _this = this;
11
- this.editor = editor;
12
- this.disposables = [];
13
- this.decorations = [];
14
- // Note that selection update is triggered not only for selection changes, but also just when no text selection is occuring and cursor just moves around.
15
- // This case is counted as a 0-length selection starting and ending on the cursor position.
16
- this.editor.onDidChangeCursorSelection(function (changeEvent) {
17
- _this.highlightCommandUnderCursor(changeEvent);
18
- });
19
- }
20
- KustoCommandHighlighter.prototype.getId = function () {
21
- return KustoCommandHighlighter.ID;
22
- };
23
- KustoCommandHighlighter.prototype.dispose = function () {
24
- this.disposables.forEach(function (d) { return d.dispose(); });
25
- };
26
- KustoCommandHighlighter.prototype.highlightCommandUnderCursor = function (changeEvent) {
27
- // Looks like the user selected a bunch of text. we don't want to highlight the entire command in this case - since highlighting
28
- // the text is more helpful.
29
- if (!changeEvent.selection.isEmpty()) {
30
- this.decorations = this.editor.deltaDecorations(this.decorations, []);
31
- return;
32
- }
33
- var commandRange = this.editor.getCurrentCommandRange(changeEvent.selection.getStartPosition());
34
- var decorations = [{
35
- range: commandRange,
36
- options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT
37
- }];
38
- this.decorations = this.editor.deltaDecorations(this.decorations, decorations);
39
- };
40
- KustoCommandHighlighter.ID = 'editor.contrib.kustoCommandHighliter';
41
- KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT = { className: 'selectionHighlight' };
42
- return KustoCommandHighlighter;
43
- }());
44
- export default KustoCommandHighlighter;
1
+ /**
2
+ * Highlights the command that surround cursor location
3
+ */
4
+ var KustoCommandHighlighter = /** @class */ (function () {
5
+ /**
6
+ * Register to cursor movement and seleciton events.
7
+ * @param editor monaco editor instance
8
+ */
9
+ function KustoCommandHighlighter(editor) {
10
+ var _this = this;
11
+ this.editor = editor;
12
+ this.disposables = [];
13
+ this.decorations = [];
14
+ // Note that selection update is triggered not only for selection changes, but also just when no text selection is occuring and cursor just moves around.
15
+ // This case is counted as a 0-length selection starting and ending on the cursor position.
16
+ this.editor.onDidChangeCursorSelection(function (changeEvent) {
17
+ _this.highlightCommandUnderCursor(changeEvent);
18
+ });
19
+ }
20
+ KustoCommandHighlighter.prototype.getId = function () {
21
+ return KustoCommandHighlighter.ID;
22
+ };
23
+ KustoCommandHighlighter.prototype.dispose = function () {
24
+ this.disposables.forEach(function (d) { return d.dispose(); });
25
+ };
26
+ KustoCommandHighlighter.prototype.highlightCommandUnderCursor = function (changeEvent) {
27
+ // Looks like the user selected a bunch of text. we don't want to highlight the entire command in this case - since highlighting
28
+ // the text is more helpful.
29
+ if (!changeEvent.selection.isEmpty()) {
30
+ this.decorations = this.editor.deltaDecorations(this.decorations, []);
31
+ return;
32
+ }
33
+ var commandRange = this.editor.getCurrentCommandRange(changeEvent.selection.getStartPosition());
34
+ var decorations = [{
35
+ range: commandRange,
36
+ options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT
37
+ }];
38
+ this.decorations = this.editor.deltaDecorations(this.decorations, decorations);
39
+ };
40
+ KustoCommandHighlighter.ID = 'editor.contrib.kustoCommandHighliter';
41
+ KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT = { className: 'selectionHighlight' };
42
+ return KustoCommandHighlighter;
43
+ }());
44
+ export default KustoCommandHighlighter;
@@ -1,38 +1,38 @@
1
- /// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />
2
- /**
3
- * Extending ICode editor to contain additional kusto-speicifc methods.
4
- * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
5
- */
6
- export function extend(editor) {
7
- var proto = Object.getPrototypeOf(editor);
8
- proto.getCurrentCommandRange = function (cursorPosition) {
9
- var editor = this;
10
- var zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
11
- var lines = this.getModel().getLinesContent();
12
- var commandOrdinal = 0;
13
- var linesWithCommandOrdinal = [];
14
- for (var lineNumber = 0; lineNumber < lines.length; lineNumber++) {
15
- var isEmptyLine = lines[lineNumber].trim() === '';
16
- if (isEmptyLine) {
17
- // increase commandCounter - we'll be starting a new command.
18
- linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal++, lineNumber: lineNumber });
19
- }
20
- else {
21
- linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal, lineNumber: lineNumber });
22
- }
23
- // No need to keep scanning if we're past our line and we've seen an empty line.
24
- if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
25
- break;
26
- }
27
- }
28
- var currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
29
- var currentCommandLines = linesWithCommandOrdinal.filter(function (line) { return line.commandOrdinal === currentCommandOrdinal; });
30
- var currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
31
- var currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
32
- // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
33
- // Start-column of 1 and End column of 2 means 1st character is selected.
34
- // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
35
- var commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
36
- return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
37
- };
38
- }
1
+ /// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />
2
+ /**
3
+ * Extending ICode editor to contain additional kusto-speicifc methods.
4
+ * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
5
+ */
6
+ export function extend(editor) {
7
+ var proto = Object.getPrototypeOf(editor);
8
+ proto.getCurrentCommandRange = function (cursorPosition) {
9
+ var editor = this;
10
+ var zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
11
+ var lines = this.getModel().getLinesContent();
12
+ var commandOrdinal = 0;
13
+ var linesWithCommandOrdinal = [];
14
+ for (var lineNumber = 0; lineNumber < lines.length; lineNumber++) {
15
+ var isEmptyLine = lines[lineNumber].trim() === '';
16
+ if (isEmptyLine) {
17
+ // increase commandCounter - we'll be starting a new command.
18
+ linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal++, lineNumber: lineNumber });
19
+ }
20
+ else {
21
+ linesWithCommandOrdinal.push({ commandOrdinal: commandOrdinal, lineNumber: lineNumber });
22
+ }
23
+ // No need to keep scanning if we're past our line and we've seen an empty line.
24
+ if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
25
+ break;
26
+ }
27
+ }
28
+ var currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
29
+ var currentCommandLines = linesWithCommandOrdinal.filter(function (line) { return line.commandOrdinal === currentCommandOrdinal; });
30
+ var currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
31
+ var currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
32
+ // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
33
+ // Start-column of 1 and End column of 2 means 1st character is selected.
34
+ // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
35
+ var commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
36
+ return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
37
+ };
38
+ }
@@ -1,8 +1,8 @@
1
- import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
2
- import { KustoWorker } from './kustoWorker';
3
- self.onmessage = function () {
4
- // ignore the first message
5
- worker.initialize(function (ctx, createData) {
6
- return new KustoWorker(ctx, createData);
7
- });
8
- };
1
+ import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
2
+ import { KustoWorker } from './kustoWorker';
3
+ self.onmessage = function () {
4
+ // ignore the first message
5
+ worker.initialize(function (ctx, createData) {
6
+ return new KustoWorker(ctx, createData);
7
+ });
8
+ };
@@ -1,98 +1,98 @@
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
- import { WorkerManager } from './workerManager';
13
- import { KustoLanguageDefinition } from './languageService/kustoMonarchLanguageDefinition';
14
- import * as languageFeatures from './languageFeatures';
15
- var kustoWorker;
16
- var resolveWorker;
17
- var rejectWorker;
18
- var workerPromise = new Promise(function (resolve, reject) {
19
- resolveWorker = resolve;
20
- rejectWorker = reject;
21
- });
22
- /**
23
- * Called when Kusto language is first needed (a model has the language set)
24
- * @param defaults
25
- */
26
- export function setupMode(defaults) {
27
- var onSchemaChange = new monaco.Emitter();
28
- // TODO: when should we dispose of these? seems like monaco-css and monaco-typescript don't dispose of these.
29
- var disposables = [];
30
- var monarchTokensProvider;
31
- var client = new WorkerManager(defaults);
32
- disposables.push(client);
33
- var workerAccessor = function (first) {
34
- var more = [];
35
- for (var _i = 1; _i < arguments.length; _i++) {
36
- more[_i - 1] = arguments[_i];
37
- }
38
- var augmentedSetSchema = function (schema, worker, globalParameters) {
39
- var workerPromise = worker.setSchema(schema);
40
- workerPromise.then(function () {
41
- onSchemaChange.fire(schema);
42
- });
43
- };
44
- var worker = client.getLanguageServiceWorker.apply(client, [first].concat(more));
45
- return worker.then(function (worker) {
46
- return (__assign(__assign({}, worker), { setSchema: function (schema) { return augmentedSetSchema(schema, worker); }, setSchemaFromShowSchema: function (schema, connection, database, globalParameters) {
47
- worker
48
- .normalizeSchema(schema, connection, database)
49
- .then(function (schema) { return (globalParameters ? __assign(__assign({}, schema), { globalParameters: globalParameters }) : schema); })
50
- .then(function (normalized) { return augmentedSetSchema(normalized, worker); });
51
- } }));
52
- });
53
- };
54
- var language = 'kusto';
55
- disposables.push(monaco.languages.registerCompletionItemProvider(language, new languageFeatures.CompletionAdapter(workerAccessor, defaults.languageSettings)));
56
- // Monaco tokenization runs in main thread so we're using a quick schema-unaware tokenization.
57
- // a web worker will run semantic colorization in the background (ColorizationAdapter).
58
- if (defaults.languageSettings.useTokenColorization) {
59
- monarchTokensProvider = monaco.languages.setMonarchTokensProvider(language, KustoLanguageDefinition);
60
- }
61
- // listen to configuration changes and if we're switching from semantic to monarch colorization, do the switch.
62
- defaults.onDidChange(function (e) {
63
- if (!e.languageSettings.useTokenColorization && monarchTokensProvider !== undefined) {
64
- monarchTokensProvider.dispose();
65
- monarchTokensProvider = undefined;
66
- }
67
- if (e.languageSettings.useTokenColorization && monarchTokensProvider == undefined) {
68
- monarchTokensProvider = monaco.languages.setMonarchTokensProvider(language, KustoLanguageDefinition);
69
- }
70
- });
71
- disposables.push(new languageFeatures.DiagnosticsAdapter(language, workerAccessor, defaults, onSchemaChange.event));
72
- disposables.push(new languageFeatures.ColorizationAdapter(language, workerAccessor, defaults, onSchemaChange.event));
73
- disposables.push(monaco.languages.registerDocumentRangeFormattingEditProvider(language, new languageFeatures.FormatAdapter(workerAccessor)));
74
- disposables.push(monaco.languages.registerFoldingRangeProvider(language, new languageFeatures.FoldingAdapter(workerAccessor)));
75
- disposables.push(monaco.languages.registerDefinitionProvider(language, new languageFeatures.DefinitionAdapter(workerAccessor)));
76
- disposables.push(monaco.languages.registerRenameProvider(language, new languageFeatures.RenameAdapter(workerAccessor)));
77
- disposables.push(monaco.languages.registerReferenceProvider(language, new languageFeatures.ReferenceAdapter(workerAccessor)));
78
- if (defaults.languageSettings.enableHover) {
79
- disposables.push(monaco.languages.registerHoverProvider(language, new languageFeatures.HoverAdapter(workerAccessor)));
80
- }
81
- monaco.languages.registerDocumentFormattingEditProvider(language, new languageFeatures.DocumentFormatAdapter(workerAccessor));
82
- kustoWorker = workerAccessor;
83
- resolveWorker(workerAccessor);
84
- monaco.languages.setLanguageConfiguration(language, {
85
- folding: {
86
- offSide: false,
87
- markers: { start: /^\s*[\r\n]/gm, end: /^\s*[\r\n]/gm },
88
- },
89
- comments: {
90
- lineComment: '//',
91
- blockComment: null,
92
- },
93
- });
94
- return kustoWorker;
95
- }
96
- export function getKustoWorker() {
97
- return workerPromise.then(function () { return kustoWorker; });
98
- }
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
+ import { WorkerManager } from './workerManager';
13
+ import { KustoLanguageDefinition } from './languageService/kustoMonarchLanguageDefinition';
14
+ import * as languageFeatures from './languageFeatures';
15
+ var kustoWorker;
16
+ var resolveWorker;
17
+ var rejectWorker;
18
+ var workerPromise = new Promise(function (resolve, reject) {
19
+ resolveWorker = resolve;
20
+ rejectWorker = reject;
21
+ });
22
+ /**
23
+ * Called when Kusto language is first needed (a model has the language set)
24
+ * @param defaults
25
+ */
26
+ export function setupMode(defaults) {
27
+ var onSchemaChange = new monaco.Emitter();
28
+ // TODO: when should we dispose of these? seems like monaco-css and monaco-typescript don't dispose of these.
29
+ var disposables = [];
30
+ var monarchTokensProvider;
31
+ var client = new WorkerManager(defaults);
32
+ disposables.push(client);
33
+ var workerAccessor = function (first) {
34
+ var more = [];
35
+ for (var _i = 1; _i < arguments.length; _i++) {
36
+ more[_i - 1] = arguments[_i];
37
+ }
38
+ var augmentedSetSchema = function (schema, worker, globalParameters) {
39
+ var workerPromise = worker.setSchema(schema);
40
+ workerPromise.then(function () {
41
+ onSchemaChange.fire(schema);
42
+ });
43
+ };
44
+ var worker = client.getLanguageServiceWorker.apply(client, [first].concat(more));
45
+ return worker.then(function (worker) {
46
+ return (__assign(__assign({}, worker), { setSchema: function (schema) { return augmentedSetSchema(schema, worker); }, setSchemaFromShowSchema: function (schema, connection, database, globalParameters) {
47
+ worker
48
+ .normalizeSchema(schema, connection, database)
49
+ .then(function (schema) { return (globalParameters ? __assign(__assign({}, schema), { globalParameters: globalParameters }) : schema); })
50
+ .then(function (normalized) { return augmentedSetSchema(normalized, worker); });
51
+ } }));
52
+ });
53
+ };
54
+ var language = 'kusto';
55
+ disposables.push(monaco.languages.registerCompletionItemProvider(language, new languageFeatures.CompletionAdapter(workerAccessor, defaults.languageSettings)));
56
+ // Monaco tokenization runs in main thread so we're using a quick schema-unaware tokenization.
57
+ // a web worker will run semantic colorization in the background (ColorizationAdapter).
58
+ if (defaults.languageSettings.useTokenColorization) {
59
+ monarchTokensProvider = monaco.languages.setMonarchTokensProvider(language, KustoLanguageDefinition);
60
+ }
61
+ // listen to configuration changes and if we're switching from semantic to monarch colorization, do the switch.
62
+ defaults.onDidChange(function (e) {
63
+ if (!e.languageSettings.useTokenColorization && monarchTokensProvider !== undefined) {
64
+ monarchTokensProvider.dispose();
65
+ monarchTokensProvider = undefined;
66
+ }
67
+ if (e.languageSettings.useTokenColorization && monarchTokensProvider == undefined) {
68
+ monarchTokensProvider = monaco.languages.setMonarchTokensProvider(language, KustoLanguageDefinition);
69
+ }
70
+ });
71
+ disposables.push(new languageFeatures.DiagnosticsAdapter(language, workerAccessor, defaults, onSchemaChange.event));
72
+ disposables.push(new languageFeatures.ColorizationAdapter(language, workerAccessor, defaults, onSchemaChange.event));
73
+ disposables.push(monaco.languages.registerDocumentRangeFormattingEditProvider(language, new languageFeatures.FormatAdapter(workerAccessor)));
74
+ disposables.push(monaco.languages.registerFoldingRangeProvider(language, new languageFeatures.FoldingAdapter(workerAccessor)));
75
+ disposables.push(monaco.languages.registerDefinitionProvider(language, new languageFeatures.DefinitionAdapter(workerAccessor)));
76
+ disposables.push(monaco.languages.registerRenameProvider(language, new languageFeatures.RenameAdapter(workerAccessor)));
77
+ disposables.push(monaco.languages.registerReferenceProvider(language, new languageFeatures.ReferenceAdapter(workerAccessor)));
78
+ if (defaults.languageSettings.enableHover) {
79
+ disposables.push(monaco.languages.registerHoverProvider(language, new languageFeatures.HoverAdapter(workerAccessor)));
80
+ }
81
+ monaco.languages.registerDocumentFormattingEditProvider(language, new languageFeatures.DocumentFormatAdapter(workerAccessor));
82
+ kustoWorker = workerAccessor;
83
+ resolveWorker(workerAccessor);
84
+ monaco.languages.setLanguageConfiguration(language, {
85
+ folding: {
86
+ offSide: false,
87
+ markers: { start: /^\s*[\r\n]/gm, end: /^\s*[\r\n]/gm },
88
+ },
89
+ comments: {
90
+ lineComment: '//',
91
+ blockComment: null,
92
+ },
93
+ });
94
+ return kustoWorker;
95
+ }
96
+ export function getKustoWorker() {
97
+ return workerPromise.then(function () { return kustoWorker; });
98
+ }