Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
185b81c
add some smoother autocompletion
drewdaemon Jul 30, 2024
c874871
update test
drewdaemon Jul 31, 2024
a73faa3
from tests
drewdaemon Jul 31, 2024
4bce660
add more test cases
drewdaemon Jul 31, 2024
bc1e5e3
fill in support for LIMIT
drewdaemon Jul 31, 2024
898027c
SORT command support
drewdaemon Aug 1, 2024
a45fe37
fix comparison bug
drewdaemon Aug 1, 2024
a38b527
checkpoint
drewdaemon Aug 1, 2024
c531ec6
Fix date suggestions displaying in STATS
drewdaemon Aug 1, 2024
bd4ee2a
automatically advance for literal suggestions
drewdaemon Aug 1, 2024
81ae3ac
fix invoke trigger kind for subsequent function parameters
drewdaemon Aug 1, 2024
bf0229b
Refocus editor and advance cursor when date selected
drewdaemon Aug 2, 2024
883b7a9
Remove unused code
drewdaemon Aug 2, 2024
a4b7e5a
Support BY ...
drewdaemon Aug 5, 2024
0f8903e
Support WHERE <field>
drewdaemon Aug 5, 2024
5011ebc
update tests
drewdaemon Aug 5, 2024
a2e8fc3
update test
drewdaemon Aug 5, 2024
0690f20
Merge branch 'main' of github.com:elastic/kibana into faster-suggesti…
drewdaemon Aug 5, 2024
7a70676
Take into account literals when selecting signatures to suggest against
drewdaemon Aug 5, 2024
c003581
fix date trunc test
drewdaemon Aug 6, 2024
ad77eac
fix final tests
drewdaemon Aug 6, 2024
bdfbba8
restore time suggestions for operators
drewdaemon Aug 6, 2024
c7d6682
basic support for KEEP
drewdaemon Aug 6, 2024
bfabf94
handle KEEP @timestamp
drewdaemon Aug 6, 2024
fd68416
add more test cases
drewdaemon Aug 6, 2024
4474f2c
suggest the good stuff
drewdaemon Aug 8, 2024
996f0a7
unify logic
drewdaemon Aug 9, 2024
9749b2b
Merge branch 'main' of github.com:elastic/kibana into auto-open-sugge…
drewdaemon Aug 9, 2024
06dc3df
Merge branch 'unify-autocomplete-test-logic' into auto-open-suggestio…
drewdaemon Aug 9, 2024
5055471
remove duplicate test block
drewdaemon Aug 9, 2024
6af1a0d
update some tests
drewdaemon Aug 13, 2024
6027756
add some type guards
drewdaemon Aug 13, 2024
7ed0eb7
Allow defining a replacement range in completion items
drewdaemon Aug 13, 2024
bb7c0b9
Try out adding a range
drewdaemon Aug 13, 2024
e238e35
Merge branch 'main' of github.com:elastic/kibana into auto-open-sugge…
drewdaemon Aug 20, 2024
3816aca
temp
drewdaemon Aug 20, 2024
83a65c9
fix replacement ranges
drewdaemon Aug 21, 2024
afc687f
Restore open-command behavior for function parameters
drewdaemon Aug 21, 2024
4221cf1
Merge branch 'main' of github.com:elastic/kibana into auto-open-sugge…
drewdaemon Aug 21, 2024
8a6733c
fix some types
drewdaemon Aug 21, 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
2 changes: 1 addition & 1 deletion packages/kbn-esql-validation-autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export {
getCommandDefinition,
getAllCommands,
getCommandOption,
lookupColumn,
getColumnForASTNode as lookupColumn,
shouldBeQuotedText,
printFunctionSignature,
checkFunctionArgMatchesDefinition as isEqualType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
dataTypes,
fieldTypes,
isFieldType,
FunctionParameter,
} from '../src/definitions/types';
import { FUNCTION_DESCRIBE_BLOCK_NAME } from '../src/validation/function_describe_block_name';
import { getMaxMinNumberOfParams } from '../src/validation/helpers';
Expand Down Expand Up @@ -1155,7 +1156,7 @@ function generateIncorrectlyTypedParameters(
signatures: FunctionDefinition['signatures'],
currentParams: FunctionDefinition['signatures'][number]['params'],
availableFields: Array<{ name: string; type: SupportedDataType }>
) {
): { wrongFieldMapping: FunctionParameter[]; expectedErrors: string[] } {
const literalValues = {
string: `"a"`,
number: '5',
Expand Down Expand Up @@ -1260,7 +1261,7 @@ function generateIncorrectlyTypedParameters(
})
.filter(nonNullable);

return { wrongFieldMapping, expectedErrors };
return { wrongFieldMapping: wrongFieldMapping as FunctionParameter[], expectedErrors };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { camelCase, partition } from 'lodash';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import {
FunctionParameter,
FunctionReturnType,
isFieldType,
isReturnType,
isSupportedDataType,
SupportedDataType,
} from '../definitions/types';
Expand Down Expand Up @@ -753,7 +755,9 @@ describe('autocomplete', () => {
);

const getTypesFromParamDefs = (paramDefs: FunctionParameter[]): SupportedDataType[] =>
Array.from(new Set(paramDefs.map((p) => p.type))).filter(isSupportedDataType);
Array.from(new Set(paramDefs.map((p) => p.type))).filter(
isSupportedDataType
) as SupportedDataType[];

const suggestedConstants = param.literalSuggestions || param.literalOptions;

Expand All @@ -778,7 +782,9 @@ describe('autocomplete', () => {
),
...getFunctionSignaturesByReturnType(
'eval',
getTypesFromParamDefs(acceptsFieldParamDefs),
getTypesFromParamDefs(acceptsFieldParamDefs).filter(
isReturnType
) as FunctionReturnType[],
{ scalar: true },
undefined,
[fn.name]
Expand All @@ -802,7 +808,7 @@ describe('autocomplete', () => {
),
...getFunctionSignaturesByReturnType(
'eval',
getTypesFromParamDefs(acceptsFieldParamDefs),
getTypesFromParamDefs(acceptsFieldParamDefs) as FunctionReturnType[],
{ scalar: true },
undefined,
[fn.name]
Expand Down Expand Up @@ -851,13 +857,7 @@ describe('autocomplete', () => {
],
' '
);
testSuggestions('from a | eval a = 1 year /', [
',',
'| ',
...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
'time_interval',
]),
]);
testSuggestions('from a | eval a = 1 year /', [',', '| ', 'IS NOT NULL', 'IS NULL']);
testSuggestions('from a | eval a = 1 day + 2 /', [',', '| ']);
testSuggestions(
'from a | eval 1 day + 2 /',
Expand Down Expand Up @@ -1357,6 +1357,81 @@ describe('autocomplete', () => {
['keyword']
).map((s) => (s.text.toLowerCase().includes('null') ? s : attachTriggerCommand(s)))
);
describe('field lists', () => {
// KEEP field
testSuggestions('FROM a | KEEP /', getFieldNamesByType('any').map(attachTriggerCommand));
testSuggestions(
'FROM a | KEEP d/',
getFieldNamesByType('any')
.map<PartialSuggestionWithText>((text) => ({
text,
rangeToReplace: { start: 15, end: 16 },
}))
.map(attachTriggerCommand)
);
testSuggestions(
'FROM a | KEEP doubleFiel/',
getFieldNamesByType('any').map(attachTriggerCommand)
);
testSuggestions(
'FROM a | KEEP doubleField/',
['doubleField, ', 'doubleField | ']
.map((text) => ({
text,
filterText: 'doubleField',
rangeToReplace: { start: 15, end: 26 },
}))
.map(attachTriggerCommand)
);
testSuggestions('FROM a | KEEP doubleField /', ['| ', ',']);

// Let's get funky with the field names
testSuggestions(
'FROM a | KEEP @timestamp/',
['@timestamp, ', '@timestamp | ']
.map((text) => ({
text,
filterText: '@timestamp',
rangeToReplace: { start: 15, end: 25 },
}))
.map(attachTriggerCommand),
undefined,
[[{ name: '@timestamp', type: 'date' }]]
);
testSuggestions(
'FROM a | KEEP foo.bar/',
['foo.bar, ', 'foo.bar | ']
.map((text) => ({
text,
filterText: 'foo.bar',
rangeToReplace: { start: 15, end: 22 },
}))
.map(attachTriggerCommand),
undefined,
[[{ name: 'foo.bar', type: 'double' }]]
);

// @todo re-enable these tests when we can use AST to support this case
testSuggestions.skip('FROM a | KEEP `foo.bar`/', ['foo.bar, ', 'foo.bar | '], undefined, [
[{ name: 'foo.bar', type: 'double' }],
]);
testSuggestions.skip('FROM a | KEEP `foo`.`bar`/', ['foo.bar, ', 'foo.bar | '], undefined, [
[{ name: 'foo.bar', type: 'double' }],
]);
testSuggestions.skip('FROM a | KEEP `any#Char$Field`/', [
'`any#Char$Field`, ',
'`any#Char$Field` | ',
]);

// Subsequent fields
testSuggestions(
'FROM a | KEEP doubleField, dateFiel/',
getFieldNamesByType('any')
.filter((s) => s !== 'doubleField')
.map(attachTriggerCommand)
);
testSuggestions('FROM a | KEEP doubleField, dateField/', ['dateField, ', 'dateField | ']);
});
});

describe('Replacement ranges are attached when needed', () => {
Expand Down Expand Up @@ -1417,21 +1492,21 @@ describe('autocomplete', () => {
describe('dot-separated field names', () => {
testSuggestions(
'FROM a | KEEP field.nam/',
[{ text: 'field.name', rangeToReplace: { start: 15, end: 23 } }],
[{ text: 'field.name', rangeToReplace: { start: 15, end: 24 } }],
undefined,
[[{ name: 'field.name', type: 'double' }]]
);
// multi-line
testSuggestions(
'FROM a\n| KEEP field.nam/',
[{ text: 'field.name', rangeToReplace: { start: 15, end: 23 } }],
[{ text: 'field.name', rangeToReplace: { start: 15, end: 24 } }],
undefined,
[[{ name: 'field.name', type: 'double' }]]
);
// triple separator
testSuggestions(
'FROM a\n| KEEP field.name.f/',
[{ text: 'field.name.foo', rangeToReplace: { start: 15, end: 26 } }],
[{ text: 'field.name.foo', rangeToReplace: { start: 15, end: 27 } }],
undefined,
[[{ name: 'field.name.foo', type: 'double' }]]
);
Expand Down
Loading