@kusto/monaco-kusto 6.2.0 → 7.0.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.
@@ -1,11 +1,59 @@
1
1
  /*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * monaco-kusto version: 6.2.0(8e26147bc7c3b5a7a3bc6ee55311dfa0b612c10c)
3
+ * monaco-kusto version: 7.0.0(f23f8fe8dd705f8413d0d094c76eb0af2131aace)
4
4
  * Released under the MIT license
5
5
  * https://https://github.com/Azure/monaco-kusto/blob/master/README.md
6
6
  *-----------------------------------------------------------------------------*/
7
7
 
8
- import * as monaco$1 from 'monaco-editor/esm/vs/editor/editor.api';
8
+ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
9
+
10
+ function getCurrentCommandRange(editor, cursorPosition) {
11
+ const zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
12
+ const lines = editor.getModel().getLinesContent();
13
+ let commandOrdinal = 0;
14
+ const linesWithCommandOrdinal = [];
15
+ for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
16
+ let isEmptyLine = lines[lineNumber].trim() === '';
17
+ if (isEmptyLine) {
18
+ // increase commandCounter - we'll be starting a new command.
19
+ linesWithCommandOrdinal.push({
20
+ commandOrdinal: commandOrdinal++,
21
+ lineNumber
22
+ });
23
+ } else {
24
+ linesWithCommandOrdinal.push({
25
+ commandOrdinal: commandOrdinal,
26
+ lineNumber
27
+ });
28
+ }
29
+
30
+ // No need to keep scanning if we're past our line and we've seen an empty line.
31
+ if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
32
+ break;
33
+ }
34
+ }
35
+ const currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
36
+ const currentCommandLines = linesWithCommandOrdinal.filter(line => line.commandOrdinal === currentCommandOrdinal);
37
+ const currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
38
+ const currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
39
+
40
+ // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
41
+ // Start-column of 1 and End column of 2 means 1st character is selected.
42
+ // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
43
+ const commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
44
+ return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
45
+ }
46
+
47
+ /**
48
+ * Extending ICode editor to contain additional kusto-specific methods.
49
+ * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
50
+ */
51
+ function extend(editor) {
52
+ const proto = Object.getPrototypeOf(editor);
53
+ proto.getCurrentCommandRange = function (cursorPosition) {
54
+ getCurrentCommandRange(this, cursorPosition);
55
+ };
56
+ }
9
57
 
10
58
  /**
11
59
  * Highlights the command that surround cursor location
@@ -46,7 +94,7 @@ class KustoCommandHighlighter {
46
94
  this.decorations = this.editor.deltaDecorations(this.decorations, []);
47
95
  return;
48
96
  }
49
- const commandRange = this.editor.getCurrentCommandRange(changeEvent.selection.getStartPosition());
97
+ const commandRange = getCurrentCommandRange(this.editor, changeEvent.selection.getStartPosition());
50
98
  const decorations = [{
51
99
  range: commandRange,
52
100
  options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT
@@ -87,54 +135,10 @@ class KustoCommandFormatter {
87
135
  }
88
136
  }
89
137
 
90
- /**
91
- * Extending ICode editor to contain additional kusto-specific methods.
92
- * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
93
- */
94
- function extend(editor) {
95
- const proto = Object.getPrototypeOf(editor);
96
- proto.getCurrentCommandRange = function (cursorPosition) {
97
- const zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
98
- const lines = this.getModel().getLinesContent();
99
- let commandOrdinal = 0;
100
- const linesWithCommandOrdinal = [];
101
- for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
102
- let isEmptyLine = lines[lineNumber].trim() === '';
103
- if (isEmptyLine) {
104
- // increase commandCounter - we'll be starting a new command.
105
- linesWithCommandOrdinal.push({
106
- commandOrdinal: commandOrdinal++,
107
- lineNumber
108
- });
109
- } else {
110
- linesWithCommandOrdinal.push({
111
- commandOrdinal: commandOrdinal,
112
- lineNumber
113
- });
114
- }
115
-
116
- // No need to keep scanning if we're past our line and we've seen an empty line.
117
- if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
118
- break;
119
- }
120
- }
121
- const currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
122
- const currentCommandLines = linesWithCommandOrdinal.filter(line => line.commandOrdinal === currentCommandOrdinal);
123
- const currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
124
- const currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
125
-
126
- // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
127
- // Start-column of 1 and End column of 2 means 1st character is selected.
128
- // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
129
- const commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
130
- return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
131
- };
132
- }
133
-
134
138
  // --- Kusto configuration and defaults ---------
135
139
 
136
140
  class LanguageServiceDefaultsImpl {
137
- _onDidChange = new monaco$1.Emitter();
141
+ _onDidChange = new monaco.Emitter();
138
142
 
139
143
  // in milliseconds. For example - this is 2 minutes 2 * 60 * 1000
140
144
 
@@ -199,14 +203,14 @@ function withMode(callback) {
199
203
  import('./kustoMode.js').then(callback);
200
204
  }
201
205
  const kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
202
- monaco$1.languages.onLanguage('kusto', () => {
203
- withMode(mode => mode.setupMode(kustoDefaults, monaco$1));
206
+ monaco.languages.onLanguage('kusto', () => {
207
+ withMode(mode => mode.setupMode(kustoDefaults, monaco));
204
208
  });
205
- monaco$1.languages.register({
209
+ monaco.languages.register({
206
210
  id: 'kusto',
207
211
  extensions: ['.csl', '.kql']
208
212
  });
209
- monaco$1.editor.defineTheme('kusto-light', {
213
+ monaco.editor.defineTheme('kusto-light', {
210
214
  base: 'vs',
211
215
  inherit: true,
212
216
  rules: [{
@@ -290,7 +294,7 @@ monaco$1.editor.defineTheme('kusto-light', {
290
294
  }],
291
295
  colors: {}
292
296
  });
293
- monaco$1.editor.defineTheme('kusto-dark', {
297
+ monaco.editor.defineTheme('kusto-dark', {
294
298
  base: 'vs-dark',
295
299
  inherit: true,
296
300
  rules: [{
@@ -376,7 +380,7 @@ monaco$1.editor.defineTheme('kusto-dark', {
376
380
  // see: https://code.visualstudio.com/api/references/theme-color#editor-widget-colors
377
381
  }
378
382
  });
379
- monaco$1.editor.defineTheme('kusto-dark2', {
383
+ monaco.editor.defineTheme('kusto-dark2', {
380
384
  base: 'vs-dark',
381
385
  inherit: true,
382
386
  rules: [],
@@ -390,7 +394,7 @@ monaco$1.editor.defineTheme('kusto-dark2', {
390
394
 
391
395
  // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis.
392
396
  // Most other language features are initialized in kustoMode.ts
393
- monaco$1.editor.onDidCreateEditor(editor => {
397
+ monaco.editor.onDidCreateEditor(editor => {
394
398
  // hook up extension methods to editor.
395
399
  extend(editor);
396
400
  new KustoCommandHighlighter(editor);
@@ -403,7 +407,7 @@ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
403
407
  editor.onDidChangeCursorSelection(event => {
404
408
  // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime.
405
409
  if (kustoDefaults && kustoDefaults.languageSettings && kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
406
- var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco$1.editor.CursorChangeReason.NotSet;
410
+ var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco.editor.CursorChangeReason.NotSet;
407
411
  // If the word at the current position is not null - meaning we did not add a space after completion.
408
412
  // In this case we don't want to activate the eager mode, since it will display the current selected word..
409
413
  if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) {
@@ -423,9 +427,11 @@ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
423
427
  function isStandaloneCodeEditor(editor) {
424
428
  return editor.addAction !== undefined;
425
429
  }
426
- monaco$1.languages.kusto = {
430
+ const globalApi = {
427
431
  kustoDefaults,
428
- getKustoWorker
432
+ getKustoWorker,
433
+ getCurrentCommandRange
429
434
  };
435
+ monaco.languages.kusto = globalApi;
430
436
 
431
- export { LanguageServiceDefaultsImpl, getKustoWorker, kustoDefaults };
437
+ export { getCurrentCommandRange, getKustoWorker, kustoDefaults };
@@ -0,0 +1,261 @@
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ import type * as ls from 'vscode-languageserver-types';
3
+ export interface LanguageSettings {
4
+ includeControlCommands?: boolean;
5
+ newlineAfterPipe?: boolean;
6
+ syntaxErrorAsMarkDown?: SyntaxErrorAsMarkDownOptions;
7
+ openSuggestionDialogAfterPreviousSuggestionAccepted?: boolean;
8
+ useIntellisenseV2?: boolean;
9
+ useSemanticColorization?: boolean;
10
+ useTokenColorization?: boolean;
11
+ disabledCompletionItems?: string[];
12
+ onDidProvideCompletionItems?: OnDidProvideCompletionItems;
13
+ enableHover?: boolean;
14
+ formatter?: FormatterOptions;
15
+ enableQueryWarnings?: boolean;
16
+ enableQuerySuggestions?: boolean;
17
+ disabledDiagnosticCodes?: string[];
18
+ quickFixCodeActions?: QuickFixCodeActionOptions[];
19
+ enableQuickFixes?: boolean;
20
+ }
21
+ export interface SyntaxErrorAsMarkDownOptions {
22
+ header?: string;
23
+ icon?: string;
24
+ enableSyntaxErrorAsMarkDown?: boolean;
25
+ }
26
+ export type QuickFixCodeActionOptions = 'Extract Expression' | 'Extract Function' | 'Change to' | 'FixAll';
27
+ export interface FormatterOptions {
28
+ indentationSize?: number;
29
+ pipeOperatorStyle?: FormatterPlacementStyle;
30
+ }
31
+ export type FormatterPlacementStyle = 'None' | 'NewLine' | 'Smart';
32
+ export interface LanguageServiceDefaults {
33
+ readonly onDidChange: monaco.IEvent<LanguageServiceDefaults>;
34
+ readonly languageSettings: LanguageSettings;
35
+ /**
36
+ * Configure language service settings.
37
+ */
38
+ setLanguageSettings(options: LanguageSettings): void;
39
+ /**
40
+ * Configure when the worker shuts down. By default that is 2mins.
41
+ *
42
+ * @param value The maximum idle time in milliseconds. Values less than one
43
+ * mean never shut down.
44
+ */
45
+ setMaximumWorkerIdleTime(value: number): void;
46
+ getWorkerMaxIdleTime(): number;
47
+ }
48
+ export interface KustoWorker {
49
+ setSchema(schema: Schema): Promise<void>;
50
+ setSchemaFromShowSchema(schema: any, clusterConnectionString: string, databaseInContextName: string, globalScalarParameters: ScalarParameter[], globalTabularParameters: TabularParameter[]): Promise<void>;
51
+ normalizeSchema(schema: any, clusterConnectionString: string, databaseInContextName: string): Promise<EngineSchema>;
52
+ getCommandInContext(uri: string, cursorOffset: number): Promise<string | null>;
53
+ getCommandAndLocationInContext(uri: string, offset: number): Promise<{
54
+ text: string;
55
+ range: monaco.IRange;
56
+ } | null>;
57
+ getCommandsInDocument(uri: string): Promise<{
58
+ absoluteStart: number;
59
+ absoluteEnd: number;
60
+ text: string;
61
+ }[]>;
62
+ getClientDirective(text: string): Promise<{
63
+ isClientDirective: boolean;
64
+ directiveWithoutLeadingComments: string;
65
+ }>;
66
+ getAdminCommand(text: string): Promise<{
67
+ isAdminCommand: boolean;
68
+ adminCommandWithoutLeadingComments: string;
69
+ }>;
70
+ /**
71
+ * Get all declared query parameters declared in current block if any.
72
+ */
73
+ getQueryParams(uri: string, cursorOffset: number): Promise<{
74
+ name: string;
75
+ type: string;
76
+ }[]>;
77
+ /**
78
+ * Get all the ambient parameters defined in global scope.
79
+ * Ambient parameters are parameters that are not defined in the syntax such as in a query parameter declaration.
80
+ * These are parameters that are injected from outside, usually by a UX application that would like to offer
81
+ * the user intellisense for a symbol, without forcing them to write a query declaration statement.
82
+ * Usually the same application injects the query declaration statement and the parameter values when
83
+ * executing the query (so it will execute correctly)
84
+ */
85
+ getGlobalParams(uri: string): Promise<{
86
+ name: string;
87
+ type: string;
88
+ }[]>;
89
+ /**
90
+ * Get the global parameters that are actually being referenced in query.
91
+ * This is different from getQueryParams that will return the parameters declare using a query declaration
92
+ * statement.
93
+ * It is also different from getGlobalParams that will return all global parameters whether used or not.
94
+ */
95
+ getReferencedGlobalParams(uri: string, cursorOffset?: number): Promise<{
96
+ name: string;
97
+ type: string;
98
+ }[]>;
99
+ getReferencedSymbols(document: ls.TextDocument, cursorOffset?: number): Promise<{
100
+ name: string;
101
+ kind: string;
102
+ display: string;
103
+ }[]>;
104
+ /**
105
+ * Get visualization options in render command if present (null otherwise).
106
+ */
107
+ getRenderInfo(uri: string, cursorOffset: number): Promise<RenderInfo | null>;
108
+ doDocumentFormat(uri: string): Promise<ls.TextEdit[]>;
109
+ doRangeFormat(uri: string, range: ls.Range): Promise<ls.TextEdit[]>;
110
+ doCurrentCommandFormat(uri: string, caretPosition: ls.Position): Promise<ls.TextEdit[]>;
111
+ doValidation(uri: string, intervals: {
112
+ start: number;
113
+ end: number;
114
+ }[], includeWarnings?: boolean, includeSuggestions?: boolean): Promise<ls.Diagnostic[]>;
115
+ setParameters(scalarParameters: readonly ScalarParameter[], tabularParameters: readonly TabularParameter[]): void;
116
+ /**
117
+ * Get all the database references from the current command.
118
+ * If database's schema is already cached in previous calls to setSchema or addDatabaseToSchema it will not be returned.
119
+ * This method should be used to get all the cross-databases in a command, then schema for the database should be fetched and added with addDatabaseToSchema.
120
+ * @example
121
+ * If the current command includes: cluster('help').database('Samples')
122
+ * getDatabaseReferences will return [{ clusterName: 'help', databaseName 'Samples' }]
123
+ */
124
+ getDatabaseReferences(uri: string, cursorOffset: number): Promise<DatabaseReference[]>;
125
+ /**
126
+ * Get all the cluster references from the current command.
127
+ * If cluster's schema is already cached it will not be returned.
128
+ * This method should be used to get all the cross-clusters in a command, then schema for the cluster should be fetched and added with addClusterToSchema.
129
+ * cluster name is returned exactly as written in the KQL `cluster(<cluster name>)` function.
130
+ * @example
131
+ * If the current command includes: cluster('help')
132
+ * it returns [{ clusterName: 'help' }]
133
+ * @example
134
+ * If the current command includes: cluster('https://demo11.westus.kusto.windows.net')
135
+ * getClusterReferences will return [{ clusterName: 'https://demo11.westus.kusto.windows.net' }]
136
+ */
137
+ getClusterReferences(uri: string, cursorOffset: number): Promise<ClusterReference[]>;
138
+ /**
139
+ * Adds a database's scheme. Useful with getDatabaseReferences to load schema for cross-cluster commands.
140
+ * @param clusterName the name of the cluster as returned from getDatabaseReferences/getClusterReferences.
141
+ * @example
142
+ * - User enters cluster('help').database('Samples')
143
+ * - hosting app calls getDatabaseReferences which returns [{ clusterName: 'help', databaseName: 'Samples' }].
144
+ * - hosting app fetches the database Schema from https://help.kusto.windows.net
145
+ * - hosting app calls 'addDatabaseToSchema' with the database's schema.
146
+ * - now, when user types cluster('help').database('Samples') then the auto complete list will show all the tables.
147
+ */
148
+ addDatabaseToSchema(uri: string, clusterName: string, databaseSchema: Database): Promise<void>;
149
+ /**
150
+ * Adds a cluster's databases to the schema. Useful when used with getClusterReferences in cross-cluster commands.
151
+ * @param clusterName the name of the cluster as returned in getClusterReferences.
152
+ * @example
153
+ * - User enters cluster('help')
154
+ * - hosting app calls getClusterReferences which returns [{ clusterName: 'help' }].
155
+ * - hosting app fetches the list of databases from https://help.kusto.windows.net
156
+ * - hosting app calls addClusterToSchema with the list of databases.
157
+ * - now, when user type `cluster('help').database(` then the auto complete list will show all the databases.
158
+ */
159
+ addClusterToSchema(uri: string, clusterName: string, databasesNames: readonly string[]): Promise<void>;
160
+ }
161
+ /**
162
+ * A function that get a model Uri and returns a kusto worker that knows how to work
163
+ * with that document.
164
+ */
165
+ export interface WorkerAccessor {
166
+ (first: monaco.Uri, ...more: monaco.Uri[]): Promise<KustoWorker>;
167
+ }
168
+ export interface Column {
169
+ name: string;
170
+ type: string;
171
+ docstring?: string;
172
+ }
173
+ export interface Table {
174
+ name: string;
175
+ columns: Column[];
176
+ docstring?: string;
177
+ }
178
+ export interface ScalarParameter {
179
+ name: string;
180
+ type?: string;
181
+ cslType?: string;
182
+ cslDefaultValue?: string;
183
+ }
184
+ export interface TabularParameter {
185
+ name: string;
186
+ columns: Column[];
187
+ docstring?: string;
188
+ }
189
+ export type InputParameter = ScalarParameter & {
190
+ columns?: ScalarParameter[];
191
+ };
192
+ export interface Function {
193
+ name: string;
194
+ body: string;
195
+ docstring?: string;
196
+ inputParameters: InputParameter[];
197
+ }
198
+ export interface Database {
199
+ name: string;
200
+ tables: Table[];
201
+ functions: Function[];
202
+ majorVersion: number;
203
+ minorVersion: number;
204
+ }
205
+ export interface EngineSchema {
206
+ clusterType: 'Engine';
207
+ cluster: {
208
+ connectionString: string;
209
+ databases: Database[];
210
+ };
211
+ database: Database | undefined;
212
+ }
213
+ export interface ClusterMangerSchema {
214
+ clusterType: 'ClusterManager';
215
+ accounts: string[];
216
+ services: string[];
217
+ connectionString: string;
218
+ }
219
+ export interface DataManagementSchema {
220
+ clusterType: 'DataManagement';
221
+ }
222
+ export type Schema = EngineSchema | ClusterMangerSchema | DataManagementSchema;
223
+ export declare type VisualizationType = 'anomalychart' | 'areachart' | 'barchart' | 'columnchart' | 'ladderchart' | 'linechart' | 'piechart' | 'pivotchart' | 'scatterchart' | 'stackedareachart' | 'timechart' | 'table' | 'timeline' | 'timepivot' | 'card';
224
+ export declare type Scale = 'linear' | 'log';
225
+ export declare type LegendVisibility = 'visible' | 'hidden';
226
+ export declare type YSplit = 'none' | 'axes' | 'panels';
227
+ export declare type Kind = 'default' | 'unstacked' | 'stacked' | 'stacked100' | 'map';
228
+ export interface RenderOptions {
229
+ visualization?: null | VisualizationType;
230
+ title?: null | string;
231
+ xcolumn?: null | string;
232
+ series?: null | string[];
233
+ ycolumns?: null | string[];
234
+ xtitle?: null | string;
235
+ ytitle?: null | string;
236
+ xaxis?: null | Scale;
237
+ yaxis?: null | Scale;
238
+ legend?: null | LegendVisibility;
239
+ ySplit?: null | YSplit;
240
+ accumulate?: null | boolean;
241
+ kind?: null | Kind;
242
+ anomalycolumns?: null | string[];
243
+ ymin?: null | number;
244
+ ymax?: null | number;
245
+ }
246
+ export interface RenderInfo {
247
+ options: RenderOptions;
248
+ location: {
249
+ startOffset: number;
250
+ endOffset: number;
251
+ };
252
+ }
253
+ export interface DatabaseReference {
254
+ databaseName: string;
255
+ clusterName: string;
256
+ }
257
+ export interface ClusterReference {
258
+ clusterName: string;
259
+ }
260
+ export type RenderOptionKeys = keyof RenderOptions;
261
+ export type OnDidProvideCompletionItems = (list: ls.CompletionList) => Promise<ls.CompletionList>;
@@ -1,7 +1,5 @@
1
- /// <reference types="../monaco" />
2
- /// <reference types="monaco-editor/monaco" />
3
- import type { Uri } from 'monaco-editor/esm/vs/editor/editor.api';
4
- import type { LanguageServiceDefaultsImpl } from './monaco.contribution';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ import type { LanguageServiceDefaults } from './monaco.contribution';
5
3
  import type { KustoWorker } from './kustoWorker';
6
4
  export declare class WorkerManager {
7
5
  private _monacoInstance;
@@ -12,11 +10,11 @@ export declare class WorkerManager {
12
10
  private _configChangeListener;
13
11
  private _worker;
14
12
  private _client;
15
- constructor(_monacoInstance: typeof monaco, defaults: LanguageServiceDefaultsImpl);
13
+ constructor(_monacoInstance: typeof monaco, defaults: LanguageServiceDefaults);
16
14
  private _stopWorker;
17
15
  private _saveStateAndStopWorker;
18
16
  dispose(): void;
19
17
  private _checkIfIdle;
20
18
  private _getClient;
21
- getLanguageServiceWorker(...resources: Uri[]): Promise<KustoWorker>;
19
+ getLanguageServiceWorker(...resources: monaco.Uri[]): Promise<KustoWorker>;
22
20
  }