Kusto language plugin for the Monaco Editor. It provides the following features when editing CSL, KQL files:
- Code completion
- Syntax highlighting
- Validation: Syntax errors and linting
- code folding / outlining
- Hovers
- Find definition
- find all references
- rename symbol
See the following path for a sample create-react-app project:
- npm i monaco-editor
- npm i @kusto/monaco-kusto
-
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 getBridge.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).
-
In order to load monaco and monaco-kusto in your application you will need to host monaco and monaco-kusto as static files on your web server, and use monaco's loader.js to load them. for an example on how to do this, you can take a look at our sample code here
- define the following aliases in
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'
- define following loaders in
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' },
- Add the following custom loader to replace the importScripts usage in KustoLanguageService and use it:
module.exports = function loader(source) {
source = `var Kusto = require("@kusto/language-service-next/Kusto.Language.Bridge.min");\n${source}`;
return source.replace(/importScripts.*/g,'');;
}
- Define the following function in your window:
window.MonacoEnvironment = { globalAPI: true, 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)
- call monaco.contribution api:
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);
})
There are 2 APIs to set a Kusto schema:
setSchema
- the passed schema is of typeClusterType
(defined inschema.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 interfaceResult
inschema.ts
), so when this method is used, it also requires a cluster URI and the name of the database in context.
- Install Node.js (v6.10.3 or later) from https://nodejs.org/
- clone repo and
npm install
- run
npm run watch
from root repo and a live-server will automatically open the index.html
npm run prepublishOnly
- fix: trigger suggestion when previous suggestion selected.
- fix: low color contrast for foreground/background in suggestWidget for dark theme
- fix: low color contrast for foreground/background in suggestWidget
- fix:
setSchemaFromShowSchema
now supports for external tables.
- fix: update language service to latest version. fixes issues with scan operator being shown first in completion list.
- fix: don't do kusto specific highlighting when other language is selected.
- BREAKING CHANGE: update monaco-editor-core and monaco-editor version to 0.24.0
- Usage for ESM modules: add
globalAPI: true
in window.MonacoEnvironment declaration to havemonaco
on the window
- fix: external table erroneously shown for materialized views
- feat: update language service
- feat: expose custom syntax error message options
- feat: update language service to support python code strings
- fix:
RenderOptions
type missingnull
property union variants
- fix: errors are shown twice on hover
- update language service.
- Expose formatting options
- Bug fix:
union *
is auto-formatted intounion*
- Bug fix: Intellisense doesn't show columns when using this syntax
materialized_view("<table name>") | where
- Bug Fix: In
mv-expand kind=array
kind is shown with a squiggly error line - Update @kusto/language-service-next
- Colorize public query options.
- Bug Fix: Format query hangs in some use cases.
- A function validation fails (shows squiggly red lines), if the function is defined with a parameter that has a default value, but it is used without passing a value for that parameter.
- Fix bug: Scalars function parameters are always showing "Table expected" error with squiggly error red line when using setSchemaFromShowSchema.
- Missing tokens are no longer added when formatting queries.
- Fix exception "Cannot read property 'getText' of null TypeError: Cannot read property 'getText' of null at e.parseDocumentV2"
- Added a sample react project
- Upgrade to latest monaco (which includes many changes amongst them accessibility improvements)
- Fix typo in 2.1.14.
- Add a theme with a darker background color.
- Fix error "Database has no tables".
- Allow formatting commands in cursor location.
- Upgrade to latest bridge.net which fixes an exception from indexOf.
- Schema with no functions was throwing "Cannot read property 'map' of undefined".
- Add DocString to onHover tooltip
- Update language service.
- Updated render kind typing to include map.
- Added
enableHover
option to languages settingss.
- Added
onDidProvideCompletionItems
to languages settings as callback function for doComplete operations.
- Fix
getCommandsInDocumentV2
not to take new lines as command.
- Fix
doRangeFormat
to work with all kind of user text selection.
- Added esm release bundles.
- Added package.json scripts to replace gulp completely.
- Fix
getRenderInfo
in cases where there is not with clause.
- Some more type fixes.
- Fixed typings.
- Added
getRenderInfo
that returns the render command visualization options in a query.
- Added
setParameters
that set parameters to the schema without providing the entire schema.
- Added
getReferencedGlobalParams
that returns the global (ambient) parameters that are actually being referenced in the query.
- Control command completion bug fix (updating intellisense library)
- null pointer exception fix.
- actually made the change described in 2.0.0
- [Breaking] Change default to use intellisense V2
- fix exception in CM & DM clusters when intellisenseV2 is on
- Abiltiy to get global parameters in scope (getGlobalParams)).
- Ability to injet global parameters to intellisense (in setSchema)
- Updated language service
- Fix corrupt monaco.d.ts
- Introduce a new function in language service called
getQueryParams
. it will return an array of all delcared query parameters for the query on cursor.
- Fix 1.1.13 to return ranges based on 1 (as monaco expects) rather than 0 (as kusto language server returns).
- Introduce a new function in language service called
getCommandAndLocationInContext
. it will return both the text and the range of the command in context.
- Update language service to latest version.
- Fix IE compatibility issue (remove new URL usage)
- Fix broken dependency on language service.
- don't suggest chart types that we do not support yet.
- don't kill web worker after 2 minutes of inactivity by default. Reason: In exterme cases where schema is very large, trying to stringify the schema in web worker causes an OOM. This is configurable though.
- Fix broken Diagnostics
- Fix vulnerability in dependency
- Support for adding and removing line comments with keyboard shortcut.
- Support hover
- Support for go-to definition, find all refrences, rename symbol.
- [Breaking] put minified versions of language serivce in npm package.
- [How to migrate]:
include the .min (minified files) rather than the unminified files (which are no longer available)
<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>
- Increase contrast of operators in syntax highlighting.
- Updated dependency @kusto/language-service-next.
- Updated dependency on @kusto/language-service.
- [Breaking] Support monaco-editor v15. This removes supprot for pre 15 versions.
- Abiltiy to suppress completion items from intellisense.
- Dark theme support (set by calling monaco.editor.setTheme('kusto.dark'))
- Don't try to run logic on disposed models.
- Format current command always formatted the 1st command.
- Removed completion options that arent' curerntly supported.
- Colorization didn't work when asked to colorize entire document
- Updated language server dependnecy to latest version.
- improve V2 intellisense colorization performance.
- V2 intellisense now correctly reverts to V1 for control commands.
- Add decimal support to V2 instllisense .
- Fix v2 intellisense.
- fix quirks in interactions between non-semantic and semantic colorization by not using semantic coloring to color plain text.
- Fixed an issue where colorization is working on an older vesion of the document, which results in wrong colorization.
- Intellisense didn't work properly when editing in the middle of a block that is not the 1st block on the page.
- Monarch colorization now colorizes sub-opeators the same as semantic colorization (which makes the changes less jarring when completing semantic colorization).
- When switching context, colorization didn't recolorize.
- (perf) Only colorize the currently edited block(s) - this supports multi-cursor editing
- (perf) don't deeply parse the entire doc when doing completion. just get the list of commands and then parse the relevant command's all tokns.
- removed semantic colorization from main thread. From now on basic colorization (schema-unaware) will happen on main thread, and semantic colorization will happen in background thread. This should improve typing performance on long rows, or on large databases.
- Support for DM intellisense
- fix incorrect column types
- upgrade to latest kusto.javascript.client (based on a newer version of bridge.net and the code itself)
- upgrade to latest Kusto.Language.Bridge (based on a newer version of bridge.net and the code itself)
- improve performance for function parsing by levaraging new functionality in Kusto.Language.Bridge.
- Update langauge service dependencies to versions with unified bridge.net version and bridge.json settings.
- [breaking] Cache clutsser schema in memory. This breaks backward compatibility since it now requries schema to include minor and major version of databases.
- Upgrade version of Kusto.Language.Bridge so solve some issues.
- enable get current command logic to V2.
- Fix ability to set schema using .show schema as json.
- fix bug that caused diagnostics and colorizaiton to be wrong until first text was typed.
- fix bug that rendered validation unusable
- Add colorization support to intellisense API v2
- Add functions support to intellisense API V2
- update version of @kusto/language-service-next to 0.0.10, integrated following functionality:
- library orders items on its own, so no need to order in monaco-kusto
- add support for the cursor not ending in the end of the completion text (like in the 1st parmaeter7 of a function for example)
- add '|' after table name
- Make sure to never parse the same text more than once.
- add diagnostics (a.k.a error message) support (when v2 parser enabled).
- add folding (a.k.a outlining) support. one can now fold commands and hide them from screen.
- [breaking] - introduce new intellisense library (off by default). requires adding the following line to code
<script src="../node_modules/kusto-language-service/kusto.javascript.client.js"></script>
- [breaking] - Update monaco-editor peer dependency to "^0.12.0" because of bug fixes performed there. Also making the dependency more permissive (allow later minor versions).
- Add missing dependency bridge newtonsoft.json.js to npm package.
- updated @kusto/lagnuage-service to latest version. this contains the latest operators, documentation, and charting logic.
- Added peer dependency for
monaco-editor@0.11
so that consumers of the package get a warning if their version of monaco is too old.
- [breaking] - The package now requires
monaco-editor@0.11.1
to function correctly. adds support for markdown in intellisense documentation.
- Added
setSchemaFromShowSchema
: a new method to set a schema from the result of .show schema as json exewcution
- [breaking]: make setSchema async so that big schemas do not block the ui thread (specifically - tokenization code is running in ui thread so it can block rendering).
- fixed label casing of
editor.action.kusto.formatCurrentCommand
command.
- add
getAdminCommand
method toKustoWorker
, 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.
- null pointer exception when creating and destroying multiple monaco models
- add
getClientDirective
method toKustoWorker
, 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.
- fix getCurrentCommand bug when there are multiple commands in document
- fix intellisense issue when trying to get suggestions for a new query (2 newlines after previous query)
- command formatting and document formatting now work (ctrl K + ctrl F and alt+shift+F respectively)
- setSchema does not update syntax highlighting
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.