-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Console] Add theme and more lexer rules (#178757)
## Summary This PR adds a theme for the Console language in Monaco editor and adds more lexer rules to bring the highlighting of the input closed to the original in Ace editor. ### Screenshots Monaco editor <img width="682" alt="Screenshot 2024-03-19 at 12 38 07" src="https://github.com/elastic/kibana/assets/6585477/98a1acc7-3a8a-4ad9-a79e-5236091c4c39"> Ace editor <img width="651" alt="Screenshot 2024-03-19 at 12 37 52" src="https://github.com/elastic/kibana/assets/6585477/37935a68-923b-493c-ac56-ef4982f27fdf"> ### How to test 1. Add `console.dev.enableMonaco: true` to `kibana.dev.yml`` 2. Type different requests into Console and check that the highlighting works the same as in Ace. For example, use the following requests ``` GET ${pathVariable}/_search { "query": { "match": { "${bodyNameVariable}": "${bodyValueVariable}", "number_property": 1234, "array_property": ["test1", 1234, false], "boolean_property": true, "text_property": "text_value", "triple_quote": """ inside triple quote """ // line comment /* block comment */ } } } // line comment /* block comment */ GET _sql { "query": """ SELECT "field" FROM "index-*" WHERE "column" = "value" """ } ``` 3. To check that `xjson` highlighting still works a. Navigate to Ingest pipelines and click the "create from csv" button b. Load a valid csv file, for example this [one](https://github.com/kgeller/ecs-mapper/blob/master/example/mapping.csv) #### Known issues that will be addressed in follow up PRs - SQL highlighting needs to be re-implemented (added to the follow up list in #176926) - Strings inside triple quotes are not using italics (added to the follow up list in #176926) - Font size needs to be set via settings and the default value provided (fixed via #178982) - Font family: do we want to use the same font as for other Monaco languages are use the one for Ace? (added to the follow up list in #176926) - In the future, we might want to use the same theme for `xjson` and Console (added to the follow up list in #176926) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
f320d56
commit c59016e
Showing
15 changed files
with
305 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const themeRuleGroupBuilderFactory = | ||
(postfix: string = '') => | ||
(tokens: string[], color: string, isBold: boolean = false) => | ||
tokens.map((i) => ({ | ||
token: i + postfix, | ||
foreground: color, | ||
fontStyle: isBold ? 'bold' : '', | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { makeHighContrastColor } from '@elastic/eui'; | ||
import { darkMode, euiThemeVars } from '@kbn/ui-theme'; | ||
|
||
import { themeRuleGroupBuilderFactory } from '../common/theme'; | ||
import { monaco } from '../monaco_imports'; | ||
|
||
const buildRuleGroup = themeRuleGroupBuilderFactory(); | ||
|
||
const background = euiThemeVars.euiColorLightestShade; | ||
const methodTextColor = '#DD0A73'; | ||
const urlTextColor = '#00A69B'; | ||
const stringTextColor = '#009926'; | ||
const commentTextColor = '#4C886B'; | ||
const variableTextColor = '#0079A5'; | ||
const booleanTextColor = '#585CF6'; | ||
const numericTextColor = variableTextColor; | ||
export const buildConsoleTheme = (): monaco.editor.IStandaloneThemeData => { | ||
return { | ||
base: darkMode ? 'vs-dark' : 'vs', | ||
inherit: true, | ||
rules: [ | ||
...buildRuleGroup(['method'], makeHighContrastColor(methodTextColor)(background)), | ||
...buildRuleGroup(['url'], makeHighContrastColor(urlTextColor)(background)), | ||
...buildRuleGroup( | ||
['string', 'string-literal', 'multi-string', 'punctuation.end-triple-quote'], | ||
makeHighContrastColor(stringTextColor)(background) | ||
), | ||
...buildRuleGroup(['comment'], makeHighContrastColor(commentTextColor)(background)), | ||
...buildRuleGroup(['variable'], makeHighContrastColor(variableTextColor)(background)), | ||
...buildRuleGroup( | ||
['constant.language.boolean'], | ||
makeHighContrastColor(booleanTextColor)(background) | ||
), | ||
...buildRuleGroup(['constant.numeric'], makeHighContrastColor(numericTextColor)(background)), | ||
], | ||
colors: { | ||
'editor.background': background, | ||
// color of the line numbers | ||
'editorLineNumber.foreground': euiThemeVars.euiColorDarkShade, | ||
// color of the active line number | ||
'editorLineNumber.activeForeground': euiThemeVars.euiColorDarkShade, | ||
// background of the line numbers side panel | ||
'editorGutter.background': euiThemeVars.euiColorEmptyShade, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.