@kusto/monaco-kusto
Version:
CSL, KQL plugin for the Monaco Editor
250 lines (249 loc) • 11.3 kB
JavaScript
import * as ls from 'vscode-languageserver-types';
import * as kustoService from './languageServiceManager/kustoLanguageService';
var KustoWorkerImpl = /** @class */ (function () {
function KustoWorkerImpl(ctx, createData) {
this._ctx = ctx;
this._languageSettings = createData.languageSettings;
this._languageService = kustoService.getKustoLanguageService();
this._languageService.configure(this._languageSettings);
}
KustoWorkerImpl.prototype.setSchema = function (schema) {
return this._languageService.setSchema(schema);
};
KustoWorkerImpl.prototype.addClusterToSchema = function (uri, clusterName, databases) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("addClusterToSchema: document is ".concat(document, ". uri is ").concat(uri));
return Promise.resolve();
}
return this._languageService.addClusterToSchema(document, clusterName, databases);
};
KustoWorkerImpl.prototype.addDatabaseToSchema = function (uri, clusterName, databaseSchema) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("addDatabaseToSchema: document is ".concat(document, ". uri is ").concat(uri));
return Promise.resolve();
}
return this._languageService.addDatabaseToSchema(document, clusterName, databaseSchema);
};
KustoWorkerImpl.prototype.setSchemaFromShowSchema = function (schema, clusterConnectionString, databaseInContextName) {
return this._languageService.setSchemaFromShowSchema(schema, clusterConnectionString, databaseInContextName);
};
KustoWorkerImpl.prototype.normalizeSchema = function (schema, clusterConnectionString, databaseInContextName) {
return this._languageService.normalizeSchema(schema, clusterConnectionString, databaseInContextName);
};
KustoWorkerImpl.prototype.getSchema = function () {
return this._languageService.getSchema();
};
KustoWorkerImpl.prototype.getCommandInContext = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getCommandInContext: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
var commandInContext = this._languageService.getCommandInContext(document, cursorOffset);
if (commandInContext === undefined) {
return null;
}
return commandInContext;
};
KustoWorkerImpl.prototype.getQueryParams = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getQueryParams: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
var queryParams = this._languageService.getQueryParams(document, cursorOffset);
if (queryParams === undefined) {
return null;
}
return queryParams;
};
KustoWorkerImpl.prototype.getGlobalParams = function (uri) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getGLobalParams: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
var globalParams = this._languageService.getGlobalParams(document);
if (globalParams === undefined) {
return null;
}
return globalParams;
};
KustoWorkerImpl.prototype.getReferencedSymbols = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getReferencedGlobalParams: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
var referencedParams = this._languageService.getReferencedSymbols(document, cursorOffset);
if (referencedParams === undefined) {
return null;
}
return referencedParams;
};
KustoWorkerImpl.prototype.getReferencedGlobalParams = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getReferencedGlobalParams: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
var referencedParams = this._languageService.getReferencedGlobalParams(document, cursorOffset);
if (referencedParams === undefined) {
return null;
}
return referencedParams;
};
KustoWorkerImpl.prototype.getRenderInfo = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getRenderInfo: document is ".concat(document, ". uri is ").concat(uri));
}
return this._languageService.getRenderInfo(document, cursorOffset).then(function (result) {
if (!result) {
return null;
}
return result;
});
};
/**
* Get command in context and the command range.
* This method will basically convert generate microsoft language service interface to monaco interface.
* @param uri document URI
* @param cursorOffset offset from start of document to cursor
*/
KustoWorkerImpl.prototype.getCommandAndLocationInContext = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getCommandAndLocationInContext: document is ".concat(document, ". uri is ").concat(uri));
return Promise.resolve(null);
}
return this._languageService.getCommandAndLocationInContext(document, cursorOffset).then(function (result) {
if (!result) {
return null;
}
// convert to monaco object.
var text = result.text, _a = result.location.range, start = _a.start, end = _a.end;
return {
range: {
startLineNumber: start.line + 1,
startColumn: start.character + 1,
endLineNumber: end.line + 1,
endColumn: end.character + 1,
},
text: text,
};
});
};
KustoWorkerImpl.prototype.getCommandsInDocument = function (uri) {
var document = this._getTextDocument(uri);
if (!document) {
console.error("getCommandInDocument: document is ".concat(document, ". uri is ").concat(uri));
return null;
}
return this._languageService.getCommandsInDocument(document);
};
KustoWorkerImpl.prototype.doComplete = function (uri, position) {
var document = this._getTextDocument(uri);
if (!document) {
return null;
}
var completions = this._languageService.doComplete(document, position);
return completions;
};
KustoWorkerImpl.prototype.doValidation = function (uri, intervals, includeWarnings, includeSuggestions) {
var document = this._getTextDocument(uri);
var diagnostics = this._languageService.doValidation(document, intervals, includeWarnings, includeSuggestions);
return diagnostics;
};
KustoWorkerImpl.prototype.getResultActions = function (uri, start, end) {
var document = this._getTextDocument(uri);
return this._languageService.getResultActions(document, start, end);
};
KustoWorkerImpl.prototype.doRangeFormat = function (uri, range) {
var document = this._getTextDocument(uri);
var formatted = this._languageService.doRangeFormat(document, range);
return formatted;
};
KustoWorkerImpl.prototype.doFolding = function (uri) {
var document = this._getTextDocument(uri);
var folding = this._languageService.doFolding(document);
return folding;
};
KustoWorkerImpl.prototype.doDocumentFormat = function (uri) {
var document = this._getTextDocument(uri);
var formatted = this._languageService.doDocumentFormat(document);
return formatted;
};
KustoWorkerImpl.prototype.doCurrentCommandFormat = function (uri, caretPosition) {
var document = this._getTextDocument(uri);
var formatted = this._languageService.doCurrentCommandFormat(document, caretPosition);
return formatted;
};
KustoWorkerImpl.prototype.getClassifications = function (uri) {
var document = this._getTextDocument(uri);
return this._languageService.getClassifications(document);
};
KustoWorkerImpl.prototype.getClientDirective = function (text) {
return this._languageService.getClientDirective(text);
};
KustoWorkerImpl.prototype.getAdminCommand = function (text) {
return this._languageService.getAdminCommand(text);
};
KustoWorkerImpl.prototype.findDefinition = function (uri, position) {
var document = this._getTextDocument(uri);
var definition = this._languageService.findDefinition(document, position);
return definition;
};
KustoWorkerImpl.prototype.findReferences = function (uri, position) {
var document = this._getTextDocument(uri);
var references = this._languageService.findReferences(document, position);
return references;
};
KustoWorkerImpl.prototype.doRename = function (uri, position, newName) {
var document = this._getTextDocument(uri);
var workspaceEdit = this._languageService.doRename(document, position, newName);
return workspaceEdit;
};
KustoWorkerImpl.prototype.doHover = function (uri, position) {
var document = this._getTextDocument(uri);
var hover = this._languageService.doHover(document, position);
return hover;
};
KustoWorkerImpl.prototype.setParameters = function (scalarParameters, tabularParameters) {
return this._languageService.setParameters(scalarParameters, tabularParameters);
};
KustoWorkerImpl.prototype.getClusterReferences = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
return Promise.resolve(null);
}
return this._languageService.getClusterReferences(document, cursorOffset);
};
KustoWorkerImpl.prototype.getDatabaseReferences = function (uri, cursorOffset) {
var document = this._getTextDocument(uri);
if (!document) {
return Promise.resolve(null);
}
return this._languageService.getDatabaseReferences(document, cursorOffset);
};
KustoWorkerImpl.prototype._getTextDocument = function (uri) {
var models = this._ctx.getMirrorModels();
for (var _i = 0, models_1 = models; _i < models_1.length; _i++) {
var model = models_1[_i];
if (model.uri.toString() === uri) {
return ls.TextDocument.create(uri, this._languageId, model.version, model.getValue());
}
}
return null;
};
return KustoWorkerImpl;
}());
export { KustoWorkerImpl };
/**
* Used when monaco-editor is resolved via amd modules
*/
export function create(ctx, createData) {
return new KustoWorkerImpl(ctx, createData);
}