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

[8.16] [ES|QL] Fix duplicate autocomplete suggestions for where clause, and suggestions with no space in between (#195771) #196716

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -1262,41 +1262,33 @@ describe('autocomplete', () => {
describe('Replacement ranges are attached when needed', () => {
testSuggestions('FROM a | WHERE doubleField IS NOT N/', [
{ text: 'IS NOT NULL', rangeToReplace: { start: 28, end: 35 } },
{ text: 'IS NULL', rangeToReplace: { start: 35, end: 35 } },
{ text: 'IS NULL', rangeToReplace: { start: 36, end: 36 } },
'!= $0',
'< $0',
'<= $0',
'== $0',
'> $0',
'>= $0',
'IN $0',
'AND $0',
'NOT',
'OR $0',
]);
testSuggestions('FROM a | WHERE doubleField IS N/', [
{ text: 'IS NOT NULL', rangeToReplace: { start: 28, end: 31 } },
{ text: 'IS NULL', rangeToReplace: { start: 28, end: 31 } },
{ text: '!= $0', rangeToReplace: { start: 31, end: 31 } },
'< $0',
'<= $0',
{ text: '!= $0', rangeToReplace: { start: 32, end: 32 } },
'== $0',
'> $0',
'>= $0',
'IN $0',
'AND $0',
'NOT',
'OR $0',
]);
testSuggestions('FROM a | EVAL doubleField IS NOT N/', [
{ text: 'IS NOT NULL', rangeToReplace: { start: 27, end: 34 } },
'IS NULL',
'% $0',
'* $0',
'+ $0',
'- $0',
'/ $0',
'!= $0',
'< $0',
'<= $0',
'== $0',
'> $0',
'>= $0',
'IN $0',
'AND $0',
'NOT',
'OR $0',
]);
describe('dot-separated field names', () => {
testSuggestions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,16 @@ function findNewVariable(variables: Map<string, ESQLVariable[]>) {
function workoutBuiltinOptions(
nodeArg: ESQLAstItem,
references: Pick<ReferenceMaps, 'fields' | 'variables'>
): { skipAssign: boolean } {
): { skipAssign: boolean; commandsToInclude?: string[] } {
const commandsToInclude =
(isSingleItem(nodeArg) && nodeArg.text?.toLowerCase().trim().endsWith('null')) ?? false
? ['and', 'or']
: undefined;

// skip assign operator if it's a function or an existing field to avoid promoting shadowing
return {
skipAssign: Boolean(!isColumnItem(nodeArg) || getColumnForASTNode(nodeArg, references)),
commandsToInclude,
};
}

Expand Down Expand Up @@ -447,7 +453,10 @@ function isFunctionArgComplete(
}
const hasCorrectTypes = fnDefinition.signatures.some((def) => {
return arg.args.every((a, index) => {
return def.params[index].type === extractTypeFromASTArg(a, references);
return (
(fnDefinition.name.endsWith('null') && def.params[index].type === 'any') ||
def.params[index].type === extractTypeFromASTArg(a, references)
);
});
});
if (!hasCorrectTypes) {
Expand Down Expand Up @@ -1140,11 +1149,12 @@ async function getBuiltinFunctionNextArgument(
}
return suggestions.map<SuggestionRawDefinition>((s) => {
const overlap = getOverlapRange(queryText, s.text);
const offset = overlap.start === overlap.end ? 1 : 0;
return {
...s,
rangeToReplace: {
start: overlap.start,
end: overlap.end,
start: overlap.start + offset,
end: overlap.end + offset,
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export const getBuiltinCompatibleFunctionDefinition = (
option: string | undefined,
argType: FunctionParameterType,
returnTypes?: FunctionReturnType[],
{ skipAssign }: { skipAssign?: boolean } = {}
{ skipAssign, commandsToInclude }: { skipAssign?: boolean; commandsToInclude?: string[] } = {}
): SuggestionRawDefinition[] => {
const compatibleFunctions = [...builtinFunctions, ...getTestFunctions()].filter(
({ name, supportedCommands, supportedOptions, signatures, ignoreAsSuggestion }) =>
(command === 'where' && commandsToInclude ? commandsToInclude.indexOf(name) > -1 : true) &&
!ignoreAsSuggestion &&
(!skipAssign || name !== '=') &&
(option ? supportedOptions?.includes(option) : supportedCommands.includes(command)) &&
Expand Down