@kusto/monaco-kusto 4.0.4 → 4.1.1

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,187 +1,187 @@
1
- var Emitter = monaco.Emitter;
2
- import KustoCommandHighlighter from './commandHighlighter';
3
- import KustoCommandFormatter from './commandFormatter';
4
- import { extend } from './extendedEditor';
5
- // --- Kusto configuration and defaults ---------
6
- var LanguageServiceDefaultsImpl = /** @class */ (function () {
7
- function LanguageServiceDefaultsImpl(languageSettings) {
8
- this._onDidChange = new Emitter();
9
- this.setLanguageSettings(languageSettings);
10
- // default to never kill worker when idle.
11
- // reason: when killing worker - schema gets lost. We transmit the schema back to main process when killing
12
- // the worker, but in some extreme cases web worker runs out of memory while stringifying the schema.
13
- // This stems from the fact that web workers have much more limited memory that the main process.
14
- // An alternative solution (not currently implemented) is to just save the schema in the main process whenever calling
15
- // setSchema. That way we don't need to stringify the schema on the worker side when killing the web worker.
16
- this._workerMaxIdleTime = 0;
17
- }
18
- Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "onDidChange", {
19
- get: function () {
20
- return this._onDidChange.event;
21
- },
22
- enumerable: false,
23
- configurable: true
24
- });
25
- Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "languageSettings", {
26
- get: function () {
27
- return this._languageSettings;
28
- },
29
- enumerable: false,
30
- configurable: true
31
- });
32
- LanguageServiceDefaultsImpl.prototype.setLanguageSettings = function (options) {
33
- this._languageSettings = options || Object.create(null);
34
- this._onDidChange.fire(this);
35
- };
36
- LanguageServiceDefaultsImpl.prototype.setMaximumWorkerIdleTime = function (value) {
37
- // doesn't fire an event since no
38
- // worker restart is required here
39
- this._workerMaxIdleTime = value;
40
- };
41
- LanguageServiceDefaultsImpl.prototype.getWorkerMaxIdleTime = function () {
42
- return this._workerMaxIdleTime;
43
- };
44
- return LanguageServiceDefaultsImpl;
45
- }());
46
- export { LanguageServiceDefaultsImpl };
47
- var defaultLanguageSettings = {
48
- includeControlCommands: true,
49
- newlineAfterPipe: true,
50
- openSuggestionDialogAfterPreviousSuggestionAccepted: true,
51
- useIntellisenseV2: true,
52
- useSemanticColorization: true,
53
- useTokenColorization: true,
54
- enableHover: true,
55
- formatter: {
56
- indentationSize: 4,
57
- pipeOperatorStyle: 'Smart'
58
- },
59
- syntaxErrorAsMarkDown: {
60
- enableSyntaxErrorAsMarkDown: false
61
- }
62
- };
63
- function getKustoWorker() {
64
- return new Promise(function (resolve, reject) {
65
- withMode(function (mode) {
66
- mode.getKustoWorker().then(resolve, reject);
67
- });
68
- });
69
- }
70
- function withMode(callback) {
71
- require(['vs/language/kusto/kustoMode'], callback);
72
- }
73
- export function setupMonacoKusto(monacoInstance) {
74
- var kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
75
- function createAPI() {
76
- return {
77
- kustoDefaults: kustoDefaults,
78
- getKustoWorker: getKustoWorker,
79
- };
80
- }
81
- monacoInstance.languages.kusto = createAPI();
82
- monacoInstance.languages.onLanguage('kusto', function () {
83
- withMode(function (mode) { return mode.setupMode(kustoDefaults, monacoInstance); });
84
- });
85
- monacoInstance.languages.register({
86
- id: 'kusto',
87
- extensions: ['.csl', '.kql'],
88
- });
89
- // TODO: asked if there's a cleaner way to register an editor contribution. looks like monaco has an internal contribution regstrar but it's no exposed in the API.
90
- // https://stackoverflow.com/questions/46700245/how-to-add-an-ieditorcontribution-to-monaco-editor
91
- var commandHighlighter;
92
- var commandFormatter;
93
- monacoInstance.editor.defineTheme('kusto-light', {
94
- base: 'vs',
95
- inherit: true,
96
- rules: [
97
- { token: 'comment', foreground: '008000' },
98
- { token: 'variable.predefined', foreground: '800080' },
99
- { token: 'function', foreground: '0000FF' },
100
- { token: 'operator.sql', foreground: 'CC3700' },
101
- { token: 'string', foreground: 'B22222' },
102
- { token: 'operator.scss', foreground: '0000FF' },
103
- { token: 'variable', foreground: 'C71585' },
104
- { token: 'variable.parameter', foreground: '9932CC' },
105
- { token: '', foreground: '000000' },
106
- { token: 'type', foreground: '0000FF' },
107
- { token: 'tag', foreground: '0000FF' },
108
- { token: 'annotation', foreground: '2B91AF' },
109
- { token: 'keyword', foreground: '0000FF' },
110
- { token: 'number', foreground: '191970' },
111
- { token: 'annotation', foreground: '9400D3' },
112
- { token: 'invalid', background: 'cd3131' },
113
- ],
114
- colors: {},
115
- });
116
- monacoInstance.editor.defineTheme('kusto-dark', {
117
- base: 'vs-dark',
118
- inherit: true,
119
- rules: [
120
- { token: 'comment', foreground: '608B4E' },
121
- { token: 'variable.predefined', foreground: '4ec9b0' },
122
- { token: 'function', foreground: 'dcdcaa' },
123
- { token: 'operator.sql', foreground: '9cdcfe' },
124
- { token: 'string', foreground: 'ce9178' },
125
- { token: 'operator.scss', foreground: '569cd6' },
126
- { token: 'variable', foreground: '4ec9b0' },
127
- { token: 'variable.parameter', foreground: 'c586c0' },
128
- { token: '', foreground: 'd4d4d4' },
129
- { token: 'type', foreground: '569cd6' },
130
- { token: 'tag', foreground: '569cd6' },
131
- { token: 'annotation', foreground: '9cdcfe' },
132
- { token: 'keyword', foreground: '569cd6' },
133
- { token: 'number', foreground: 'd7ba7d' },
134
- { token: 'annotation', foreground: 'b5cea8' },
135
- { token: 'invalid', background: 'cd3131' },
136
- ],
137
- colors: {},
138
- });
139
- monacoInstance.editor.defineTheme('kusto-dark2', {
140
- base: 'vs-dark',
141
- inherit: true,
142
- rules: [],
143
- colors: { 'editor.background': '#1B1A19' },
144
- });
145
- // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis.
146
- // Most other language features are initialized in kustoMode.ts
147
- monacoInstance.editor.onDidCreateEditor(function (editor) {
148
- // hook up extension methods to editor.
149
- extend(editor);
150
- commandHighlighter = new KustoCommandHighlighter(editor);
151
- if (isStandaloneCodeEditor(editor)) {
152
- commandFormatter = new KustoCommandFormatter(editor);
153
- }
154
- triggerSuggestDialogWhenCompletionItemSelected(editor);
155
- });
156
- function triggerSuggestDialogWhenCompletionItemSelected(editor) {
157
- editor.onDidChangeCursorSelection(function (event) {
158
- // checking the condition inside the event makes sure we will stay up to date whne kusto configuration changes at runtime.
159
- if (kustoDefaults &&
160
- kustoDefaults.languageSettings &&
161
- kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
162
- var didAcceptSuggestion = event.source === 'modelChange' && event.reason === monaco.editor.CursorChangeReason.RecoverFromMarkers;
163
- if (!didAcceptSuggestion) {
164
- return;
165
- }
166
- event.selection;
167
- var completionText = editor.getModel().getValueInRange(event.selection);
168
- if (completionText[completionText.length - 1] === ' ') {
169
- // OK so now we in a situation where we know a suggestion was selected and we want to trigger another one.
170
- // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
171
- // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
172
- // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
173
- // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions,
174
- // this is the best we have.
175
- setTimeout(function () { return editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}); }, 10);
176
- }
177
- }
178
- });
179
- }
180
- }
181
- function isStandaloneCodeEditor(editor) {
182
- return editor.addAction !== undefined;
183
- }
184
- // --- Registration to monaco editor ---
185
- if (monaco.editor) {
186
- setupMonacoKusto(monaco);
187
- }
1
+ var Emitter = monaco.Emitter;
2
+ import KustoCommandHighlighter from './commandHighlighter';
3
+ import KustoCommandFormatter from './commandFormatter';
4
+ import { extend } from './extendedEditor';
5
+ // --- Kusto configuration and defaults ---------
6
+ var LanguageServiceDefaultsImpl = /** @class */ (function () {
7
+ function LanguageServiceDefaultsImpl(languageSettings) {
8
+ this._onDidChange = new Emitter();
9
+ this.setLanguageSettings(languageSettings);
10
+ // default to never kill worker when idle.
11
+ // reason: when killing worker - schema gets lost. We transmit the schema back to main process when killing
12
+ // the worker, but in some extreme cases web worker runs out of memory while stringifying the schema.
13
+ // This stems from the fact that web workers have much more limited memory that the main process.
14
+ // An alternative solution (not currently implemented) is to just save the schema in the main process whenever calling
15
+ // setSchema. That way we don't need to stringify the schema on the worker side when killing the web worker.
16
+ this._workerMaxIdleTime = 0;
17
+ }
18
+ Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "onDidChange", {
19
+ get: function () {
20
+ return this._onDidChange.event;
21
+ },
22
+ enumerable: false,
23
+ configurable: true
24
+ });
25
+ Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "languageSettings", {
26
+ get: function () {
27
+ return this._languageSettings;
28
+ },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ LanguageServiceDefaultsImpl.prototype.setLanguageSettings = function (options) {
33
+ this._languageSettings = options || Object.create(null);
34
+ this._onDidChange.fire(this);
35
+ };
36
+ LanguageServiceDefaultsImpl.prototype.setMaximumWorkerIdleTime = function (value) {
37
+ // doesn't fire an event since no
38
+ // worker restart is required here
39
+ this._workerMaxIdleTime = value;
40
+ };
41
+ LanguageServiceDefaultsImpl.prototype.getWorkerMaxIdleTime = function () {
42
+ return this._workerMaxIdleTime;
43
+ };
44
+ return LanguageServiceDefaultsImpl;
45
+ }());
46
+ export { LanguageServiceDefaultsImpl };
47
+ var defaultLanguageSettings = {
48
+ includeControlCommands: true,
49
+ newlineAfterPipe: true,
50
+ openSuggestionDialogAfterPreviousSuggestionAccepted: true,
51
+ useIntellisenseV2: true,
52
+ useSemanticColorization: true,
53
+ useTokenColorization: true,
54
+ enableHover: true,
55
+ formatter: {
56
+ indentationSize: 4,
57
+ pipeOperatorStyle: 'Smart'
58
+ },
59
+ syntaxErrorAsMarkDown: {
60
+ enableSyntaxErrorAsMarkDown: false
61
+ }
62
+ };
63
+ function getKustoWorker() {
64
+ return new Promise(function (resolve, reject) {
65
+ withMode(function (mode) {
66
+ mode.getKustoWorker().then(resolve, reject);
67
+ });
68
+ });
69
+ }
70
+ function withMode(callback) {
71
+ require(['vs/language/kusto/kustoMode'], callback);
72
+ }
73
+ export function setupMonacoKusto(monacoInstance) {
74
+ var kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
75
+ function createAPI() {
76
+ return {
77
+ kustoDefaults: kustoDefaults,
78
+ getKustoWorker: getKustoWorker,
79
+ };
80
+ }
81
+ monacoInstance.languages.kusto = createAPI();
82
+ monacoInstance.languages.onLanguage('kusto', function () {
83
+ withMode(function (mode) { return mode.setupMode(kustoDefaults, monacoInstance); });
84
+ });
85
+ monacoInstance.languages.register({
86
+ id: 'kusto',
87
+ extensions: ['.csl', '.kql'],
88
+ });
89
+ // TODO: asked if there's a cleaner way to register an editor contribution. looks like monaco has an internal contribution regstrar but it's no exposed in the API.
90
+ // https://stackoverflow.com/questions/46700245/how-to-add-an-ieditorcontribution-to-monaco-editor
91
+ var commandHighlighter;
92
+ var commandFormatter;
93
+ monacoInstance.editor.defineTheme('kusto-light', {
94
+ base: 'vs',
95
+ inherit: true,
96
+ rules: [
97
+ { token: 'comment', foreground: '008000' },
98
+ { token: 'variable.predefined', foreground: '800080' },
99
+ { token: 'function', foreground: '0000FF' },
100
+ { token: 'operator.sql', foreground: 'CC3700' },
101
+ { token: 'string', foreground: 'B22222' },
102
+ { token: 'operator.scss', foreground: '0000FF' },
103
+ { token: 'variable', foreground: 'C71585' },
104
+ { token: 'variable.parameter', foreground: '9932CC' },
105
+ { token: '', foreground: '000000' },
106
+ { token: 'type', foreground: '0000FF' },
107
+ { token: 'tag', foreground: '0000FF' },
108
+ { token: 'annotation', foreground: '2B91AF' },
109
+ { token: 'keyword', foreground: '0000FF' },
110
+ { token: 'number', foreground: '191970' },
111
+ { token: 'annotation', foreground: '9400D3' },
112
+ { token: 'invalid', background: 'cd3131' },
113
+ ],
114
+ colors: {},
115
+ });
116
+ monacoInstance.editor.defineTheme('kusto-dark', {
117
+ base: 'vs-dark',
118
+ inherit: true,
119
+ rules: [
120
+ { token: 'comment', foreground: '608B4E' },
121
+ { token: 'variable.predefined', foreground: '4ec9b0' },
122
+ { token: 'function', foreground: 'dcdcaa' },
123
+ { token: 'operator.sql', foreground: '9cdcfe' },
124
+ { token: 'string', foreground: 'ce9178' },
125
+ { token: 'operator.scss', foreground: '569cd6' },
126
+ { token: 'variable', foreground: '4ec9b0' },
127
+ { token: 'variable.parameter', foreground: 'c586c0' },
128
+ { token: '', foreground: 'd4d4d4' },
129
+ { token: 'type', foreground: '569cd6' },
130
+ { token: 'tag', foreground: '569cd6' },
131
+ { token: 'annotation', foreground: '9cdcfe' },
132
+ { token: 'keyword', foreground: '569cd6' },
133
+ { token: 'number', foreground: 'd7ba7d' },
134
+ { token: 'annotation', foreground: 'b5cea8' },
135
+ { token: 'invalid', background: 'cd3131' },
136
+ ],
137
+ colors: {},
138
+ });
139
+ monacoInstance.editor.defineTheme('kusto-dark2', {
140
+ base: 'vs-dark',
141
+ inherit: true,
142
+ rules: [],
143
+ colors: { 'editor.background': '#1B1A19' },
144
+ });
145
+ // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis.
146
+ // Most other language features are initialized in kustoMode.ts
147
+ monacoInstance.editor.onDidCreateEditor(function (editor) {
148
+ // hook up extension methods to editor.
149
+ extend(editor);
150
+ commandHighlighter = new KustoCommandHighlighter(editor);
151
+ if (isStandaloneCodeEditor(editor)) {
152
+ commandFormatter = new KustoCommandFormatter(editor);
153
+ }
154
+ triggerSuggestDialogWhenCompletionItemSelected(editor);
155
+ });
156
+ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
157
+ editor.onDidChangeCursorSelection(function (event) {
158
+ // checking the condition inside the event makes sure we will stay up to date whne kusto configuration changes at runtime.
159
+ if (kustoDefaults &&
160
+ kustoDefaults.languageSettings &&
161
+ kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
162
+ var didAcceptSuggestion = event.source === 'modelChange' && event.reason === monaco.editor.CursorChangeReason.RecoverFromMarkers;
163
+ if (!didAcceptSuggestion) {
164
+ return;
165
+ }
166
+ event.selection;
167
+ var completionText = editor.getModel().getValueInRange(event.selection);
168
+ if (completionText[completionText.length - 1] === ' ') {
169
+ // OK so now we in a situation where we know a suggestion was selected and we want to trigger another one.
170
+ // the only problem is that the suggestion widget itself listens to this same event in order to know it needs to close.
171
+ // The only problem is that we're ahead in line, so we're triggering a suggest operation that will be shut down once
172
+ // the next callback is called. This is why we're waiting here - to let all the callbacks run synchronously and be
173
+ // the 'last' subscriber to run. Granted this is hacky, but until monaco provides a specific event for suggestions,
174
+ // this is the best we have.
175
+ setTimeout(function () { return editor.trigger('monaco-kusto', 'editor.action.triggerSuggest', {}); }, 10);
176
+ }
177
+ }
178
+ });
179
+ }
180
+ }
181
+ function isStandaloneCodeEditor(editor) {
182
+ return editor.addAction !== undefined;
183
+ }
184
+ // --- Registration to monaco editor ---
185
+ if (monaco.editor) {
186
+ setupMonacoKusto(monaco);
187
+ }