Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0e937a9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 6, 2025
7ffbf4c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 10, 2025
b426318
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 13, 2025
511ccaa
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 14, 2025
2d71300
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 18, 2025
0076de9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 21, 2025
2898ce1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 24, 2025
ace0009
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 3, 2025
6cdd8c1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 4, 2025
98616e9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 6, 2025
64e40fd
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 7, 2025
1e3f8d1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 11, 2025
afd5630
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 13, 2025
31c6cb3
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
08f4b1b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
0c11f55
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 20, 2025
de2bc7a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 21, 2025
828d142
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 25, 2025
34bd1ef
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 1, 2025
f0070c6
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
16a27c7
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
cde697e
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 8, 2025
8b66178
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 10, 2025
0a4713e
Remove worker
drewdaemon Apr 11, 2025
70164d1
fix types issue
drewdaemon Apr 11, 2025
6ab76ee
fix types ONCE AND FOR ALL
drewdaemon Apr 11, 2025
86e4e63
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Apr 11, 2025
31cfeb9
fix again
drewdaemon Apr 11, 2025
005fbf5
Merge branch '217923/remove-worker' of github.com:drewdaemon/kibana i…
drewdaemon Apr 11, 2025
483c5f1
remove errant test
drewdaemon Apr 12, 2025
33fc6da
Merge branch 'main' into 217923/remove-worker
elasticmachine Apr 13, 2025
513788b
Merge branch 'main' into 217923/remove-worker
stratoula Apr 14, 2025
8e7c82e
Merge branch 'main' into 217923/remove-worker
stratoula Apr 15, 2025
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
20 changes: 8 additions & 12 deletions examples/esql_validation_example/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import type { CoreStart } from '@kbn/core/public';

import { ESQLCallbacks, ESQLRealField, validateQuery } from '@kbn/esql-validation-autocomplete';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import type { StartDependencies } from './plugin';
import { CodeSnippet } from './code_snippet';

Expand Down Expand Up @@ -77,16 +76,13 @@ export const App = (props: { core: CoreStart; plugins: StartDependencies }) => {
if (currentQuery === '') {
return;
}
validateQuery(
currentQuery,
getAstAndSyntaxErrors,
{ ignoreOnMissingCallbacks: ignoreErrors },
callbacks
).then(({ errors: validationErrors, warnings: validationWarnings }) => {
// syntax errors come with a slight different format than other validation errors
setErrors(validationErrors.map((e) => ('severity' in e ? e.message : e.text)));
setWarnings(validationWarnings.map((e) => e.text));
});
validateQuery(currentQuery, { ignoreOnMissingCallbacks: ignoreErrors }, callbacks).then(
({ errors: validationErrors, warnings: validationWarnings }) => {
// syntax errors come with a slight different format than other validation errors
setErrors(validationErrors.map((e) => ('severity' in e ? e.message : e.text)));
setWarnings(validationWarnings.map((e) => e.text));
}
);
}, [currentQuery, ignoreErrors, callbacks]);

const checkboxes = [
Expand All @@ -106,7 +102,7 @@ export const App = (props: { core: CoreStart; plugins: StartDependencies }) => {

return (
<EuiPage>
<EuiPageBody style={{ maxWidth: 800, margin: '0 auto' }}>
<EuiPageBody css={{ maxWidth: 800, margin: '0 auto' }}>
<EuiPageHeader paddingSize="s" bottomBorder={true} pageTitle="ES|QL validation example" />
<EuiPageSection paddingSize="s">
<p>This app shows how to use the ES|QL validation API with all its options</p>
Expand Down
3 changes: 1 addition & 2 deletions examples/esql_validation_example/public/code_snippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ export function CodeSnippet({ currentQuery, callbacks, ignoreErrors }: CodeSnipp
<EuiCodeBlock language="typescript" isCopyable>
{`
import { ESQLCallbacks, validateQuery } from '@kbn/esql-validation-autocomplete';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';

const currentQuery = "${currentQuery}";

const callbacks: ESQLCallbacks = () => ${getCallbacksCode(callbacks)};

const {errors, warnings} = validateQuery(
currentQuery,
getAstAndSyntaxErrors,
{ ignoreOnMissingCallbacks: ${Boolean(ignoreErrors)} },
callbacks
);
Expand Down
1 change: 0 additions & 1 deletion examples/esql_validation_example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@kbn/data-plugin",
"@kbn/data-views-plugin",
"@kbn/developer-examples-plugin",
"@kbn/esql-ast",
"@kbn/esql-validation-autocomplete",
]
}
2 changes: 0 additions & 2 deletions src/platform/packages/shared/kbn-esql-ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type {
ESQLColumn,
ESQLLiteral,
ESQLParamLiteral,
AstProviderFn,
EditorError,
ESQLAstNode,
ESQLInlineCast,
Expand Down Expand Up @@ -57,7 +56,6 @@ export {
parseErrors,
type ParseOptions,
type ParseResult,
getAstAndSyntaxErrors,
ESQLErrorListener,
} from './src/parser';

Expand Down
3 changes: 0 additions & 3 deletions src/platform/packages/shared/kbn-esql-ast/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export {
parseErrors,
type ParseOptions,
type ParseResult,

/** @deprecated Use `parse` instead. */
parse as getAstAndSyntaxErrors,
} from './parser';

export { ESQLErrorListener } from './esql_error_listener';
7 changes: 0 additions & 7 deletions src/platform/packages/shared/kbn-esql-ast/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,6 @@ export interface ESQLMessage {
code: string;
}

export type AstProviderFn = (text: string | undefined) =>
| Promise<{
ast: ESQLAst;
errors: EditorError[];
}>
| { ast: ESQLAst; errors: EditorError[] };

export interface EditorError {
startLineNumber: number;
endLineNumber: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse, mutate, BasicPrettyPrinter } from '@kbn/esql-ast';
import { sanitazeESQLInput } from './sanitaze_input';

Expand Down Expand Up @@ -61,7 +60,7 @@ export function appendWhereClauseToESQLQuery(
filterValue = '';
}

const { ast } = getAstAndSyntaxErrors(baseESQLQuery);
const { ast } = parse(baseESQLQuery);

const lastCommandIsWhere = ast[ast.length - 1].name === 'where';
// if where command already exists in the end of the query:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';

export function getESQLWithSafeLimit(esql: string, limit: number): string {
const { ast } = getAstAndSyntaxErrors(esql);
const { ast } = parse(esql);
const sourceCommand = ast.find(({ name }) => ['from', 'metrics'].includes(name));
if (!sourceCommand) {
return esql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For instance, not passing the `getSources` callback will report all index mentio
##### Usage

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { validateQuery } from '@kbn/esql-validation-autocomplete';

// define all callbacks
Expand All @@ -35,13 +35,13 @@ const myCallbacks = {
};

// Full validation performed
const { errors, warnings } = await validateQuery("from index | stats 1 + avg(myColumn)", getAstAndSyntaxErrors, undefined, myCallbacks);
const { errors, warnings } = await validateQuery("from index | stats 1 + avg(myColumn)", parse, undefined, myCallbacks);
```

If not all callbacks are available it is possible to gracefully degrade the validation experience with the `ignoreOnMissingCallbacks` option:

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { validateQuery } from '@kbn/esql-validation-autocomplete';

// define only the getSources callback
Expand All @@ -52,7 +52,7 @@ const myCallbacks = {
// ignore errors that might be triggered by the lack of some callbacks (i.e. "Unknown columns", etc...)
const { errors, warnings } = await validateQuery(
'from index | stats 1 + avg(myColumn)',
getAstAndSyntaxErrors,
parse,
{ ignoreOnMissingCallbacks: true },
myCallbacks
);
Expand All @@ -63,7 +63,7 @@ const { errors, warnings } = await validateQuery(
This is the complete logic for the ES|QL autocomplete language, it is completely independent from the actual editor (i.e. Monaco) and the suggestions reported need to be wrapped against the specific editor shape.

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { suggest } from '@kbn/esql-validation-autocomplete';

const queryString = "from index | stats 1 + avg(myColumn) ";
Expand All @@ -76,7 +76,7 @@ const suggestions = await suggest(
queryString,
queryString.length - 1, // the cursor position in a single line context
{ triggerCharacter: " "; triggerKind: 1 }, // kind = 0 is a programmatic trigger, while other values are ignored
getAstAndSyntaxErrors,
parse,
myCallbacks
);

Expand All @@ -102,7 +102,7 @@ This feature provides a list of suggestions to propose as fixes for a subset of
The feature works in combination with the validation service.

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { validateQuery, getActions } from '@kbn/esql-validation-autocomplete';

const queryString = "from index2 | stats 1 + avg(myColumn)"
Expand All @@ -111,12 +111,12 @@ const myCallbacks = {
getSources: async () => [{name: 'index', hidden: false}],
...
};
const { errors, warnings } = await validateQuery(queryString, getAstAndSyntaxErrors, undefined, myCallbacks);
const { errors, warnings } = await validateQuery(queryString, parse, undefined, myCallbacks);

const {title, edits} = await getActions(
queryString,
errors,
getAstAndSyntaxErrors,
parse,
undefined,
myCallbacks
);
Expand All @@ -129,7 +129,7 @@ console.log({ title, edits });
Like with validation also `getActions` can 'relax' its internal checks when no callbacks, either all or specific ones, are passed.

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { validateQuery, getActions } from '@kbn/esql-validation-autocomplete';

const queryString = "from index2 | keep unquoted-field"
Expand All @@ -138,12 +138,12 @@ const myCallbacks = {
getSources: async () => [{name: 'index', hidden: false}],
...
};
const { errors, warnings } = await validateQuery(queryString, getAstAndSyntaxErrors, undefined, myCallbacks);
const { errors, warnings } = await validateQuery(queryString, parse, undefined, myCallbacks);

const {title, edits} = await getActions(
queryString,
errors,
getAstAndSyntaxErrors,
parse,
{ relaxOnMissingCallbacks: true },
myCallbacks
);
Expand All @@ -159,13 +159,13 @@ This is an important function in order to build more features on top of the exis
For instance to show contextual information on Hover the `getAstContext` function can be leveraged to get the correct context for the cursor position:

```js
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { parse } from '@kbn/esql-ast';
import { getAstContext } from '@kbn/esql-validation-autocomplete';

const queryString = 'from index2 | stats 1 + avg(myColumn)';
const offset = queryString.indexOf('avg');

const astContext = getAstContext(queryString, getAstAndSyntaxErrors(queryString), offset);
const astContext = getAstContext(queryString, parse(queryString), offset);

if (astContext.type === 'function') {
const fnNode = astContext.node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { ESQLCallbacks } from '../../shared/types';
import * as autocomplete from '../autocomplete';
import { getCallbackMocks } from '../../__tests__/helpers';
Expand All @@ -26,7 +25,7 @@ const setup = async (caret = '?') => {
const pos = query.indexOf(caret);
if (pos < 0) throw new Error(`User cursor/caret "${caret}" not found in query: ${query}`);
const querySansCaret = query.slice(0, pos) + query.slice(pos + 1);
return await autocomplete.suggest(querySansCaret, pos, ctx, getAstAndSyntaxErrors, cb);
return await autocomplete.suggest(querySansCaret, pos, ctx, cb);
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { camelCase } from 'lodash';
import { parse } from '@kbn/esql-ast';
import { scalarFunctionDefinitions } from '../../definitions/generated/scalar_functions';
import { operatorsDefinitions } from '../../definitions/all_operators';
import { NOT_SUGGESTED_TYPES } from '../../shared/resources_helpers';
Expand Down Expand Up @@ -353,13 +352,7 @@ export const setup = async (caret = '/') => {
? { triggerKind: 1, triggerCharacter: opts.triggerCharacter }
: { triggerKind: 0 };

return await autocomplete.suggest(
querySansCaret,
pos,
ctx,
(_query: string | undefined) => parse(_query, { withFormatting: true }),
opts.callbacks ?? callbacks
);
return await autocomplete.suggest(querySansCaret, pos, ctx, opts.callbacks ?? callbacks);
};

const assertSuggestions: AssertSuggestionsFn = async (query, expected, opts) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { suggest } from './autocomplete';
import { commandDefinitions as unmodifiedCommandDefinitions } from '../definitions/commands';
import { scalarFunctionDefinitions } from '../definitions/generated/scalar_functions';
import { timeUnitsToSuggest } from '../definitions/literals';
import { commandDefinitions as unmodifiedCommandDefinitions } from '../definitions/commands';
import { getSafeInsertText, TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND } from './factories';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { Location } from '../definitions/types';
import { METADATA_FIELDS } from '../shared/constants';
import { ESQL_STRING_TYPES } from '../shared/esql_types';
import {
policies,
getFunctionSignaturesByReturnType,
getFieldNamesByType,
createCustomCallbackMocks,
attachTriggerCommand,
createCompletionContext,
createCustomCallbackMocks,
fields,
getFieldNamesByType,
getFunctionSignaturesByReturnType,
getPolicyFields,
PartialSuggestionWithText,
TIME_PICKER_SUGGESTION,
policies,
setup,
attachTriggerCommand,
SuggestOptions,
fields,
TIME_PICKER_SUGGESTION,
} from './__tests__/helpers';
import { METADATA_FIELDS } from '../shared/constants';
import { ESQL_STRING_TYPES } from '../shared/esql_types';
import { getRecommendedQueries } from './recommended_queries/templates';
import { suggest } from './autocomplete';
import { getDateHistogramCompletionItem } from './commands/stats/util';
import { Location } from '../definitions/types';
import { getSafeInsertText, TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND } from './factories';
import { getRecommendedQueries } from './recommended_queries/templates';

const commandDefinitions = unmodifiedCommandDefinitions.filter(({ hidden }) => !hidden);

Expand Down Expand Up @@ -213,13 +212,7 @@ describe('autocomplete', () => {
const statement = 'from a | drop keywordField | eval var0 = abs(doubleField) ';
const triggerOffset = statement.lastIndexOf(' ');
const context = createCompletionContext(statement[triggerOffset]);
await suggest(
statement,
triggerOffset + 1,
context,
async (text) => (text ? getAstAndSyntaxErrors(text) : { ast: [], errors: [] }),
callbackMocks
);
await suggest(statement, triggerOffset + 1, context, callbackMocks);
expect(callbackMocks.getColumnsFor).toHaveBeenCalledWith({
query: 'from a | drop keywordField',
});
Expand All @@ -229,13 +222,7 @@ describe('autocomplete', () => {
const statement = 'from a | drop | eval var0 = abs(doubleField) ';
const triggerOffset = statement.lastIndexOf('p') + 1; // drop <here>
const context = createCompletionContext(statement[triggerOffset]);
await suggest(
statement,
triggerOffset + 1,
context,
async (text) => (text ? getAstAndSyntaxErrors(text) : { ast: [], errors: [] }),
callbackMocks
);
await suggest(statement, triggerOffset + 1, context, callbackMocks);
expect(callbackMocks.getColumnsFor).toHaveBeenCalledWith({ query: 'from a' });
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { uniq } from 'lodash';
import {
type AstProviderFn,
parse,
type ESQLAstItem,
type ESQLCommand,
type ESQLCommandOption,
Expand Down Expand Up @@ -87,13 +87,12 @@ export async function suggest(
fullText: string,
offset: number,
context: EditorContext,
astProvider: AstProviderFn,
resourceRetriever?: ESQLCallbacks
): Promise<SuggestionRawDefinition[]> {
// Partition out to inner ast / ast context for the latest command
const innerText = fullText.substring(0, offset);
const correctedQuery = correctQuerySyntax(innerText, context);
const { ast } = await astProvider(correctedQuery);
const { ast } = parse(correctedQuery, { withFormatting: true });
const astContext = getAstContext(innerText, ast, offset);

if (astContext.type === 'comment') {
Expand Down
Loading