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

[Expressions] Add support of comments #122457

Merged
merged 9 commits into from
Jan 20, 2022
Merged

Conversation

dokmic
Copy link
Contributor

@dokmic dokmic commented Jan 6, 2022

Summary

This PR resolves #42829, and namely adds the following:

  • support of inline comments (// something);
  • support of multiline comments (/* something */);
  • syntax highlighting in the code editor;
  • fixes canvas to preserve the original formatting of the expression.

The comments do not end up in the AST so that there are no changes in the interpreter.

Checklist

For maintainers

@dokmic dokmic force-pushed the feature/42829 branch 5 times, most recently from aa94013 to 2f14160 Compare January 10, 2022 11:50
@dokmic dokmic marked this pull request as ready for review January 10, 2022 13:29
@dokmic dokmic requested review from a team as code owners January 10, 2022 13:29
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServicesSv)

@dokmic dokmic requested a review from ppisljar January 10, 2022 13:29
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

VisEditors changes LGTM, code review only - simple type rename

@dokmic
Copy link
Contributor Author

dokmic commented Jan 12, 2022

@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

LGTM

};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type AstFunction = {
Copy link
Member

Choose a reason for hiding this comment

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

i think we should try to get rid of duplicate types for this (ones inside expressions plugin and ones inside kbn-interpreter package. If we add optional debug property on this one i think we can reuse this ones in expressions plugin. not necesarry part of this pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I tried already. I did that with type augmentation in the expression plugin as the cleanest solution, but that's causing so many type errors with the PersistableState generics as they require serializable objects. Fixing those errors caused many changes in other parts of the code using the expressions plugin.

I don't think it would be correct to declare the debug property in the interpreter package because it doesn't belong there. It's a custom logic built on top of the tree structure in the expressions plugin.

In the end, I refactored those types in the expressions plugin to extend the related ones from the interpreter. As a result, I removed all the duplicating typings and kept only the ones produced by the expressions plugin. This approach also keeps our public API unchanged.

@@ -36,7 +36,7 @@ const collectArgs = (args: ExpressionFunctionAST['arguments']) => {
);
};

export function adaptCanvasFilter(filter: ExpressionFunctionAST): Filter {
export function adaptCanvasFilter(filter: AstFunction): Filter {
Copy link
Member

Choose a reason for hiding this comment

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

nit: i preferred the old names ExpressionFunctionAST over just AstFunction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a few points to rename them.

  1. They were inconsistent Ast versusExpressionFunctionAST and ExpressionArgAST (Ast vs AST, and not ExpressionAST for some reason).
  2. ExpressionArgAST - shortcut in the name is not a good practice.
  3. The AST context was in the suffix, but it should be in the prefix.
  4. The AST was incorrectly camel-cased and should be Ast.
  5. It was confusing next to the expressions plugin's types (ExpressionFunctionAST & ExpressionAstFunction, ExpressionArgAST & ExpressionAstArgument).

I think they are named better know:

  • Clear Ast and ExpressionAst prefixes.
  • Consistent with each other and with the expressions plugin types.

WDYT?

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
canvas 1081 1088 +7
expressions 160 167 +7
lens 711 718 +7
presentationUtil 165 172 +7
total +28

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/interpreter 30 35 +5

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
@kbn/interpreter 1 3 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
canvas 1.0MB 1.0MB +4.3KB
expressions 44.1KB 44.1KB +11.0B
lens 1.0MB 1.0MB +4.2KB
presentationUtil 130.5KB 135.1KB +4.5KB
total +13.0KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
kibana 957 959 +2

Page load bundle

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

id before after diff
expressions 82.9KB 87.1KB +4.2KB
Unknown metric groups

API count

id before after diff
@kbn/interpreter 30 35 +5

ESLint disabled line counts

id before after diff
@kbn/interpreter 3 5 +2

Total ESLint disabled count

id before after diff
@kbn/interpreter 3 5 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@crob611 crob611 left a comment

Choose a reason for hiding this comment

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

Presentation Changes look good to me 👍

@dokmic dokmic merged commit 6ae6467 into elastic:main Jan 20, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 20, 2022
@dokmic dokmic deleted the feature/42829 branch January 20, 2022 19:46
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:enhancement review v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Expressions] Comments in Canvas expression editor
7 participants