@kusto/monaco-kusto 6.2.0 → 7.0.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,12 +1,7 @@
1
- /// <reference types="../monaco" />
2
- /// <reference types="monaco-editor/monaco" />
3
1
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
4
- import type { LanguageServiceDefaultsImpl } from './monaco.contribution';
5
- import type { KustoWorker } from './kustoWorker';
2
+ import type { LanguageServiceDefaults, LanguageSettings } from './monaco.contribution';
6
3
  import type { Schema } from './languageService/schema';
7
- export interface WorkerAccessor {
8
- (first: monaco.Uri, ...more: monaco.Uri[]): Promise<KustoWorker>;
9
- }
4
+ import { AugmentedWorkerAccessor } from './kustoMode';
10
5
  export declare class DiagnosticsAdapter {
11
6
  private _monacoInstance;
12
7
  private _languageId;
@@ -18,7 +13,7 @@ export declare class DiagnosticsAdapter {
18
13
  private _schemaListener;
19
14
  private _cursorListener;
20
15
  private _debouncedValidations;
21
- constructor(_monacoInstance: typeof globalThis.monaco, _languageId: string, _worker: WorkerAccessor, defaults: LanguageServiceDefaultsImpl, onSchemaChange: monaco.IEvent<Schema>);
16
+ constructor(_monacoInstance: typeof globalThis.monaco, _languageId: string, _worker: AugmentedWorkerAccessor, defaults: LanguageServiceDefaults, onSchemaChange: monaco.IEvent<Schema>);
22
17
  private getMonacoCodeActions;
23
18
  private getOrCreateDebouncedValidation;
24
19
  dispose(): void;
@@ -33,7 +28,7 @@ export declare class ColorizationAdapter {
33
28
  private _configurationListener;
34
29
  private _schemaListener;
35
30
  private decorations;
36
- constructor(_monacoInstance: typeof globalThis.monaco, _languageId: string, _worker: WorkerAccessor, defaults: LanguageServiceDefaultsImpl, onSchemaChange: monaco.IEvent<Schema>);
31
+ constructor(_monacoInstance: typeof globalThis.monaco, _languageId: string, _worker: AugmentedWorkerAccessor, defaults: LanguageServiceDefaults, onSchemaChange: monaco.IEvent<Schema>);
37
32
  dispose(): void;
38
33
  /**
39
34
  * Return true if the range doesn't intersect any of the line ranges.
@@ -46,42 +41,42 @@ export declare class ColorizationAdapter {
46
41
  export declare class CompletionAdapter implements monaco.languages.CompletionItemProvider {
47
42
  private _worker;
48
43
  private languageSettings;
49
- constructor(_worker: WorkerAccessor, languageSettings: globalThis.monaco.languages.kusto.LanguageSettings);
44
+ constructor(_worker: AugmentedWorkerAccessor, languageSettings: LanguageSettings);
50
45
  get triggerCharacters(): string[];
51
46
  provideCompletionItems(model: monaco.editor.IReadOnlyModel, position: monaco.Position, context: monaco.languages.CompletionContext, token: monaco.CancellationToken): monaco.Thenable<monaco.languages.CompletionList>;
52
47
  }
53
48
  export declare class DefinitionAdapter {
54
49
  private _worker;
55
- constructor(_worker: WorkerAccessor);
50
+ constructor(_worker: AugmentedWorkerAccessor);
56
51
  provideDefinition(model: monaco.editor.IReadOnlyModel, position: monaco.Position, token: monaco.CancellationToken): monaco.Thenable<monaco.languages.Definition>;
57
52
  }
58
53
  export declare class ReferenceAdapter implements monaco.languages.ReferenceProvider {
59
54
  private _worker;
60
- constructor(_worker: WorkerAccessor);
55
+ constructor(_worker: AugmentedWorkerAccessor);
61
56
  provideReferences(model: monaco.editor.IReadOnlyModel, position: monaco.Position, context: monaco.languages.ReferenceContext, token: monaco.CancellationToken): monaco.Thenable<monaco.languages.Location[]>;
62
57
  }
63
58
  export declare class RenameAdapter implements monaco.languages.RenameProvider {
64
59
  private _worker;
65
- constructor(_worker: WorkerAccessor);
60
+ constructor(_worker: AugmentedWorkerAccessor);
66
61
  provideRenameEdits(model: monaco.editor.IReadOnlyModel, position: monaco.Position, newName: string, token: monaco.CancellationToken): monaco.Thenable<monaco.languages.WorkspaceEdit>;
67
62
  }
68
63
  export declare class DocumentFormatAdapter implements monaco.languages.DocumentFormattingEditProvider {
69
64
  private _worker;
70
- constructor(_worker: WorkerAccessor);
65
+ constructor(_worker: AugmentedWorkerAccessor);
71
66
  provideDocumentFormattingEdits(model: monaco.editor.IReadOnlyModel, options: monaco.languages.FormattingOptions, token: monaco.CancellationToken): monaco.languages.TextEdit[] | monaco.Thenable<monaco.languages.TextEdit[]>;
72
67
  }
73
68
  export declare class FormatAdapter implements monaco.languages.DocumentRangeFormattingEditProvider {
74
69
  private _worker;
75
- constructor(_worker: WorkerAccessor);
70
+ constructor(_worker: AugmentedWorkerAccessor);
76
71
  provideDocumentRangeFormattingEdits(model: monaco.editor.IReadOnlyModel, range: monaco.Range, options: monaco.languages.FormattingOptions, token: monaco.CancellationToken): monaco.languages.TextEdit[] | monaco.Thenable<monaco.languages.TextEdit[]>;
77
72
  }
78
73
  export declare class FoldingAdapter implements monaco.languages.FoldingRangeProvider {
79
74
  private _worker;
80
- constructor(_worker: WorkerAccessor);
75
+ constructor(_worker: AugmentedWorkerAccessor);
81
76
  provideFoldingRanges(model: monaco.editor.ITextModel, context: monaco.languages.FoldingContext, token: monaco.CancellationToken): monaco.languages.FoldingRange[] | PromiseLike<monaco.languages.FoldingRange[]>;
82
77
  }
83
78
  export declare class HoverAdapter implements monaco.languages.HoverProvider {
84
79
  private _worker;
85
- constructor(_worker: WorkerAccessor);
80
+ constructor(_worker: AugmentedWorkerAccessor);
86
81
  provideHover(model: monaco.editor.IReadOnlyModel, position: monaco.Position, token: monaco.CancellationToken): monaco.Thenable<monaco.languages.Hover>;
87
82
  }
@@ -10,6 +10,7 @@ import k = Kusto.Data.IntelliSense;
10
10
  import k2 = Kusto.Language.Editor;
11
11
  import { Database } from './schema';
12
12
  import type { RenderInfo } from './renderInfo';
13
+ import type { ClusterReference, DatabaseReference } from '../types';
13
14
  export declare enum TokenKind {
14
15
  TableToken = 2,
15
16
  TableColumnToken = 4,
@@ -124,20 +125,13 @@ export interface LanguageService {
124
125
  getDatabaseReferences(document: TextDocument, cursorOffset: number): Promise<DatabaseReference[]>;
125
126
  getClusterReferences(document: TextDocument, cursorOffset: number): Promise<ClusterReference[]>;
126
127
  addDatabaseToSchema(document: TextDocument, clusterName: string, databaseSchema: Database): Promise<void>;
127
- addClusterToSchema(document: TextDocument, clusterName: string, databaseNames: string[]): Promise<void>;
128
+ addClusterToSchema(document: TextDocument, clusterName: string, databaseNames: readonly string[]): Promise<void>;
128
129
  }
129
130
  export type CmSchema = {
130
131
  accounts: k.KustoIntelliSenseAccountEntity[];
131
132
  services: k.KustoIntelliSenseServiceEntity[];
132
133
  connectionString: string;
133
134
  };
134
- export interface DatabaseReference {
135
- databaseName: string;
136
- clusterName: string;
137
- }
138
- export interface ClusterReference {
139
- clusterName: string;
140
- }
141
135
  /**
142
136
  * Obtain an instance of the kusto language service.
143
137
  */
@@ -1,2 +1,2 @@
1
- /// <reference types="monaco-editor/monaco" />
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.worker';
2
2
  export declare const KustoLanguageDefinition: monaco.languages.IMonarchLanguage;
@@ -27,9 +27,14 @@ export interface TabularParameter {
27
27
  columns: Column[];
28
28
  docstring?: string;
29
29
  }
30
- export type InputParameter = ScalarParameter & {
30
+ /**
31
+ * An input parameter either be a scalar in which case it has a name, type and
32
+ * cslType, or it can be columnar, in which case it will have a name, and a list
33
+ * of scalar types which are the column types.
34
+ */
35
+ export interface InputParameter extends ScalarParameter {
31
36
  columns?: ScalarParameter[];
32
- };
37
+ }
33
38
  export interface Function {
34
39
  name: string;
35
40
  body: string;
@@ -1,4 +1,4 @@
1
- /// <reference types="../monaco" />
1
+ import type { OnDidProvideCompletionItems } from '../types';
2
2
  export interface LanguageSettings {
3
3
  includeControlCommands?: boolean;
4
4
  newlineAfterPipe?: boolean;
@@ -7,13 +7,13 @@ export interface LanguageSettings {
7
7
  useSemanticColorization?: boolean;
8
8
  useTokenColorization?: boolean;
9
9
  disabledCompletionItems?: string[];
10
- onDidProvideCompletionItems?: monaco.languages.kusto.OnDidProvideCompletionItems;
10
+ onDidProvideCompletionItems?: OnDidProvideCompletionItems;
11
11
  enableHover?: boolean;
12
12
  formatter?: FormatterOptions;
13
13
  syntaxErrorAsMarkDown?: SyntaxErrorAsMarkDownOptions;
14
14
  enableQueryWarnings?: boolean;
15
15
  enableQuerySuggestions?: boolean;
16
- disabledDiagnoticCodes?: string[];
16
+ disabledDiagnosticCodes?: string[];
17
17
  quickFixCodeActions?: QuickFixCodeActionOptions[];
18
18
  enableQuickFixes?: boolean;
19
19
  }
@@ -26,5 +26,5 @@ export interface SyntaxErrorAsMarkDownOptions {
26
26
  icon?: string;
27
27
  enableSyntaxErrorAsMarkDown?: boolean;
28
28
  }
29
- export type QuickFixCodeActionOptions = 'Extract Expression' | 'Extract Function' | 'Change to';
29
+ export type QuickFixCodeActionOptions = 'Extract Expression' | 'Extract Function' | 'Change to' | 'FixAll';
30
30
  export type FormatterPlacementStyle = 'None' | 'NewLine' | 'Smart';
@@ -1,16 +1,21 @@
1
- /// <reference types="../monaco" />
2
1
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
3
- import type { KustoWorker } from './kustoWorker';
4
- export declare class LanguageServiceDefaultsImpl implements globalThis.globalThis.monaco.languages.kusto.LanguageServiceDefaults {
2
+ import type { LanguageServiceDefaults, WorkerAccessor } from './types';
3
+ import type { LanguageSettings } from './languageService/settings';
4
+ export * from './languageService/schema';
5
+ export * from './languageService/renderInfo';
6
+ export * from './languageService/settings';
7
+ export * from './types';
8
+ export { getCurrentCommandRange } from './extendedEditor';
9
+ declare class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
5
10
  private _onDidChange;
6
11
  private _languageSettings;
7
12
  private _workerMaxIdleTime;
8
- constructor(languageSettings: globalThis.monaco.languages.kusto.LanguageSettings);
9
- get onDidChange(): monaco.IEvent<globalThis.monaco.languages.kusto.LanguageServiceDefaults>;
10
- get languageSettings(): globalThis.monaco.languages.kusto.LanguageSettings;
11
- setLanguageSettings(options: globalThis.monaco.languages.kusto.LanguageSettings): void;
13
+ constructor(languageSettings: LanguageSettings);
14
+ get onDidChange(): monaco.IEvent<LanguageServiceDefaults>;
15
+ get languageSettings(): LanguageSettings;
16
+ setLanguageSettings(options: LanguageSettings): void;
12
17
  setMaximumWorkerIdleTime(value: number): void;
13
18
  getWorkerMaxIdleTime(): number;
14
19
  }
15
- export declare function getKustoWorker(): Promise<(first: monaco.Uri, ...more: monaco.Uri[]) => Promise<KustoWorker>>;
20
+ export declare function getKustoWorker(): Promise<WorkerAccessor>;
16
21
  export declare const kustoDefaults: LanguageServiceDefaultsImpl;
@@ -1,17 +1,67 @@
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.1(d5a041ddb6e4a3a3ebcb2a1aa79da979a62b6da2)
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
+ import { g as getCslTypeNameFromClrType, a as getCallName, b as getExpression, c as getInputParametersAsCslString, d as getEntityDataTypeFromCslType } from './schema-cdbe085f.js';
10
+ export { s as showSchema } from './schema-cdbe085f.js';
11
+
12
+ function getCurrentCommandRange(editor, cursorPosition) {
13
+ const zeroBasedCursorLineNumber = cursorPosition.lineNumber - 1;
14
+ const lines = editor.getModel().getLinesContent();
15
+ let commandOrdinal = 0;
16
+ const linesWithCommandOrdinal = [];
17
+ for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
18
+ let isEmptyLine = lines[lineNumber].trim() === '';
19
+ if (isEmptyLine) {
20
+ // increase commandCounter - we'll be starting a new command.
21
+ linesWithCommandOrdinal.push({
22
+ commandOrdinal: commandOrdinal++,
23
+ lineNumber
24
+ });
25
+ } else {
26
+ linesWithCommandOrdinal.push({
27
+ commandOrdinal: commandOrdinal,
28
+ lineNumber
29
+ });
30
+ }
31
+
32
+ // No need to keep scanning if we're past our line and we've seen an empty line.
33
+ if (lineNumber > zeroBasedCursorLineNumber && commandOrdinal > linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal) {
34
+ break;
35
+ }
36
+ }
37
+ const currentCommandOrdinal = linesWithCommandOrdinal[zeroBasedCursorLineNumber].commandOrdinal;
38
+ const currentCommandLines = linesWithCommandOrdinal.filter(line => line.commandOrdinal === currentCommandOrdinal);
39
+ const currentCommandStartLine = currentCommandLines[0].lineNumber + 1;
40
+ const currentCommandEndLine = currentCommandLines[currentCommandLines.length - 1].lineNumber + 1;
41
+
42
+ // End-column of 1 means no characters will be highlighted - since columns are 1-based in monaco apis.
43
+ // Start-column of 1 and End column of 2 means 1st character is selected.
44
+ // Thus if a line has n column and we need to provide n+1 so that the entire line will be highlighted.
45
+ const commandEndColumn = lines[currentCommandEndLine - 1].length + 1;
46
+ return new monaco.Range(currentCommandStartLine, 1, currentCommandEndLine, commandEndColumn);
47
+ }
48
+
49
+ /**
50
+ * Extending ICode editor to contain additional kusto-specific methods.
51
+ * note that the extend method needs to be called at least once to take affect, otherwise this here code is useless.
52
+ */
53
+ function extend(editor) {
54
+ const proto = Object.getPrototypeOf(editor);
55
+ proto.getCurrentCommandRange = function (cursorPosition) {
56
+ getCurrentCommandRange(this, cursorPosition);
57
+ };
58
+ }
9
59
 
10
60
  /**
11
61
  * Highlights the command that surround cursor location
12
62
  */
13
63
  class KustoCommandHighlighter {
14
- static ID = 'editor.contrib.kustoCommandHighliter';
64
+ static ID = 'editor.contrib.kustoCommandHighlighter';
15
65
  static CURRENT_COMMAND_HIGHLIGHT = {
16
66
  className: 'selectionHighlight'
17
67
  };
@@ -46,7 +96,7 @@ class KustoCommandHighlighter {
46
96
  this.decorations = this.editor.deltaDecorations(this.decorations, []);
47
97
  return;
48
98
  }
49
- const commandRange = this.editor.getCurrentCommandRange(changeEvent.selection.getStartPosition());
99
+ const commandRange = getCurrentCommandRange(this.editor, changeEvent.selection.getStartPosition());
50
100
  const decorations = [{
51
101
  range: commandRange,
52
102
  options: KustoCommandHighlighter.CURRENT_COMMAND_HIGHLIGHT
@@ -87,54 +137,10 @@ class KustoCommandFormatter {
87
137
  }
88
138
  }
89
139
 
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
140
  // --- Kusto configuration and defaults ---------
135
141
 
136
142
  class LanguageServiceDefaultsImpl {
137
- _onDidChange = new monaco$1.Emitter();
143
+ _onDidChange = new monaco.Emitter();
138
144
 
139
145
  // in milliseconds. For example - this is 2 minutes 2 * 60 * 1000
140
146
 
@@ -199,14 +205,14 @@ function withMode(callback) {
199
205
  import('./kustoMode.js').then(callback);
200
206
  }
201
207
  const kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);
202
- monaco$1.languages.onLanguage('kusto', () => {
203
- withMode(mode => mode.setupMode(kustoDefaults, monaco$1));
208
+ monaco.languages.onLanguage('kusto', () => {
209
+ withMode(mode => mode.setupMode(kustoDefaults, monaco));
204
210
  });
205
- monaco$1.languages.register({
211
+ monaco.languages.register({
206
212
  id: 'kusto',
207
213
  extensions: ['.csl', '.kql']
208
214
  });
209
- monaco$1.editor.defineTheme('kusto-light', {
215
+ monaco.editor.defineTheme('kusto-light', {
210
216
  base: 'vs',
211
217
  inherit: true,
212
218
  rules: [{
@@ -290,7 +296,7 @@ monaco$1.editor.defineTheme('kusto-light', {
290
296
  }],
291
297
  colors: {}
292
298
  });
293
- monaco$1.editor.defineTheme('kusto-dark', {
299
+ monaco.editor.defineTheme('kusto-dark', {
294
300
  base: 'vs-dark',
295
301
  inherit: true,
296
302
  rules: [{
@@ -376,7 +382,7 @@ monaco$1.editor.defineTheme('kusto-dark', {
376
382
  // see: https://code.visualstudio.com/api/references/theme-color#editor-widget-colors
377
383
  }
378
384
  });
379
- monaco$1.editor.defineTheme('kusto-dark2', {
385
+ monaco.editor.defineTheme('kusto-dark2', {
380
386
  base: 'vs-dark',
381
387
  inherit: true,
382
388
  rules: [],
@@ -390,7 +396,7 @@ monaco$1.editor.defineTheme('kusto-dark2', {
390
396
 
391
397
  // Initialize kusto specific language features that don't currently have a natural way to extend using existing apis.
392
398
  // Most other language features are initialized in kustoMode.ts
393
- monaco$1.editor.onDidCreateEditor(editor => {
399
+ monaco.editor.onDidCreateEditor(editor => {
394
400
  // hook up extension methods to editor.
395
401
  extend(editor);
396
402
  new KustoCommandHighlighter(editor);
@@ -403,7 +409,7 @@ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
403
409
  editor.onDidChangeCursorSelection(event => {
404
410
  // checking the condition inside the event makes sure we will stay up to date when kusto configuration changes at runtime.
405
411
  if (kustoDefaults && kustoDefaults.languageSettings && kustoDefaults.languageSettings.openSuggestionDialogAfterPreviousSuggestionAccepted) {
406
- var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco$1.editor.CursorChangeReason.NotSet;
412
+ var didAcceptSuggestion = event.source === 'snippet' && event.reason === monaco.editor.CursorChangeReason.NotSet;
407
413
  // If the word at the current position is not null - meaning we did not add a space after completion.
408
414
  // In this case we don't want to activate the eager mode, since it will display the current selected word..
409
415
  if (!didAcceptSuggestion || editor.getModel().getWordAtPosition(event.selection.getPosition()) !== null) {
@@ -423,9 +429,16 @@ function triggerSuggestDialogWhenCompletionItemSelected(editor) {
423
429
  function isStandaloneCodeEditor(editor) {
424
430
  return editor.addAction !== undefined;
425
431
  }
426
- monaco$1.languages.kusto = {
432
+ const globalApi = {
433
+ getCslTypeNameFromClrType,
434
+ getCallName,
435
+ getExpression,
436
+ getInputParametersAsCslString,
437
+ getEntityDataTypeFromCslType,
427
438
  kustoDefaults,
428
- getKustoWorker
439
+ getKustoWorker,
440
+ getCurrentCommandRange
429
441
  };
442
+ monaco.languages.kusto = globalApi;
430
443
 
431
- export { LanguageServiceDefaultsImpl, getKustoWorker, kustoDefaults };
444
+ export { getCallName, getCslTypeNameFromClrType, getCurrentCommandRange, getEntityDataTypeFromCslType, getExpression, getInputParametersAsCslString, getKustoWorker, kustoDefaults };
@@ -0,0 +1,85 @@
1
+ /*!-----------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * monaco-kusto version: 7.0.1(d5a041ddb6e4a3a3ebcb2a1aa79da979a62b6da2)
4
+ * Released under the MIT license
5
+ * https://https://github.com/Azure/monaco-kusto/blob/master/README.md
6
+ *-----------------------------------------------------------------------------*/
7
+
8
+ // Definition of schema object in the context of language services. This model is exposed to consumers of this library.
9
+
10
+ /**
11
+ * An input parameter either be a scalar in which case it has a name, type and
12
+ * cslType, or it can be columnar, in which case it will have a name, and a list
13
+ * of scalar types which are the column types.
14
+ */
15
+
16
+ /**
17
+ * Schema types:
18
+ * Engine – The main schema type. Contains clusters, databases, tables, table columns and functions.
19
+ * Cluster Manager – Internal only. A schema for clusters that manages other clusters.
20
+ * Data Management – Internal only. A schema for ingestion point operations.
21
+ */
22
+
23
+ const dotnetTypeToKustoType = {
24
+ 'System.SByte': 'bool',
25
+ 'System.Byte': 'uint8',
26
+ 'System.Int16': 'int16',
27
+ 'System.UInt16': 'uint16',
28
+ 'System.Int32': 'int',
29
+ 'System.UInt32': 'uint',
30
+ 'System.Int64': 'long',
31
+ 'System.UInt64': 'ulong',
32
+ 'System.String': 'string',
33
+ 'System.Single': 'float',
34
+ 'System.Double': 'real',
35
+ 'System.DateTime': 'datetime',
36
+ 'System.TimeSpan': 'timespan',
37
+ 'System.Guid': 'guid',
38
+ 'System.Boolean': 'bool',
39
+ 'Newtonsoft.Json.Linq.JArray': 'dynamic',
40
+ 'Newtonsoft.Json.Linq.JObject': 'dynamic',
41
+ 'Newtonsoft.Json.Linq.JToken': 'dynamic',
42
+ 'System.Object': 'dynamic',
43
+ 'System.Data.SqlTypes.SqlDecimal': 'decimal'
44
+ };
45
+ const getCslTypeNameFromClrType = clrType => dotnetTypeToKustoType[clrType] || clrType;
46
+ const kustoTypeToEntityDataType = {
47
+ object: 'Object',
48
+ bool: 'Boolean',
49
+ uint8: 'Byte',
50
+ int16: 'Int16',
51
+ uint16: 'UInt16',
52
+ int: 'Int32',
53
+ uint: 'UInt32',
54
+ long: 'Int64',
55
+ ulong: 'UInt64',
56
+ float: 'Single',
57
+ real: 'Double',
58
+ decimal: 'Decimal',
59
+ datetime: 'DateTime',
60
+ string: 'String',
61
+ dynamic: 'Dynamic',
62
+ timespan: 'TimeSpan'
63
+ };
64
+ const getEntityDataTypeFromCslType = cslType => kustoTypeToEntityDataType[cslType] || cslType;
65
+ const getCallName = fn => `${fn.name}(${fn.inputParameters.map(p => `{${p.name}}`).join(',')})`;
66
+ const getExpression = fn => `let ${fn.name} = ${getInputParametersAsCslString(fn.inputParameters)} ${fn.body}`;
67
+ const getInputParametersAsCslString = inputParameters => `(${inputParameters.map(inputParameter => getInputParameterAsCslString(inputParameter)).join(',')})`;
68
+ const getInputParameterAsCslString = inputParameter => {
69
+ // If this is a tabular parameter
70
+ if (inputParameter.columns && inputParameter.columns.length > 0) {
71
+ const attributesAsString = inputParameter.columns.map(col => `${col.name}:${col.cslType || getCslTypeNameFromClrType(col.type)}`).join(',');
72
+ return `${inputParameter.name}:${attributesAsString === '' ? '*' : attributesAsString}`;
73
+ } else {
74
+ return `${inputParameter.name}:${inputParameter.cslType || getCslTypeNameFromClrType(inputParameter.type)}`;
75
+ }
76
+ };
77
+
78
+ /**
79
+ * This is the schema of the output of kusto command
80
+ * .show schema as json
81
+ */
82
+ let showSchema;
83
+ (function (_showSchema) {})(showSchema || (showSchema = {}));
84
+
85
+ export { getCallName as a, getExpression as b, getInputParametersAsCslString as c, getEntityDataTypeFromCslType as d, getCslTypeNameFromClrType as g, showSchema as s };
@@ -0,0 +1,149 @@
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ import type * as ls from 'vscode-languageserver-types';
3
+ import type { Schema, ScalarParameter, TabularParameter, EngineSchema, Database, showSchema } from './languageService/schema';
4
+ import type { RenderInfo } from './languageService/renderInfo';
5
+ import type { LanguageSettings } from './languageService/settings';
6
+ export interface LanguageServiceDefaults {
7
+ readonly onDidChange: monaco.IEvent<LanguageServiceDefaults>;
8
+ readonly languageSettings: LanguageSettings;
9
+ /**
10
+ * Configure language service settings.
11
+ */
12
+ setLanguageSettings(options: LanguageSettings): void;
13
+ /**
14
+ * Configure when the worker shuts down. By default that is 2mins.
15
+ *
16
+ * @param value The maximum idle time in milliseconds. Values less than one
17
+ * mean never shut down.
18
+ */
19
+ setMaximumWorkerIdleTime(value: number): void;
20
+ getWorkerMaxIdleTime(): number;
21
+ }
22
+ export interface KustoWorker {
23
+ setSchema(schema: Schema): Promise<void>;
24
+ setSchemaFromShowSchema(schema: any, clusterConnectionString: string, databaseInContextName: string, globalScalarParameters?: ScalarParameter[], globalTabularParameters?: TabularParameter[]): Promise<void>;
25
+ normalizeSchema(schema: showSchema.Result, clusterConnectionString: string, databaseInContextName: string): Promise<EngineSchema>;
26
+ getCommandInContext(uri: string, cursorOffset: number): Promise<string | null>;
27
+ getCommandAndLocationInContext(uri: string, offset: number): Promise<{
28
+ text: string;
29
+ range: monaco.IRange;
30
+ } | null>;
31
+ getCommandsInDocument(uri: string): Promise<{
32
+ absoluteStart: number;
33
+ absoluteEnd: number;
34
+ text: string;
35
+ }[]>;
36
+ getClientDirective(text: string): Promise<{
37
+ isClientDirective: boolean;
38
+ directiveWithoutLeadingComments: string;
39
+ }>;
40
+ getAdminCommand(text: string): Promise<{
41
+ isAdminCommand: boolean;
42
+ adminCommandWithoutLeadingComments: string;
43
+ }>;
44
+ /**
45
+ * Get all declared query parameters declared in current block if any.
46
+ */
47
+ getQueryParams(uri: string, cursorOffset: number): Promise<{
48
+ name: string;
49
+ type: string;
50
+ }[]>;
51
+ /**
52
+ * Get all the ambient parameters defined in global scope.
53
+ * Ambient parameters are parameters that are not defined in the syntax such as in a query parameter declaration.
54
+ * These are parameters that are injected from outside, usually by a UX application that would like to offer
55
+ * the user intellisense for a symbol, without forcing them to write a query declaration statement.
56
+ * Usually the same application injects the query declaration statement and the parameter values when
57
+ * executing the query (so it will execute correctly)
58
+ */
59
+ getGlobalParams(uri: string): Promise<{
60
+ name: string;
61
+ type: string;
62
+ }[]>;
63
+ /**
64
+ * Get the global parameters that are actually being referenced in query.
65
+ * This is different from getQueryParams that will return the parameters using a query declaration
66
+ * statement.
67
+ * It is also different from getGlobalParams that will return all global parameters whether used or not.
68
+ */
69
+ getReferencedGlobalParams(uri: string, cursorOffset?: number): Promise<{
70
+ name: string;
71
+ type: string;
72
+ }[]>;
73
+ getReferencedSymbols(uri: string, cursorOffset?: number): Promise<{
74
+ name: string;
75
+ kind: string;
76
+ display: string;
77
+ }[]>;
78
+ /**
79
+ * Get visualization options in render command if present (null otherwise).
80
+ */
81
+ getRenderInfo(uri: string, cursorOffset: number): Promise<RenderInfo | null>;
82
+ doDocumentFormat(uri: string): Promise<ls.TextEdit[]>;
83
+ doRangeFormat(uri: string, range: ls.Range): Promise<ls.TextEdit[]>;
84
+ doCurrentCommandFormat(uri: string, caretPosition: ls.Position): Promise<ls.TextEdit[]>;
85
+ doValidation(uri: string, intervals: {
86
+ start: number;
87
+ end: number;
88
+ }[], includeWarnings?: boolean, includeSuggestions?: boolean): Promise<ls.Diagnostic[]>;
89
+ setParameters(scalarParameters: readonly ScalarParameter[], tabularParameters: readonly TabularParameter[]): Promise<void>;
90
+ /**
91
+ * Get all the database references from the current command.
92
+ * If database's schema is already cached in previous calls to setSchema or addDatabaseToSchema it will not be returned.
93
+ * 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.
94
+ * @example
95
+ * If the current command includes: cluster('help').database('Samples')
96
+ * getDatabaseReferences will return [{ clusterName: 'help', databaseName 'Samples' }]
97
+ */
98
+ getDatabaseReferences(uri: string, cursorOffset: number): Promise<DatabaseReference[]>;
99
+ /**
100
+ * Get all the cluster references from the current command.
101
+ * If cluster's schema is already cached it will not be returned.
102
+ * 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.
103
+ * cluster name is returned exactly as written in the KQL `cluster(<cluster name>)` function.
104
+ * @example
105
+ * If the current command includes: cluster('help')
106
+ * it returns [{ clusterName: 'help' }]
107
+ * @example
108
+ * If the current command includes: cluster('https://demo11.westus.kusto.windows.net')
109
+ * getClusterReferences will return [{ clusterName: 'https://demo11.westus.kusto.windows.net' }]
110
+ */
111
+ getClusterReferences(uri: string, cursorOffset: number): Promise<ClusterReference[]>;
112
+ /**
113
+ * Adds a database's scheme. Useful with getDatabaseReferences to load schema for cross-cluster commands.
114
+ * @param clusterName the name of the cluster as returned from getDatabaseReferences/getClusterReferences.
115
+ * @example
116
+ * - User enters cluster('help').database('Samples')
117
+ * - hosting app calls getDatabaseReferences which returns [{ clusterName: 'help', databaseName: 'Samples' }].
118
+ * - hosting app fetches the database Schema from https://help.kusto.windows.net
119
+ * - hosting app calls 'addDatabaseToSchema' with the database's schema.
120
+ * - now, when user types cluster('help').database('Samples') then the auto complete list will show all the tables.
121
+ */
122
+ addDatabaseToSchema(uri: string, clusterName: string, databaseSchema: Database): Promise<void>;
123
+ /**
124
+ * Adds a cluster's databases to the schema. Useful when used with getClusterReferences in cross-cluster commands.
125
+ * @param clusterName the name of the cluster as returned in getClusterReferences.
126
+ * @example
127
+ * - User enters cluster('help')
128
+ * - hosting app calls getClusterReferences which returns [{ clusterName: 'help' }].
129
+ * - hosting app fetches the list of databases from https://help.kusto.windows.net
130
+ * - hosting app calls addClusterToSchema with the list of databases.
131
+ * - now, when user type `cluster('help').database(` then the auto complete list will show all the databases.
132
+ */
133
+ addClusterToSchema(uri: string, clusterName: string, databasesNames: readonly string[]): Promise<void>;
134
+ }
135
+ /**
136
+ * A function that get a model Uri and returns a kusto worker that knows how to work
137
+ * with that document.
138
+ */
139
+ export interface WorkerAccessor {
140
+ (first: monaco.Uri, ...more: monaco.Uri[]): Promise<KustoWorker>;
141
+ }
142
+ export interface DatabaseReference {
143
+ databaseName: string;
144
+ clusterName: string;
145
+ }
146
+ export interface ClusterReference {
147
+ clusterName: string;
148
+ }
149
+ export type OnDidProvideCompletionItems = (list: ls.CompletionList) => Promise<ls.CompletionList>;