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] Batch of fixes and new features for autocomplete and validation #175986

Merged
merged 37 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b90808c
:wrench: export utility fn
dej611 Jan 30, 2024
78c4ec3
:wrench: Change to non-array type
dej611 Jan 30, 2024
8665d2c
:fire: Remove unused fn
dej611 Jan 30, 2024
eb5697d
:fire: Remove unused branches and fns
dej611 Jan 30, 2024
1db565f
:label: Add types
dej611 Jan 30, 2024
bc1e204
:sparkles: Enable metafields
dej611 Jan 30, 2024
4fa664e
:bug: Fix issues with not and in oeprators
dej611 Jan 30, 2024
9838f47
:sparkles: Add metadata validation
dej611 Jan 30, 2024
1b8a3a0
:sparkles: Add metadata fields callback
dej611 Jan 30, 2024
3a1819c
:sparkles: Tons of fixes
dej611 Jan 30, 2024
0d920d4
:sparkles: Add autocomplete support/fixes
dej611 Jan 30, 2024
623caa9
:sparkles: Add validation support/fixes
dej611 Jan 30, 2024
8b50c59
Merge remote-tracking branch 'upstream/main' into fix/esql-various-fixes
dej611 Jan 30, 2024
98d89fb
:bug: Fix for not in expressions
dej611 Jan 31, 2024
2446122
:white_check_mark: Add tests for hover
dej611 Jan 31, 2024
abffd85
:truck: rename file
dej611 Jan 31, 2024
9b44170
:bug: better detect newExpression
dej611 Jan 31, 2024
fa9b683
:white_check_mark: Add more tests
dej611 Jan 31, 2024
68784b3
:bug: Suggest a better pattern
dej611 Jan 31, 2024
ccd0687
:sparkles: Use a better pattern for grok and dissect
dej611 Jan 31, 2024
62b3298
:bug: Fix missing column on grok/dissect match
dej611 Jan 31, 2024
33d2083
:bug: Avoid auto trigger on fields
dej611 Jan 31, 2024
6242474
:fire: Removed debug logging
dej611 Jan 31, 2024
aae41c7
Merge branch 'main' into fix/esql-various-fixes
dej611 Jan 31, 2024
8d1abc9
Merge branch 'main' into fix/esql-various-fixes
dej611 Jan 31, 2024
9331f1d
Merge remote-tracking branch 'upstream/main' into fix/esql-various-fixes
dej611 Feb 1, 2024
a1ea467
:recycle: Better auto trigger encapsulation
dej611 Feb 1, 2024
9a5d10d
Merge branch 'fix/esql-various-fixes' of https://github.com/dej611/ki…
dej611 Feb 1, 2024
8968b19
:label: fix type
dej611 Feb 1, 2024
f6bf44d
:recycle: Rename id
dej611 Feb 1, 2024
df467ed
:sparkles: Extends auto fixes to metadata fields
dej611 Feb 1, 2024
8af04fb
Merge branch 'main' into fix/esql-various-fixes
stratoula Feb 1, 2024
3e38d82
:bug: fix import
dej611 Feb 1, 2024
41ddfd6
Merge branch 'fix/esql-various-fixes' of https://github.com/dej611/ki…
dej611 Feb 1, 2024
6faf762
:recycle: Revisit the metadata fields
dej611 Feb 1, 2024
9a95bdf
Update packages/kbn-text-based-editor/src/text_based_languages_editor…
dej611 Feb 1, 2024
07d1c80
Merge branch 'main' into fix/esql-various-fixes
dej611 Feb 1, 2024
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
3 changes: 1 addition & 2 deletions packages/kbn-monaco/src/esql/lib/ast/ast_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ export class AstListener implements ESQLParserListener {
if (metadataContext) {
const option = createOption(metadataContext.METADATA().text.toLowerCase(), metadataContext);
commandAst.args.push(option);
// skip for the moment as there's no easy way to get meta fields right now
// option.args.push(...collectAllColumnIdentifiers(metadataContext));
option.args.push(...collectAllColumnIdentifiers(metadataContext));
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-monaco/src/esql/lib/ast/ast_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function createLiteralString(token: Token): ESQLLiteral {
};
}

function isMissingText(text: string) {
export function isMissingText(text: string) {
return /<missing /.test(text);
}

Expand Down Expand Up @@ -180,6 +180,13 @@ export function computeLocationExtends(fn: ESQLFunction) {
location.min = walkFunctionStructure(fn.args, location, 'min', () => 0);
// get max location navigating in depth keeping the right/last arg
location.max = walkFunctionStructure(fn.args, location, 'max', (args) => args.length - 1);
// in case of empty array as last arg, bump the max location by 3 chars (empty brackets)
if (
Array.isArray(fn.args[fn.args.length - 1]) &&
!(fn.args[fn.args.length - 1] as ESQLAstItem[]).length
) {
location.max += 3;
}
}
return location;
}
Expand Down
31 changes: 21 additions & 10 deletions packages/kbn-monaco/src/esql/lib/ast/ast_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
createPolicy,
createSettingTuple,
createLiteralString,
isMissingText,
} from './ast_helpers';
import { getPosition } from './ast_position_utils';
import type {
Expand Down Expand Up @@ -206,11 +207,16 @@ function visitLogicalAndsOrs(ctx: LogicalBinaryContext) {
function visitLogicalIns(ctx: LogicalInContext) {
const fn = createFunction(ctx.NOT() ? 'not_in' : 'in', ctx);
const [left, ...list] = ctx.valueExpression();
const values = [visitValueExpression(left), list.map((ve) => visitValueExpression(ve))];
for (const arg of values) {
if (arg) {
const filteredArgs = Array.isArray(arg) ? arg.filter(nonNullable) : [arg];
fn.args.push(filteredArgs);
const leftArg = visitValueExpression(left);
if (leftArg) {
fn.args.push(...(Array.isArray(leftArg) ? leftArg : [leftArg]));
const values = list.map((ve) => visitValueExpression(ve));
const listArgs = values
.filter(nonNullable)
.flatMap((arg) => (Array.isArray(arg) ? arg.filter(nonNullable) : arg));
// distinguish between missing brackets (missing text error) and an empty list
if (!isMissingText(ctx.text)) {
fn.args.push(listArgs);
}
}
// update the location of the assign based on arguments
Expand Down Expand Up @@ -244,6 +250,9 @@ function getComparisonName(ctx: ComparisonOperatorContext) {
}

function visitValueExpression(ctx: ValueExpressionContext) {
if (isMissingText(ctx.text)) {
return [];
}
if (ctx instanceof ValueExpressionDefaultContext) {
return visitOperatorExpression(ctx.operatorExpression());
}
Expand Down Expand Up @@ -538,16 +547,18 @@ export function visitDissect(ctx: DissectCommandContext) {
const pattern = ctx.string().tryGetToken(esql_parser.STRING, 0);
return [
visitPrimaryExpression(ctx.primaryExpression()),
createLiteral('string', pattern),
...visitDissectOptions(ctx.commandOptions()),
...(pattern && !isMissingText(pattern.text)
? [createLiteral('string', pattern), ...visitDissectOptions(ctx.commandOptions())]
: []),
].filter(nonNullable);
}

export function visitGrok(ctx: GrokCommandContext) {
const pattern = ctx.string().tryGetToken(esql_parser.STRING, 0);
return [visitPrimaryExpression(ctx.primaryExpression()), createLiteral('string', pattern)].filter(
nonNullable
);
return [
visitPrimaryExpression(ctx.primaryExpression()),
...(pattern && !isMissingText(pattern.text) ? [createLiteral('string', pattern)] : []),
].filter(nonNullable);
}

function visitDissectOptions(ctx: CommandOptionsContext | undefined) {
Expand Down
Loading