
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@kusto/monaco-kusto
Advanced tools
Kusto language plugin for the Monaco Editor. It provides the following features when editing CSL, KQL files:
There are 2 APIs to set a Kusto schema:
setSchema
- the passed schema is of type ClusterType
(defined in schema.ts
).
The database in ROOT.database will be the one in context.setSchemaFromShowSchema
- a method to set a schema from the result of the Kusto query .show schema as json
.
The result is a list of databases (see interface Result
in schema.ts
), so when this method is used,
it also requires a cluster URI and the name of the database in context.npm install
npm run watch
from root repo and a live-server will automatically open the index.htmlnpm run prepublishOnly
add the following to your index.html
(or other entry point)
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/bridge.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/kusto.javascript.client.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/newtonsoft.json.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/Kusto.Language.Bridge.min.js"></script>
This is done since this package has a dependency on kusto-language-service
but for now, we couldn't get Bridge.Net
to produce valid modules with valid typescript typings.
Until we do, consumer of this package will have to add the aformentioned lines globally in order for the package to work. In the future we might load these programmatically ourselves (in fact - we already do this for the web monaco language service web worker).
Monaco is using AMD module (actually it now supports ES modules, but we've still not update this pacakge to leverage that). In order to load monaco and monaco-kusto in your application you will need to monaco and monaco-ksuto as static files on your web server, and do do the following (this is in a React app and is taken from an older version of react-monaco-editor
// The MIT License (MIT)
// Copyright (c) 2016-present Leon Shi
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const requireConfig = {
url: 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js',
paths: {
'vs': `${process.env.PUBLIC_URL}/monaco-editor/min/vs`
}
};
componentDidMount() {
const context = this.props.context || window;
if (context.monaco !== undefined) {
this.initMonaco();
return;
}
const { requireConfig } = this.props;
const loaderUrl = requireConfig!.url || 'vs/loader.js';
const onGotAmdLoader = () => {
if (context.__REACT_MONACO_EDITOR_LOADER_ISPENDING__) {
// Do not use webpack
if (requireConfig!.paths && requireConfig!.paths!.vs) {
context.require.config(requireConfig);
}
}
// Load monaco
context.require(['vs/editor/editor.main'], () => {
context.require(['vs/language/kusto/monaco.contribution'], () => {
this.initMonaco();
});
});
// Call the delayed callbacks when AMD loader has been loaded
if (context.__REACT_MONACO_EDITOR_LOADER_ISPENDING__) {
context.__REACT_MONACO_EDITOR_LOADER_ISPENDING__ = false;
const loaderCallbacks = context.__REACT_MONACO_EDITOR_LOADER_CALLBACKS__;
if (loaderCallbacks && loaderCallbacks.length) {
let currentCallback = loaderCallbacks.shift();
while (currentCallback) {
currentCallback.fn.call(currentCallback.context);
currentCallback = loaderCallbacks.shift();
}
}
}
};
resolve.alias
:'vs/language/kusto/kustoMode': 'kustoMode',
'bridge.min': '@kusto/monaco-kusto/release/esm/bridge.min',
'kusto.javascript.client.min': '@kusto/monaco-kusto/release/esm/kusto.javascript.client.min.js',
'Kusto.Language.Bridge.min': '@kusto/monaco-kusto/release/esm/Kusto.Language.Bridge.min.js',
'Kusto': '@kusto/monaco-kusto/release/esm/Kusto.Language.Bridge.min.js',
'monaco.contribution': '@kusto/monaco-kusto/release/esm/monaco.contribution'
module.rules
:{ test: /bridge\.js/, parser: { system: false } },
{ test: /kusto\.javascript\.client\.min\.js/, parser: { system: false } },
{ test: /Kusto\.Language\.Bridge\.min\.js/, parser: { system: false } },
{ test: /kustoLanguageService/, parser: { system: false } },
Also, add the following dependency (shim) as loaders:
{ test: /Kusto\.Language\.Bridge\.min/, loader: 'exports-loader?window.Kusto!imports-loader?bridge.min,kusto.javascript.client.min' },
{ test: /kustoMonarchLanguageDefinition/, loader: 'imports-loader?Kusto' },
module.exports = function loader(source) {
source = `var Kusto = require("@kusto/language-service-next/Kusto.Language.Bridge.min");\n${source}`;
return source.replace(/importScripts.*/g,'');;
}
window.MonacoEnvironment = { getWorkerUrl: function() { return "<path_and_full_name_of_kusto_worker_chunk>"} };
Add "@kusto/monaco-kusto/release/esm/kusto.worker.js" as entry point to your webpack configuration.
You'll need to merge the runtime chunk of this entry point with this entry point output chunk to one chunk, and have this one call in getWorkerUrl in step 5.
Create a monao.editor object from an HTML element:
this.editor = monaco.editor.create(editorElement, editorConfig)
import('monaco.contribution').then(async (contribution: any) => {
const model = this.monaco && this.monaco.editor.createModel("", 'kusto');
this.editor.setModel(model);
const workerAccessor: monaco.languages.kusto.WorkerAccessor = await monaco.languages.kusto.getKustoWorker();
const worker: monaco.languages.kusto.KustoWorker = await workerAccessor(model.uri);
})
enableHover
option to languages settingss.onDidProvideCompletionItems
to languages settings as callback function for doComplete operations.getCommandsInDocumentV2
not to take new lines as command.doRangeFormat
to work with all kind of user text selection.getRenderInfo
in cases where there is not with clause.getRenderInfo
that returns the render command visualization options in a query.setParameters
that set parameters to the schema without providing the entire schema.getReferencedGlobalParams
that returns the global (ambient) parameters that are actually being referenced in the query.getQueryParams
. it will return an array of all delcared query parameters for the query on cursor.getCommandAndLocationInContext
.
it will return both the text and the range of the command in context.<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/bridge.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/kusto.javascript.client.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/newtonsoft.json.min.js"></script>
<script src="%PUBLIC_URL%/monaco-editor/min/vs/language/kusto/Kusto.Language.Bridge.min.js"></script>
<script src="../node_modules/kusto-language-service/kusto.javascript.client.js"></script>
monaco-editor@0.11
so that consumers of the package get a warning if their version of monaco is too old.monaco-editor@0.11.1
to function correctly. adds support for markdown in intellisense documentation.setSchemaFromShowSchema
: a new method to set a schema from the result of .show schema as json exewcutioneditor.action.kusto.formatCurrentCommand
command.getAdminCommand
method to KustoWorker
, which returns an object with a boolean property signifying whether
the text is an admin command, and a string property that contains the command without leading comments.getClientDirective
method to KustoWorker
, which returns an object with a boolean property signifying whether
the text is a client directive, and a string property that contains the directive without leading comments.This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
FAQs
CSL, KQL plugin for the Monaco Editor
The npm package @kusto/monaco-kusto receives a total of 12,235 weekly downloads. As such, @kusto/monaco-kusto popularity was classified as popular.
We found that @kusto/monaco-kusto demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.