Skip to content

Commit

Permalink
[ES|QL] Make sure that the commands are not overwritten (#204711)
Browse files Browse the repository at this point in the history
(cherry picked from commit 76e22f7)
  • Loading branch information
stratoula committed Dec 19, 2024
1 parent 7dcfba5 commit 6d17e8d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,22 +612,30 @@ async function getExpressionSuggestionsByType(
(fragment) => Boolean(getColumnByName(fragment, references)),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// COMMAND fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// COMMAND field<suggest>
if (['grok', 'dissect'].includes(command.name)) {
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
}

const finalSuggestions = [{ ...pipeCompleteItem, text: ' | ' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ export async function suggest(
// SORT fie<suggest>
return [
...pushItUpInTheList(
fieldSuggestions.map((suggestion) => ({
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
})),
fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
}),
true
),
...functionSuggestions,
Expand Down

0 comments on commit 6d17e8d

Please sign in to comment.