Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
dba6c06
static declarations
drewdaemon Mar 20, 2025
7b0ea76
static metadata suggestion
drewdaemon Mar 20, 2025
f74fefc
move metadata field validation to command
drewdaemon Mar 20, 2025
67531f3
move append separator validation to command
drewdaemon Mar 20, 2025
fb83d67
remove some special cases in option validation
drewdaemon Mar 20, 2025
40ef759
goodbye option definitions
drewdaemon Mar 20, 2025
feecfd9
Update some autocomplete tests
drewdaemon Mar 20, 2025
ef1adac
remove old translations
drewdaemon Mar 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
*/

export type { SuggestionRawDefinition, ItemKind } from './src/autocomplete/types';
export type {
FunctionDefinition,
CommandDefinition,
CommandOptionsDefinition,
Literals,
} from './src/definitions/types';
export type { FunctionDefinition, CommandDefinition, Literals } from './src/definitions/types';
export type { ESQLCallbacks } from './src/shared/types';

/**
Expand Down Expand Up @@ -44,7 +39,6 @@ export {
getFunctionDefinition,
getCommandDefinition,
getAllCommands,
getCommandOption,
getColumnForASTNode as lookupColumn,
shouldBeQuotedText,
printFunctionSignature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('autocomplete.suggest', () => {
});
const { assertSuggestions } = await setup();
const expected = [
'METADATA $0',
'METADATA ',
',',
'| ',
...recommendedQueries.map((query) => query.queryString),
Expand All @@ -89,7 +89,7 @@ describe('autocomplete.suggest', () => {
test('partially-typed METADATA keyword', async () => {
const { assertSuggestions } = await setup();

assertSuggestions('FROM index1 MET/', ['METADATA $0']);
assertSuggestions('FROM index1 MET/', ['METADATA ']);
});

test('not before first index', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('autocomplete', () => {

// FROM source METADATA
recommendedQuerySuggestions = getRecommendedQueriesSuggestions('', 'dateField');
testSuggestions('FROM index1 M/', ['METADATA $0']);
testSuggestions('FROM index1 M/', ['METADATA ']);

// FROM source METADATA field
testSuggestions('FROM index1 METADATA _/', METADATA_FIELDS);
Expand Down Expand Up @@ -570,7 +570,7 @@ describe('autocomplete', () => {
testSuggestions('FROM a /', [
attachTriggerCommand('| '),
',',
attachAsSnippet(attachTriggerCommand('METADATA $0')),
attachTriggerCommand('METADATA '),
...recommendedQuerySuggestions.map((q) => q.queryString),
]);

Expand Down Expand Up @@ -675,7 +675,6 @@ describe('autocomplete', () => {
{
text: 'foo$bar METADATA ',
filterText: 'foo$bar',
asSnippet: false, // important because the text includes "$"
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace: { start: 6, end: 13 },
},
Expand Down Expand Up @@ -708,7 +707,7 @@ describe('autocomplete', () => {

recommendedQuerySuggestions = getRecommendedQueriesSuggestions('', 'dateField');
// FROM source METADATA
testSuggestions('FROM index1 M/', [attachAsSnippet(attachTriggerCommand('METADATA $0'))]);
testSuggestions('FROM index1 M/', [attachTriggerCommand('METADATA ')]);

describe('ENRICH', () => {
testSuggestions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { ESQLCommandOption } from '@kbn/esql-ast';
import { i18n } from '@kbn/i18n';
import { isMarkerNode } from '../../../shared/context';
import { metadataOption } from '../../../definitions/options';
import type { SuggestionRawDefinition } from '../../types';
import { getOverlapRange, handleFragment, removeQuoteForSuggestedSources } from '../../helper';
import { CommandSuggestParams } from '../../../definitions/types';
Expand All @@ -23,7 +23,6 @@ import {
import {
TRIGGER_SUGGESTION_COMMAND,
buildFieldsDefinitions,
buildOptionDefinition,
buildSourcesDefinitions,
} from '../../factories';
import { ESQLSourceResult } from '../../../shared/types';
Expand Down Expand Up @@ -70,7 +69,7 @@ export async function suggest({
}
// FROM something /
else if (indexes.length > 0 && /\s$/.test(innerText) && !isRestartingExpression(innerText)) {
suggestions.push(buildOptionDefinition(metadataOption));
suggestions.push(metadataSuggestion);
suggestions.push(commaCompleteItem);
suggestions.push(pipeCompleteItem);
suggestions.push(...(await getRecommendedQueriesSuggestions()));
Expand All @@ -81,7 +80,7 @@ export async function suggest({
/^FROM\s+\S+\s+/i.test(innerText) &&
metadataOverlap.start !== metadataOverlap.end
) {
suggestions.push(buildOptionDefinition(metadataOption));
suggestions.push(metadataSuggestion);
}
// FROM someth/
// FROM something/
Expand Down Expand Up @@ -127,10 +126,9 @@ export async function suggest({
rangeToReplace,
},
{
...buildOptionDefinition(metadataOption),
...metadataSuggestion,
filterText: fragment,
text: fragment + ' METADATA ',
asSnippet: false, // turn this off because $ could be contained within the source name
rangeToReplace,
},
...recommendedQuerySuggestions.map((suggestion) => ({
Expand Down Expand Up @@ -161,6 +159,17 @@ function getSourceSuggestions(sources: ESQLSourceResult[]) {
);
}

const metadataSuggestion: SuggestionRawDefinition = {
label: 'METADATA',
text: 'METADATA ',
kind: 'Reference',
detail: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.metadataDoc', {
defaultMessage: 'Metadata',
}),
sortText: '1',
command: TRIGGER_SUGGESTION_COMMAND,
};

async function suggestForMetadata(metadata: ESQLCommandOption, innerText: string) {
const existingFields = new Set(metadata.args.filter(isColumnItem).map(({ name }) => name));
const filteredMetaFields = METADATA_FIELDS.filter((name) => !existingFields.has(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { operatorsDefinitions } from '../definitions/all_operators';
import { getOperatorSuggestion, TRIGGER_SUGGESTION_COMMAND } from './factories';
import { CommandDefinition, CommandTypeDefinition } from '../definitions/types';
import { getCommandDefinition } from '../shared/helpers';
import { getCommandSignature } from '../definitions/helpers';
import { buildDocumentation } from './documentation_util';

const techPreviewLabel = i18n.translate(
Expand Down Expand Up @@ -55,15 +54,14 @@ export const getCommandAutocompleteDefinitions = (
if (commandDefinition.preview) {
detail = `[${techPreviewLabel}] ${detail}`;
}
const commandSignature = getCommandSignature(commandDefinition, type.name);
const suggestion: SuggestionRawDefinition = {
label: type.name ? `${type.name.toLocaleUpperCase()} ${label}` : label,
text: type.name ? `${type.name.toLocaleUpperCase()} ${text}` : text,
asSnippet: true,
kind: 'Method',
detail,
documentation: {
value: buildDocumentation(commandSignature.declaration, commandSignature.examples),
value: buildDocumentation(commandDefinition.declaration, commandDefinition.examples),
},
sortText: 'A-' + label + '-' + type.name,
command: TRIGGER_SUGGESTION_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { getFunctionSignatures } from '../definitions/helpers';
import { timeUnitsToSuggest } from '../definitions/literals';
import {
FunctionDefinition,
CommandOptionsDefinition,
FunctionParameterType,
FunctionDefinitionTypes,
} from '../definitions/types';
Expand Down Expand Up @@ -366,28 +365,6 @@ export const buildPoliciesDefinitions = (
command: TRIGGER_SUGGESTION_COMMAND,
}));

/** @deprecated — options will be removed */
export const buildOptionDefinition = (
option: CommandOptionsDefinition,
isAssignType: boolean = false
) => {
const completeItem: SuggestionRawDefinition = {
label: option.name.toUpperCase(),
text: option.name.toUpperCase(),
kind: 'Reference',
detail: option.description,
sortText: '1',
};
if (isAssignType || option.signature.params.length) {
completeItem.text = isAssignType
? `${option.name.toUpperCase()} = $0`
: `${option.name.toUpperCase()} $0`;
completeItem.asSnippet = true;
completeItem.command = TRIGGER_SUGGESTION_COMMAND;
}
return completeItem;
};

export function getUnitDuration(unit: number = 1) {
const filteredTimeLiteral = timeUnitsToSuggest.filter(({ name }) => {
const result = /s$/.test(name);
Expand Down
Loading