Add ES|QL syntax highlighting to EuiCodeBlock
and EuiMarkdown
components
#8046
Replies: 4 comments 16 replies
-
Thanx Drew for the investigation! I am assuming that more and more places in kibana would want to show an ES|QL query as a code block / markdown so it would be awesome to support it in EUI. If not, we could handle it at the kibana side. So interested in seeing what you think @JasonStoltz. It would help us to prioritize accordingly. |
Beta Was this translation helpful? Give feedback.
-
I did notice that we are currently using regex-based rules, similar to what |
Beta Was this translation helpful? Give feedback.
-
VSCode uses TextMate grammars for syntax highlighting (example: https://github.com/rosshamish/kuskus/blob/master/kusto-syntax-highlighting/syntaxes/kusto.tmLanguage.json) If there were a way to generate a grammar like this from what's happening in Kibana that could drive VSCode syntax highlighting. |
Beta Was this translation helpful? Give feedback.
-
I've looked into This work could also decrease the overall bundle size by eliminating the need to ship multiple tokenizers/parsers/regex-based processors to clients and instead provide a single solution to support them all. This would be pretty complicated to pull off, though... My general take on this issue is that I don't fully love having the DSL for As an immediate solution, I'd suggest adding a lightweight, regex-based ESQL parser to cover 99% of its syntax and have it correctly highlighted. Without a (somewhat heavy) language processor, there's no way to support 100% of the language features anyway, and it usually isn't needed just for syntax highlighting. |
Beta Was this translation helpful? Give feedback.
-
It would be great to support syntax highlighting for ES|QL in EUI.
ES|QL is key to our strategy as a company. Users interact with ES|QL primarily through the ES|QL editor:
However there are a couple of prominent places we are displaying ES|QL queries in Kibana using EUI. One is the inline documentation. Another is the AI assistants.
Example from the inline docs (uses EuiMarkdown, no highlighting):
Full support in EUI would improve the appearance of these occurrences and encourage the use of both ES|QL and EUI.
ES|QL technical background
ES|QL syntax highlighting in the editor is supported by the Monaco and ANTLR libraries (editor, and parser-generator). Our lexer generates a list of tokens given an ES|QL query. Then, these tokens are passed to Monaco, along with a set of coloring rules that are applied based on the token identifier.
The lexer currently lives in Kibana itself. It is generated code so it is automatically updated on a weekly basis from any changes made in the ANTLR grammar on the Elasticsearch side. ES|QL is an evolving language, so this is a plus.
EUI technical background
EUI’s syntax highlighting is tightly coupled with the
refractor
library and thePrism
library which it wraps. Prism allows custom languages to be registered, but they are based on regex rules. Simple example:As I understand it,
refractor
generates an AST from thePrism
highlighting and then EUI renders that AST into the code blocks.Questions/technical thinking
First I thought about how we might integrate ES|QL seamlessly into EUI’s current system. Prism does not support imperatively-defined language definitions, so leveraging our existing lexer is not an option. We would essentially have to come up with regex based rules for ES|QL. We would not reap the benefits of our automatic updates to the lexer, since the regex rules would need to updated as a separate step. However, this approach has the benefit of not requiring any refactor on EUI’s side, and offering ES|QL support in a popular library like Prism might be a nice thing strategically.
Another option I thought of was to build a
refractor
-like API that uses the existing lexer under-the-hood to generate arefractor
AST. EUI would have the responsibility of routing ES|QL queries to this API instead ofrefactor
, but very little would have to change in the downstream rendering system. This custom AST generator could either be injected into the relevant EUI components from Kibana, or the lexer could be separated from Kibana, becoming a shared dependency between Kibana and EUI. There are pros and cons to either strategy and one might be a stepping stone to another.Custom theming
There is also the question of custom theming. We have defined custom theming for the ES|QL editor (though using EUI theme colors). We might like to keep that same theme consistent for all appearances of ES|QL in Kibana. This opens the question of code theme overrides. Again, here we have the option to have these injected from Kibana, or we could house them in EUI and import them into Kibana.
Conclusion
I am thinking broadly here and hoping to get technical feedback and ideas from the EUI team. No need to view this as anything more than a discussion about the technical landscape. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions