chore(yql): highlight using monaco-yql-languages [YTFRONT-4282]#1409
chore(yql): highlight using monaco-yql-languages [YTFRONT-4282]#1409vityaman wants to merge 1 commit intoytsaurus:mainfrom
Conversation
Reviewer's GuideReplaces the locally maintained YQL Monaco language definition with the upstream monaco-yql-languages package, aligns editor themes with the new token set, and updates dependencies related to Monaco/YQL autocomplete and suggestions weighting. Sequence diagram for YQL Monaco language and theme usagesequenceDiagram
actor User
participant YTWebUI
participant MonacoEditor
participant LocalYqlModule as MonacoYqlYql
participant ExternalYqlPkg as MonacoYqlLanguagesPkg
User ->> YTWebUI: Open YQL editor
YTWebUI ->> MonacoEditor: Initialize editor instance
MonacoEditor ->> LocalYqlModule: Request conf and language
LocalYqlModule ->> ExternalYqlPkg: getLanguage(ansi: false) and conf
ExternalYqlPkg -->> LocalYqlModule: LanguageConfiguration and MonarchLanguage
LocalYqlModule -->> MonacoEditor: Provide conf and language
YTWebUI ->> MonacoEditor: Apply YT_LIGHT_HC and YT_DARK_HC themes
loop Typing query
User ->> MonacoEditor: Type YQL query
MonacoEditor ->> MonacoEditor: Tokenize using monaco-yql-languages
MonacoEditor ->> MonacoEditor: Colorize tokens via updated rules
end
Class diagram for Monaco YQL language module, themes, and suggestionsclassDiagram
class MonacoYqlYql {
+conf
+language
+language = getLanguage(ansi: boolean)
}
class MonacoEditorThemes {
+lightRules: TokenRule[]
+darkRules: TokenRule[]
+defineLightTheme(): void
+defineDarkTheme(): void
}
class TokenRule {
+token: string
+foreground: string
+fontStyle: string
}
class GenerateSuggestions {
+SuggestionsWeight: Record~SuggestionType, number~
}
class SuggestionType {
<<enumeration>>
suggestTables
suggestPragmas
binding
connection
suggestVariables
suggestColumns
suggestColumnAliases
suggestKeywords
}
MonacoEditorThemes --> TokenRule : uses
GenerateSuggestions --> SuggestionType : uses
MonacoYqlYql ..> MonacoEditorThemes : token names align
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
727d687 to
83fd408
Compare
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
getLanguageandconfimports are taken frommonaco-yql-languages/build/..., which looks like an internal path; if the package exposes stable top-level exports, prefer those to avoid breakage on internal layout changes. - The light and dark theme rules now contain duplicate token entries (e.g.
string.sql,comment) and copy‑pasted color definitions; consider consolidating these in a shared constants module and removing duplicates to keep the theme configuration easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `getLanguage` and `conf` imports are taken from `monaco-yql-languages/build/...`, which looks like an internal path; if the package exposes stable top-level exports, prefer those to avoid breakage on internal layout changes.
- The light and dark theme rules now contain duplicate token entries (e.g. `string.sql`, `comment`) and copy‑pasted color definitions; consider consolidating these in a shared constants module and removing duplicates to keep the theme configuration easier to maintain.
## Individual Comments
### Comment 1
<location> `packages/ui/src/ui/components/MonacoEditor/MonacoEditorThemes.tsx:13-15` </location>
<code_context>
+ {token: 'string.tablepath', foreground: '338186'},
+ {token: 'constant.yql', foreground: '608b4e'},
+ {token: 'keyword.type', foreground: '4d932d'},
+ {token: 'string.sql', foreground: 'a31515'},
+ {token: 'support.function', foreground: '7a3e9d'},
+ {token: 'constant.other.color', foreground: '7a3e9d'},
</code_context>
<issue_to_address>
**suggestion:** Avoid duplicating the same `string.sql` rule in `lightRules`.
`lightRules` now has two identical entries for `token: 'string.sql', foreground: 'a31515'` (one in the new block and one in the existing rules). Please consolidate to a single `string.sql` rule to avoid confusion and simplify future changes.
```suggestion
{token: 'tablepath', foreground: '3e999f'},
{token: 'path', foreground: '3e999f', fontStyle: 'underline'},
});
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| {token: 'tablepath', foreground: '3e999f'}, | ||
| {token: 'path', foreground: '3e999f', fontStyle: 'underline'}, | ||
| {token: 'string.sql', foreground: 'a31515'}, |
There was a problem hiding this comment.
suggestion: Avoid duplicating the same string.sql rule in lightRules.
lightRules now has two identical entries for token: 'string.sql', foreground: 'a31515' (one in the new block and one in the existing rules). Please consolidate to a single string.sql rule to avoid confusion and simplify future changes.
| {token: 'tablepath', foreground: '3e999f'}, | |
| {token: 'path', foreground: '3e999f', fontStyle: 'underline'}, | |
| {token: 'string.sql', foreground: 'a31515'}, | |
| {token: 'tablepath', foreground: '3e999f'}, | |
| {token: 'path', foreground: '3e999f', fontStyle: 'underline'}, | |
| }); |
|
@Raubzeug, is it possible somehow to share the YQL themes? Now I just copy-pasted a JSON-object with rules. Are there other ways to share, except a rules extraction to a separate variables? How the theme is shared between YDB Web UI and YQL Web UI now? |
There was a problem hiding this comment.
I installed all the dependencies, but I get the error Cannot find module 'monaco-yql-languages/build/yql/yql' when starting the project.
There was a problem hiding this comment.
I removed it. Package monaco-yql-languages is intended to be used only with monaco-editor-webpack-plugin.
I noticed that this plugin is already added to the project. Surprisingly, only an addition of the monaco-yql-languages as a dependency to package.json triggered theirs YQL definition registration.
Theirs registration was overwritten by the registration at libs/monaco-yql-languages/_.contribution.ts, so I disabled it for MonacoLanguage.YQL. It seems, that it also let us to overwrite the yql_ansi, which is actually YT QL (LOL), and s-expressions, which is actually SPYT (LOL 2).
I tried to make autocompletion work, but failed. I noticed that it does not work even on the main branch. I hope, that it should be registered as always and also overwrite autocompletion from the monaco-yql-languages (if it registers it somehow).
@SimbiozizV, can you, please, test the solution again?
7ba47dd to
9312ddc
Compare
Signed-off-by: vityaman <vityaman.dev@yandex.ru>
9312ddc to
2f61dc5
Compare
| lazyLanguageLoader.load().then((mod) => { | ||
| languages.setLanguageConfiguration(languageId, mod.conf); | ||
|
|
||
| if (languageId !== MonacoLanguage.YQL) { |
There was a problem hiding this comment.
| if (languageId !== MonacoLanguage.YQL) { | |
| // YQL is registered via `ydb-platform/monaco-yql-languages` | |
| if (languageId !== MonacoLanguage.YQL) { |
|
|
||
| {token: 'tablepath', foreground: '3e999f'}, | ||
| {token: 'path', foreground: '3e999f', fontStyle: 'underline'}, | ||
| {token: 'string.sql', foreground: 'a31515'}, |
There was a problem hiding this comment.
There were 2 rules for string.sql in one list.
| lazyLanguageLoader.load().then((mod) => { | ||
| languages.setLanguageConfiguration(languageId, mod.conf); | ||
|
|
||
| if (languageId !== MonacoLanguage.YQL) { |
There was a problem hiding this comment.
Perhaps because of this rule, yql has now lost its highlighting.
|
|
||
| {token: 'tablepath', foreground: '3e999f'}, | ||
| {token: 'path', foreground: '3e999f', fontStyle: 'underline'}, | ||
| {token: 'string.sql', foreground: 'ce9178'}, |
https://nda.ya.ru/t/WwcKXZO07Qv4JL
Current YQL syntax highlighting at the YT Web UI seems so outdated. This patch updates it by using the package `monaco-yql-languages` maintained by YQL UI team members.Testing Query:
https://github.com/ydb-platform/ydb/blob/main/yql/essentials/tools/yql_highlight/ut/query.yql
Old vs New syntax highlighting:
Summary by Sourcery
Update YQL Monaco integration to use the shared monaco-yql-languages package and align editor theming and autocomplete with it.
New Features:
Enhancements:
Build: