Skip to content
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

[Console] Add highlighting for painless language #202695

Merged

Conversation

ElenaStoeva
Copy link
Contributor

@ElenaStoeva ElenaStoeva commented Dec 3, 2024

Closes #201672

Summary

This PR adds existing painless rules to the console language so that the painless scripts are correctly highlighted. We are adding a painless starting rule that matches a string "*_script", "inline", or "source", followed by a triple quote, in order to prevent clashing with the existing rules for triple-quote strings.

Example request with a script:

POST _ingest/pipeline/_simulate
{
  "pipeline": { 
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
Screenshot 2024-12-03 at 12 02 52

@ElenaStoeva ElenaStoeva added Feature:Console Dev Tools Console Feature Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v9.0.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) v8.16.0 v8.17.0 labels Dec 3, 2024
@ElenaStoeva ElenaStoeva self-assigned this Dec 3, 2024
@ElenaStoeva ElenaStoeva requested a review from a team as a code owner December 3, 2024 12:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-management (Team:Kibana Management)

@ElenaStoeva ElenaStoeva requested a review from a team December 3, 2024 12:16
@SoniaSanzV SoniaSanzV self-requested a review December 3, 2024 13:13
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.5MB 3.5MB +671.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/monaco 4 5 +1

Total ESLint disabled count

id before after diff
@kbn/monaco 12 13 +1

cc @ElenaStoeva

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Code review only

@@ -100,17 +107,22 @@ xjsonRules.json_root = [
matchToken('variable.template', /("\${\w+}")/),
// @ts-expect-error include a rule to start sql highlighting
buildSqlStartRule(),
// @ts-expect-error include a rule to start sql highlighting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't this comment be to start painless highlighting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Fixed with 18a2f1f. Thanks for the review!

Copy link
Contributor

@SoniaSanzV SoniaSanzV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, lgtm!

@ElenaStoeva ElenaStoeva enabled auto-merge (squash) December 4, 2024 12:35
@ElenaStoeva ElenaStoeva merged commit 2fcd323 into elastic:main Dec 4, 2024
8 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12162195614

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">

(cherry picked from commit 2fcd323)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">

(cherry picked from commit 2fcd323)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">

(cherry picked from commit 2fcd323)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.16
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 4, 2024
…2953)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Console] Add highlighting for painless language
(#202695)](#202695)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T14:48:16Z","message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana
Management","release_note:skip","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"title":"[Console]
Add highlighting for painless
language","number":202695,"url":"https://github.com/elastic/kibana/pull/202695","mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202695","number":202695,"mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
kibanamachine added a commit that referenced this pull request Dec 4, 2024
…02951)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Console] Add highlighting for painless language
(#202695)](#202695)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T14:48:16Z","message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana
Management","release_note:skip","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"title":"[Console]
Add highlighting for painless
language","number":202695,"url":"https://github.com/elastic/kibana/pull/202695","mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202695","number":202695,"mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
kibanamachine added a commit that referenced this pull request Dec 4, 2024
…02952)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Console] Add highlighting for painless language
(#202695)](#202695)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T14:48:16Z","message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana
Management","release_note:skip","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"title":"[Console]
Add highlighting for painless
language","number":202695,"url":"https://github.com/elastic/kibana/pull/202695","mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202695","number":202695,"mergeCommit":{"message":"[Console]
Add highlighting for painless language (#202695)\n\nCloses
https://github.com/elastic/kibana/issues/201672?reload=1?reload=1\r\n\r\n##
Summary\r\n\r\nThis PR adds existing painless rules to the console
language so that the\r\npainless scripts are correctly highlighted. We
are adding a painless\r\nstarting rule that matches a string
`\"*_script\"`, `\"inline\"`, or\r\n`\"source\"`, followed by a triple
quote, in order to prevent clashing\r\nwith the existing rules for
triple-quote strings.\r\n\r\nExample request with a
script:\r\n\r\n```\r\nPOST _ingest/pipeline/_simulate\r\n{\r\n
\"pipeline\": { \r\n \"processors\": [\r\n {\r\n \"script\": {\r\n
\"description\": \"Extract 'tags' from 'env' field\",\r\n \"lang\":
\"painless\",\r\n \"source\": \"\"\"\r\n String[] envSplit =
ctx['env'].splitOnToken(params['delimiter']);\r\n ArrayList tags = new
ArrayList();\r\n tags.add(envSplit[params['position']].trim());\r\n
ctx['tags'] = tags;\r\n \"\"\",\r\n \"params\": {\r\n \"delimiter\":
\"-\",\r\n \"position\": 1\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"docs\":
[\r\n {\r\n \"_source\": {\r\n \"env\": \"es01-prod\"\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n<img width=\"1049\" alt=\"Screenshot 2024-12-03 at
12 02
52\"\r\nsrc=\"https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2\">","sha":"2fcd323927e42b4e7648f2aaa1a38dd3c7ea3900"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": { 
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": { 
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": { 
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Closes elastic#201672

## Summary

This PR adds existing painless rules to the console language so that the
painless scripts are correctly highlighted. We are adding a painless
starting rule that matches a string `"*_script"`, `"inline"`, or
`"source"`, followed by a triple quote, in order to prevent clashing
with the existing rules for triple-quote strings.

Example request with a script:

```
POST _ingest/pipeline/_simulate
{
  "pipeline": { 
    "processors": [
      {
        "script": {
          "description": "Extract 'tags' from 'env' field",
          "lang": "painless",
          "source": """
            String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
            ArrayList tags = new ArrayList();
            tags.add(envSplit[params['position']].trim());
            ctx['tags'] = tags;
          """,
          "params": {
            "delimiter": "-",
            "position": 1
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "env": "es01-prod"
      }
    }
  ]
}
```

<img width="1049" alt="Screenshot 2024-12-03 at 12 02 52"
src="https://github.com/user-attachments/assets/fb249953-a998-40c0-9775-3474e15b5de2">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Console Dev Tools Console Feature release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v8.16.0 v8.16.2 v8.17.0 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Console] No script highlighting
5 participants