Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions package/scripts/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
"extends": "../tsconfig.json",
"include": ["../src/monaco.contribution.ts", "../src/KustoWorker.ts", "../src/KustoMode.ts"],
"compilerOptions": {
"rootDir": "../src",
"module": "esnext",
"moduleResolution": "node",
"outDir": "../release/esm",
"emitDeclarationOnly": true,
"declaration": true,
"noEmit": false,
"types": [
"@kusto/language-service/Kusto.JavaScript.Client",
"@kusto/language-service-next/Kusto.Language.Bridge"
]
"noEmit": false
}
}
11 changes: 1 addition & 10 deletions package/scripts/tsconfig.watch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"include": ["../src/**/*"],
"compilerOptions": {
"rootDir": "../src",
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"preserveWatchOutput": true,
"pretty": true,
"types": [
"@kusto/language-service/Kusto.JavaScript.Client",
"@kusto/language-service-next/Kusto.Language.Bridge"
]
"pretty": true
}
}
1 change: 1 addition & 0 deletions package/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'monaco-editor/esm/vs/editor/editor.worker';
28 changes: 22 additions & 6 deletions package/src/kustoWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import type { ColorizationRange } from './languageService/kustoLanguageService';
import type { RenderInfo } from './languageService/renderInfo';
import type { ClusterReference, DatabaseReference, KustoWorker } from './types';

export interface IWorkerContext<H = undefined> {
/**
* A proxy to the main thread host object.
*/
host: H;
/**
* Get all available mirror models in this worker.
*/
getMirrorModels(): IMirrorModel[];
}

export type InterfaceFor<C> = {
[Member in keyof C]: C[Member];
};
Expand Down Expand Up @@ -71,7 +82,7 @@ export class KustoWorkerImpl {
return this._languageService.getSchema();
}

getCommandInContext(uri: string, cursorOffset: number): Promise<string | null> {
async getCommandInContext(uri: string, cursorOffset: number): Promise<string | null> {
const document = this._getTextDocument(uri);
if (!document) {
console.error(`getCommandInContext: document is ${document}. uri is ${uri}`);
Expand All @@ -86,7 +97,7 @@ export class KustoWorkerImpl {
return commandInContext;
}

getQueryParams(uri: string, cursorOffset: number): Promise<{ name: string; type: string }[]> {
async getQueryParams(uri: string, cursorOffset: number): Promise<null | { name: string; type: string }[]> {
const document = this._getTextDocument(uri);
if (!document) {
console.error(`getQueryParams: document is ${document}. uri is ${uri}`);
Expand All @@ -101,7 +112,7 @@ export class KustoWorkerImpl {
return queryParams;
}

getGlobalParams(uri: string): Promise<{ name: string; type: string }[]> {
async getGlobalParams(uri: string): Promise<null | { name: string; type: string }[]> {
const document = this._getTextDocument(uri);
if (!document) {
console.error(`getGLobalParams: document is ${document}. uri is ${uri}`);
Expand Down Expand Up @@ -131,7 +142,10 @@ export class KustoWorkerImpl {
return referencedParams;
}

getReferencedGlobalParams(uri: string, cursorOffset?: number): Promise<{ name: string; type: string }[]> {
async getReferencedGlobalParams(
uri: string,
cursorOffset?: number
): Promise<null | { name: string; type: string }[]> {
const document = this._getTextDocument(uri);
if (!document) {
console.error(`getReferencedGlobalParams: document is ${document}. uri is ${uri}`);
Expand Down Expand Up @@ -199,7 +213,9 @@ export class KustoWorkerImpl {
});
}

getCommandsInDocument(uri: string): Promise<{ absoluteStart: number; absoluteEnd: number; text: string }[]> {
async getCommandsInDocument(
uri: string
): Promise<null | { absoluteStart: number; absoluteEnd: number; text: string }[]> {
const document = this._getTextDocument(uri);
if (!document) {
console.error(`getCommandInDocument: document is ${document}. uri is ${uri}`);
Expand All @@ -209,7 +225,7 @@ export class KustoWorkerImpl {
return this._languageService.getCommandsInDocument(document);
}

doComplete(uri: string, position: ls.Position): Promise<ls.CompletionList> {
async doComplete(uri: string, position: ls.Position): Promise<null | ls.CompletionList> {
let document = this._getTextDocument(uri);
if (!document) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions package/src/languageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ function getEnumKeys<E>(e: any) {
function getClassificationColorTriplets(): { classification: string; colorLight: string; colorDark: string }[] {
const result = Object.keys(ClassificationKind).map((key) => ({
classification: key,
colorLight: classificationToColorLight[key],
colorDark: classificationToColorDark[key],
colorLight: classificationToColorLight[key as keyof typeof classificationToColorLight],
colorDark: classificationToColorDark[key as keyof typeof classificationToColorLight],
}));
return result;
}
Expand Down
49 changes: 27 additions & 22 deletions package/src/languageService/kustoLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class KustoLanguageService implements LanguageService {

let context = this._rulesProvider.AnalyzeCommand$1(commandTextUntilCursor, currentCommand).Context;

let result = { v: null };
let result: { v: null | k.IntelliSenseRule } = { v: null };
this._rulesProvider.TryMatchAnyRule(commandTextWithoutLastWord, result);
let rule: k.IntelliSenseRule = result.v;

Expand Down Expand Up @@ -779,7 +779,7 @@ class KustoLanguageService implements LanguageService {
const applyCodeActions = this.getApplyCodeActions(document, start, end);
const resultActionsMap: ResultAction[] = applyCodeActions
.map((applyCodeAction) => {
let changes = [];
let changes: ResultAction['changes'] = [];
const codeActionResults = this.toArray(block.Service.ApplyCodeAction(applyCodeAction, start).Actions);
const changeTextAction = codeActionResults.find(
(c) => c instanceof Kusto.Language.Editor.ChangeTextAction
Expand Down Expand Up @@ -1434,7 +1434,7 @@ class KustoLanguageService implements LanguageService {
return Promise.resolve([]);
}

const queryParams = [];
const queryParams: { name: string; type: string }[] = [];
queryParamStatements.forEach((paramStatement: Kusto.Language.Syntax.QueryParametersStatement) => {
paramStatement.WalkElements((el: any) =>
el.ReferencedSymbol && el.ReferencedSymbol.Type
Expand Down Expand Up @@ -1482,7 +1482,9 @@ class KustoLanguageService implements LanguageService {
return Promise.resolve(info);
}

const properties = this.toArray(withClause.Properties);
const properties = this.toArray(
withClause.Properties
) as Kusto.Language.Syntax.SeparatedElement$1<Kusto.Language.Syntax.NamedParameter>[];

const props = properties.reduce<RenderOptions>(
(
Expand All @@ -1498,13 +1500,11 @@ class KustoLanguageService implements LanguageService {
break;
case 'ycolumns':
case 'anomalycolumns':
const nameNodes = this.toArray((property.Element$1.Expression as any).Names);
const nameNodes = this.toArray(
(property.Element$1.Expression as any).Names
) as Kusto.Language.Syntax.SeparatedElement$1<Kusto.Language.Syntax.NameDeclaration>[];

const values = nameNodes.map(
(
nameNode: Kusto.Language.Syntax.SeparatedElement$1<Kusto.Language.Syntax.NameDeclaration>
) => nameNode.Element$1.SimpleName
);
const values = nameNodes.map((nameNode) => nameNode.Element$1.SimpleName);
prev[name] = values;
break;
case 'ymin':
Expand Down Expand Up @@ -1793,25 +1793,28 @@ class KustoLanguageService implements LanguageService {
let kDatabaseInContext: k.KustoIntelliSenseDatabaseEntity = undefined;

kCluster.ConnectionString = schema.cluster.connectionString;
const databases = [];
const databases: k.KustoIntelliSenseDatabaseEntity[] = [];
schema.cluster.databases.forEach((database) => {
const kDatabase = new k.KustoIntelliSenseDatabaseEntity();
kDatabase.Name = database.name;
const tables = [];
const tables: k.KustoIntelliSenseTableEntity[] = [];
database.tables.forEach((table) => {
const kTable = new k.KustoIntelliSenseTableEntity();
kTable.Name = table.name;
const cols = [];
const cols: k.KustoIntelliSenseColumnEntity[] = [];
table.columns.forEach((column) => {
const kColumn = new k.KustoIntelliSenseColumnEntity();
kColumn.Name = column.name;
kColumn.TypeCode = k.EntityDataType[getEntityDataTypeFromCslType(column.type)];
kColumn.TypeCode =
k.EntityDataType[
getEntityDataTypeFromCslType(column.type) as keyof typeof k.EntityDataType
];
cols.push(kColumn);
});
kTable.Columns = new Bridge.ArrayEnumerable(cols);
tables.push(kTable);
});
const functions = [];
const functions: k.KustoIntelliSenseFunctionEntity[] = [];
database.functions.forEach((fn) => {
const kFunction = new k.KustoIntelliSenseFunctionEntity();
(kFunction.Name = fn.name),
Expand Down Expand Up @@ -2023,10 +2026,12 @@ class KustoLanguageService implements LanguageService {
}

// Remove deleted databases from cache
const schemaDbLookup: { [dbName: string]: s.Database } = schema.cluster.databases.reduce(
(prev, curr) => (prev[curr.name] = curr),
{}
);
const schemaDbLookup: { [dbName: string]: s.Database } = schema.cluster.databases.reduce<
Record<string, s.Database>
>((prev, curr) => {
prev[curr.name] = curr;
return prev;
}, {});
Object.keys(cached).map((dbName) => {
if (!schemaDbLookup[dbName]) {
delete cached.dbName;
Expand Down Expand Up @@ -2346,7 +2351,7 @@ class KustoLanguageService implements LanguageService {
);
}

private _kustoKindtolsKind = {
private _kustoKindtolsKind: Record<k.OptionKind, ls.CompletionItemKind> = {
[k.OptionKind.None]: ls.CompletionItemKind.Interface,
[k.OptionKind.Operator]: ls.CompletionItemKind.Method,
[k.OptionKind.Command]: ls.CompletionItemKind.Method,
Expand All @@ -2372,7 +2377,7 @@ class KustoLanguageService implements LanguageService {
[k.OptionKind.FunctionFilter]: ls.CompletionItemKind.Field,
[k.OptionKind.FunctionScalar]: ls.CompletionItemKind.Field,
[k.OptionKind.ClientDirective]: ls.CompletionItemKind.Enum,
};
} as Record<k.OptionKind, ls.CompletionItemKind>; // TODO: Add missing keys and remove this cast

private _kustoKindToLsKindV2: { [k in k2.CompletionKind]: ls.CompletionItemKind } = {
[k2.CompletionKind.AggregateFunction]: ls.CompletionItemKind.Field,
Expand Down Expand Up @@ -2423,7 +2428,7 @@ class KustoLanguageService implements LanguageService {
return (Bridge as any).toArray(bridgeList);
}

private static toBridgeList(array): any {
private static toBridgeList(array: any): any {
// copied from bridge.js from the implementation of Enumerable.prototype.toList
return new (System.Collections.Generic.List$1(System.Object).$ctor1)(array);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.worker';
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';

export const KustoLanguageDefinition: monaco.languages.IMonarchLanguage = {
name: 'kusto',
Expand Down
8 changes: 6 additions & 2 deletions package/src/languageService/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ const dotnetTypeToKustoType = {
'System.Object': 'dynamic',
'System.Data.SqlTypes.SqlDecimal': 'decimal',
};
export const getCslTypeNameFromClrType = (clrType: string): string => dotnetTypeToKustoType[clrType] || clrType;

export const getCslTypeNameFromClrType = (clrType: string): string =>
(dotnetTypeToKustoType as Record<string, string>)[clrType] || clrType;

const kustoTypeToEntityDataType = {
object: 'Object',
Expand All @@ -133,7 +135,9 @@ const kustoTypeToEntityDataType = {
dynamic: 'Dynamic',
timespan: 'TimeSpan',
};
export const getEntityDataTypeFromCslType = (cslType: string): string => kustoTypeToEntityDataType[cslType] || cslType;

export const getEntityDataTypeFromCslType = (cslType: string): string =>
(kustoTypeToEntityDataType as Record<string, string>)[cslType] || cslType;

export const getCallName = (fn: Function): string =>
`${fn.name}(${fn.inputParameters.map((p) => `{${p.name}}`).join(',')})`;
Expand Down
2 changes: 1 addition & 1 deletion package/src/monaco.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function withMode(callback: (module: typeof mode) => void): void {
export const kustoDefaults = new LanguageServiceDefaultsImpl(defaultLanguageSettings);

monaco.languages.onLanguage('kusto', () => {
withMode((mode) => mode.setupMode(kustoDefaults, monaco as typeof globalThis.monaco));
withMode((mode) => mode.setupMode(kustoDefaults, monaco));
});

monaco.languages.register({
Expand Down
2 changes: 2 additions & 0 deletions package/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"lib": ["es2020", "dom", "WebWorker.ImportScripts"],
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": false,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"types": [
Expand Down