-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement error reporting in monaco for painless language #84695
Implement error reporting in monaco for painless language #84695
Conversation
…ss_error_reporting
…ss_error_reporting
…ss_error_reporting
💚 Build SucceededMetrics [docs]Async chunks
Distributable file count
Page load bundle
Unknown metric groups@kbn/ui-shared-deps asset size
History
To update your PR or re-run it, just comment with: |
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
🚀 This is so slick! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @alisonelizabeth ! I tested this locally and it is really awesome to finally see in line error reporting.
It's interesting that package bundle sizes seem relatively unaffected 🤔
.toString() | ||
.split('\n'); | ||
|
||
fileContentRows.unshift('// @ts-nocheck'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Glad to see we can disable TS checks at a file-level!
$('fieldname', <default>) was added in elasticsearch/elastic#80518. This updated the ANTLR grammar so that the syntax check passes. painless_lexer.g4 adapted from elasticsearch/modules/lang-painless/src/main/antlr/PainlessLexer.g4 painless_parser.g4 adapted from elasticsearch/modules/lang-painless/src/main/antlr/PainlessParser.g4 Generated by running `npm run build:antlr4ts` from `packages/kbn-monaco` Related to elastic#84695
This PR adds error reporting in monaco for basic syntax errors in the Painless language.
Continuation of work related to #80577.
Implementation
I integrated ANTLR to track syntax errors (and in the future help support contextual autocomplete) in a Painless script. Elasticsearch already has defined lexer and parser rules for the Painless language. For now, these rules have been largely copied from ES to Kibana and reside in the
antlr
directory with the.g4
file extension (some modifications were needed in order to handle Java-specific code in the grammar). We then use antlr4ts to generate a lexer and a parser in Typescript.The parser is initialized in
parser.ts
. I've implemented anANTLRErrorListener
(error_listener.ts
) which can collect the errors as ANTLR parses the code. The errors include the position in which the error occurred, which can then be passed to monaco to set error model markers.I've updated the readme with this information^. There's also more details in the readme around the script used to generate the lexer and parser in TS.
How to review
Anything under the
antlr
directory includes either the grammar definitions from ES or the generated TS and does not need to be reviewed.Using Painless Lab (or ingest node pipelines UI or the runtime fields editor), write a script and make a syntax error(s) and verify the monaco editor highlights it accordingly.
Future improvements
The current implementation has room for improvement.
Better error messages. The error messages returned from ANTLR are sometimes a little hard to parse. It does appear possible to override them (as ES appears to be doing here and here for the execute API), but needs further investigation.
Maintenance. As mentioned, the antlr grammar is largely copied from ES. If the grammar is ever modified in ES, the UI team would need to be made aware and also apply the changes. While it's probably not likely the language will change too often or drastically, it is not ideal and prone to be forgotten.
Surface syntax error(s) to a form. If the editor is used in the context of a form, it would be helpful to block on submit if there are any syntax errors reported by the editor.