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

[ES|QL] Advanced validation and autocomplete #170071

Merged
merged 57 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e793907
[ES|QL] Use custom AST for suggestion, validation, etc... (#166185)
dej611 Oct 26, 2023
e43f1fb
Merge remote-tracking branch 'upstream/main' into feature/esql-valida…
dej611 Oct 26, 2023
0c7300d
Merge branch 'main' into feature/esql-validation
dej611 Oct 27, 2023
420e3b2
Merge branch 'main' into feature/esql-validation
dej611 Oct 31, 2023
b716982
Merge branch 'main' into feature/esql-validation
dej611 Oct 31, 2023
6c7ec66
Merge branch 'main' into feature/esql-validation
dej611 Nov 1, 2023
db639ea
[ES|QL] Add validation coverage for wildcards on commands (#170014)
dej611 Nov 1, 2023
84f5c31
:wrench: Fix conflicts with main
dej611 Nov 20, 2023
c57ba4c
Merge branch 'main' into feature/esql-validation
dej611 Nov 21, 2023
adff5bd
Merge branch 'main' into feature/esql-validation
dej611 Nov 22, 2023
8d3d583
Merge branch 'main' into feature/esql-validation
dej611 Nov 22, 2023
b9aa925
Merge branch 'main' into feature/esql-validation
dej611 Nov 23, 2023
893e702
Merge remote-tracking branch 'upstream/main' into feature/esql-valida…
dej611 Nov 24, 2023
bac92d3
[ESQL] New and improved autosuggestion (#171664)
dej611 Nov 24, 2023
d890b49
Merge branch 'main' into feature/esql-validation
dej611 Nov 27, 2023
0ceaeb6
[ES|QL] Fix bundle size (#171966)
dej611 Nov 27, 2023
82d66ed
[ESQL] Add caching for ESQL validation and autocomplete requests (#17…
dej611 Nov 27, 2023
d7a101e
[ES|QL] Show policy metadata on hover (#171940)
dej611 Nov 27, 2023
0716be8
[ES|QL] Disable warning highlights within editor + make syntax errors…
dej611 Nov 27, 2023
01bc182
Merge branch 'main' into feature/esql-validation
stratoula Nov 28, 2023
e63b63d
[ES|QL] Improve validation for remote and hidden indexes (#171996)
dej611 Nov 28, 2023
c9fe2b9
Apply suggestions from copy code review
dej611 Nov 28, 2023
b38e54e
Fix linting issue
dej611 Nov 28, 2023
69c3adb
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 28, 2023
5289d0a
Merge branch 'main' into feature/esql-validation
dej611 Nov 28, 2023
90699c8
[ES|QL] Fix autocomplete when cursor is not at the end of the stateme…
dej611 Nov 29, 2023
0e8f6cd
[ES|QL] fix query highlight when wrapped in multi-line (#172080)
dej611 Nov 29, 2023
434f95b
[ES|QL] Add support for * as valid function argument (#172054)
dej611 Nov 29, 2023
7e8bf8b
Merge branch 'main' into feature/esql-validation
dej611 Nov 29, 2023
1641f7a
[ES|QL] Fix functions highlight with ES grammar (#172287)
dej611 Nov 30, 2023
9e703df
:ok_hand: pipe before comma
dej611 Nov 30, 2023
d4cd2b3
Merge branch 'main' into feature/esql-validation
dej611 Dec 1, 2023
2e42d60
Merge remote-tracking branch 'upstream/feature/esql-validation' into …
dej611 Dec 1, 2023
f7f42ef
:sparkles: Show better messages for unhandled errors
dej611 Dec 1, 2023
bd1c634
:bug: Bette quote detection
dej611 Dec 1, 2023
422b569
:bug: fix the comma suggestion in where bug
dej611 Dec 1, 2023
9164e74
:sparkles: Add warning on using project command
dej611 Dec 1, 2023
b10bf77
:bug: Fix for quoted variable identifiers
dej611 Dec 1, 2023
b52219a
:bug: Fix for unhandled errors
dej611 Dec 1, 2023
e5dd07f
:bug: Fix brackets issues
dej611 Dec 1, 2023
2c9094e
:bug: fix autocomplete within statement
dej611 Dec 1, 2023
6e654be
:fire: remove unused function
dej611 Dec 1, 2023
d4c7220
:fire: remove unused import
dej611 Dec 1, 2023
0cb5a1a
Merge branch 'main' into feature/esql-validation
dej611 Dec 1, 2023
921ea85
:sparkles: Add new column suggested after comma
dej611 Dec 1, 2023
cc8c686
Merge branch 'feature/esql-validation' of https://github.com/elastic/…
dej611 Dec 1, 2023
c689c74
Merge remote-tracking branch 'upstream/main' into feature/esql-valida…
dej611 Dec 1, 2023
7852840
:sparkles: Add unsupported type warning
dej611 Dec 1, 2023
a3a8b2c
:bug: Fix where suggestions with and + or
dej611 Dec 1, 2023
07ed43c
Merge branch 'main' into feature/esql-validation
stratoula Dec 4, 2023
f86dc89
:bug: Fix suggestion on any char
dej611 Dec 4, 2023
3127c44
:bug: Fix empty warning on run press
dej611 Dec 4, 2023
d7a4c2b
Merge branch 'main' into feature/esql-validation
dej611 Dec 4, 2023
84ee8b8
Merge branch 'main' into feature/esql-validation
dej611 Dec 5, 2023
f8f95d6
Merge branch 'main' into feature/esql-validation
dej611 Dec 5, 2023
1e599c3
Merge branch 'main' into feature/esql-validation
dej611 Dec 5, 2023
ed32ef8
Merge branch 'main' into feature/esql-validation
dej611 Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-monaco/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { monaco } from './src/monaco_imports';
export { XJsonLang } from './src/xjson';
export { SQLLang } from './src/sql';
export { ESQL_LANG_ID, ESQL_THEME_ID, ESQLLang } from './src/esql';
export type { ESQLCustomAutocompleteCallbacks } from './src/esql';
export type { ESQLCallbacks } from './src/esql';

export * from './src/painless';
/* eslint-disable-next-line @kbn/eslint/module_migration */
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-monaco/src/common/error_listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ANTLREErrorListener implements ANTLRErrorListener<any> {
startColumn: column,
endColumn,
message,
severity: 8,
});
}

Expand Down
244 changes: 50 additions & 194 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

lexer grammar esql_lexer;
options { }

DISSECT : D I S S E C T -> pushMode(EXPRESSION);
GROK : G R O K -> pushMode(EXPRESSION);
DROP : D R O P -> pushMode(SOURCE_IDENTIFIERS);
ENRICH : E N R I C H -> pushMode(SOURCE_IDENTIFIERS);
EVAL : E V A L -> pushMode(EXPRESSION);
EXPLAIN : E X P L A I N -> pushMode(EXPLAIN_MODE);
FROM : F R O M -> pushMode(SOURCE_IDENTIFIERS);
GROK : G R O K -> pushMode(EXPRESSION);
KEEP : K E E P -> pushMode(SOURCE_IDENTIFIERS);
LIMIT : L I M I T -> pushMode(EXPRESSION);
MV_EXPAND : M V UNDERSCORE E X P A N D -> pushMode(SOURCE_IDENTIFIERS);
PROJECT : P R O J E C T -> pushMode(SOURCE_IDENTIFIERS);
RENAME : R E N A M E -> pushMode(SOURCE_IDENTIFIERS);
ROW : R O W -> pushMode(EXPRESSION);
SHOW : S H O W -> pushMode(EXPRESSION);
SORT : S O R T -> pushMode(EXPRESSION);
STATS : S T A T S -> pushMode(EXPRESSION);
WHERE : W H E R E -> pushMode(EXPRESSION);
SORT : S O R T -> pushMode(EXPRESSION);
MV_EXPAND : M V UNDERSCORE E X P A N D -> pushMode(EXPRESSION);
LIMIT : L I M I T -> pushMode(EXPRESSION);
PROJECT : P R O J E C T -> pushMode(EXPRESSION);
DROP : D R O P -> pushMode(EXPRESSION);
RENAME : R E N A M E -> pushMode(EXPRESSION);
SHOW : S H O W -> pushMode(EXPRESSION);
ENRICH : E N R I C H -> pushMode(ENRICH_IDENTIFIERS);
KEEP : K E E P -> pushMode(EXPRESSION);
UNKNOWN_CMD : ~[ \r\n\t[\]/]+ -> pushMode(EXPRESSION);

LINE_COMMENT
: '//' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
Expand All @@ -36,12 +37,7 @@ MULTILINE_COMMENT
WS
: [ \r\n\t]+ -> channel(HIDDEN)
;
mode EXPLAIN_MODE;
EXPLAIN_OPENING_BRACKET : '[' -> type(OPENING_BRACKET), pushMode(DEFAULT_MODE);
EXPLAIN_PIPE : '|' -> type(PIPE), popMode;
EXPLAIN_WS : WS -> channel(HIDDEN);
EXPLAIN_LINE_COMMENT : LINE_COMMENT -> channel(HIDDEN);
EXPLAIN_MULTILINE_COMMENT : MULTILINE_COMMENT -> channel(HIDDEN);

mode EXPRESSION;

PIPE : '|' -> popMode;
Expand Down Expand Up @@ -82,169 +78,60 @@ DECIMAL_LITERAL
| DOT DIGIT+ EXPONENT
;

BY : 'by';

DATE_LITERAL
: 'year'
| 'month'
| 'day'
| 'second'
| 'minute'
| 'hour'
| 'week'
| 'millisecond'
| 'years'
| 'months'
| 'days'
| 'seconds'
| 'minutes'
| 'hours'
| 'weeks'
| 'milliseconds'
;
BY : B Y;

AND : 'and';
AND : A N D;
ASC : A S C;
ASSIGN : '=';
COMMA : ',';
DESC : D E S C;
DOT : '.';
FALSE : F A L S E;
FIRST : F I R S T;
LAST : L A S T;
LP : '(';
OPENING_BRACKET : '[' -> pushMode(EXPRESSION), pushMode(EXPRESSION);
CLOSING_BRACKET : ']' -> popMode, popMode;
NOT : N O T;
LIKE: L I K E;
RLIKE: R L I K E;
IN: I N;
IS: I S;
AS: A S;
LIKE: L I K E;
NOT : N O T;
NULL : N U L L;
OR : 'or';
NULLS : N U L L S;
OR : O R;
PARAM: '?';
RLIKE: R L I K E;
RP : ')';
TRUE : T R U E;
INFO : I N F O;
FUNCTIONS : F U N C T I O N S;
UNDERSCORE: '_';
INFO : 'info';
FUNCTIONS : 'functions';

BOOLEAN_VALUE
: 'true'
| 'false'
;

COMPARISON_OPERATOR
: '=='
|'!='
| '<'
| '<='
| '>'
| '>='
;

EQ : '==';
NEQ : '!=';
LT : '<';
LTE : '<=';
GT : '>';
GTE : '>=';

PLUS : '+';
MINUS : '-';
ASTERISK : '*';
SLASH : '/';
PERCENT : '%';
TEN: '10';

ORDERING
: 'asc'
| 'desc'
;

NULLS_ORDERING: 'nulls';
NULLS_ORDERING_DIRECTION
: 'first'
| 'last'
;

MATH_FUNCTION
: R O U N D
| A B S
| P O W
| L O G TEN
| P I
| T A U
| E
| S U B S T R I N G
| T R I M
| C O N C A T
| C O A L E S C E
| G R E A T E S T
| L E F T
| N O W
| R I G H T
| S T A R T S UNDERSCORE W I T H
| D A T E UNDERSCORE F O R M A T
| D A T E UNDERSCORE T R U N C
| D A T E UNDERSCORE P A R S E
| A U T O UNDERSCORE B U C K E T
| D A T E UNDERSCORE E X T R A C T
| I S UNDERSCORE F I N I T E
| I S UNDERSCORE I N F I N I T E
| C A S E
| L E N G T H
| M V UNDERSCORE M A X
| M V UNDERSCORE M I N
| M V UNDERSCORE A V G
| M V UNDERSCORE S U M
| M V UNDERSCORE C O U N T
| M V UNDERSCORE C O N C A T
| M V UNDERSCORE J O I N
| M V UNDERSCORE M E D I A N
| M V UNDERSCORE D E D U P E
| M E T A D A T A
| S P L I T
| T O UNDERSCORE S T R I N G
| T O UNDERSCORE S T R
| T O UNDERSCORE B O O L
| T O UNDERSCORE B O O L E A N
| T O UNDERSCORE D A T E T I M E
| T O UNDERSCORE D T
| T O UNDERSCORE D B L
| T O UNDERSCORE D O U B L E
| T O UNDERSCORE D E G R E E S
| T O UNDERSCORE I N T
| T O UNDERSCORE I N T E G E R
| T O UNDERSCORE I P
| T O UNDERSCORE L O N G
| T O UNDERSCORE R A D I A N S
| T O UNDERSCORE V E R S I O N
| T O UNDERSCORE U N S I G N E D UNDERSCORE L O N G
;

UNARY_FUNCTION
: A V G
| M I N
| M A X
| S U M
| C O U N T
| C O U N T UNDERSCORE D I S T I N C T
| P E R C E N T I L E
| M E D I A N
| M E D I A N UNDERSCORE A B S O L U T E UNDERSCORE D E V I A T I O N
| A C O S
| A S I N
| A T A N
| A T A N '2'
| C E I L
| C O S
| C O S H
| F L O O R
| L T R I M
| S I N
| S I N H
| S Q R T
| T A N
| T A N H
;
// Brackets are funny. We can happen upon a CLOSING_BRACKET in two ways - one
// way is to start in an explain command which then shifts us to expression
// mode. Thus, the two popModes on CLOSING_BRACKET. The other way could as
// the start of a multivalued field constant. To line up with the double pop
// the explain mode needs, we double push when we see that.
OPENING_BRACKET : '[' -> pushMode(EXPRESSION), pushMode(EXPRESSION);
CLOSING_BRACKET : ']' -> popMode, popMode;

WHERE_FUNCTIONS
: C I D R UNDERSCORE M A T C H
;

UNQUOTED_IDENTIFIER
: LETTER (LETTER | DIGIT | '_' | ASTERISK)*
: LETTER (LETTER | DIGIT | '_')*
// only allow @ at beginning of identifier to keep the option to allow @ as infix operator in the future
// also, single `_` and `@` characters are not valid identifiers
| ('_' | '@') (LETTER | DIGIT | '_' | ASTERISK)+
| ('_' | '@') (LETTER | DIGIT | '_')+
;

QUOTED_IDENTIFIER
Expand All @@ -264,14 +151,18 @@ EXPR_WS
;



mode SOURCE_IDENTIFIERS;

SRC_PIPE : '|' -> type(PIPE), popMode;
SRC_OPENING_BRACKET : '[' -> type(OPENING_BRACKET), pushMode(SOURCE_IDENTIFIERS), pushMode(SOURCE_IDENTIFIERS);
SRC_CLOSING_BRACKET : ']' -> popMode, popMode, type(CLOSING_BRACKET);
SRC_COMMA : ',' -> type(COMMA);
SRC_ASSIGN : '=' -> type(ASSIGN);
AS : A S;
METADATA: M E T A D A T A;
ON : O N;
WITH : W I T H;

SRC_UNQUOTED_IDENTIFIER
: SRC_UNQUOTED_IDENTIFIER_PART+
Expand All @@ -298,41 +189,6 @@ SRC_WS
: WS -> channel(HIDDEN)
;

mode ENRICH_IDENTIFIERS;

ON : O N;
WITH : W I T H;

ENR_PIPE : '|' -> type(PIPE), popMode;
ENR_CLOSING_BRACKET : ']' -> popMode, popMode, type(CLOSING_BRACKET);
ENR_COMMA : ',' -> type(COMMA);
ENR_ASSIGN : '=' -> type(ASSIGN);

ENR_UNQUOTED_IDENTIFIER
: ENR_UNQUOTED_IDENTIFIER_PART+
;

fragment ENR_UNQUOTED_IDENTIFIER_PART
: ~[=`|,[\]/ \t\r\n]+
| '/' ~[*/] // allow single / but not followed by another / or * which would start a comment
;

ENR_QUOTED_IDENTIFIER
: QUOTED_IDENTIFIER
;

ENR_LINE_COMMENT
: LINE_COMMENT -> channel(HIDDEN)
;

ENR_MULTILINE_COMMENT
: MULTILINE_COMMENT -> channel(HIDDEN)
;

ENR_WS
: WS -> channel(HIDDEN)
;

fragment A : [aA]; // match either an 'a' or 'A'
fragment B : [bB];
fragment C : [cC];
Expand Down
Loading
Loading