mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ES|QL] insert assignment suggestion as a snippet (#180203)
## Summary Fix https://github.com/elastic/kibana/issues/179978 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
65b5298a85
commit
f04153ba2c
2 changed files with 16 additions and 7 deletions
|
@ -15,6 +15,7 @@ import { commandDefinitions } from '../definitions/commands';
|
|||
import { TRIGGER_SUGGESTION_COMMAND } from './factories';
|
||||
import { camelCase } from 'lodash';
|
||||
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
|
||||
import { SuggestionRawDefinition } from './types';
|
||||
|
||||
const triggerCharacters = [',', '(', '=', ' '];
|
||||
|
||||
|
@ -200,14 +201,14 @@ function getPolicyFields(policyName: string) {
|
|||
describe('autocomplete', () => {
|
||||
type TestArgs = [
|
||||
string,
|
||||
string[],
|
||||
Array<string | Partial<SuggestionRawDefinition>>,
|
||||
(string | number)?,
|
||||
Parameters<typeof createCustomCallbackMocks>?
|
||||
];
|
||||
|
||||
const testSuggestionsFn = (
|
||||
statement: string,
|
||||
expected: string[],
|
||||
expected: Array<string | Partial<SuggestionRawDefinition>>,
|
||||
triggerCharacter: string | number = '',
|
||||
customCallbacksArgs: Parameters<typeof createCustomCallbackMocks> = [
|
||||
undefined,
|
||||
|
@ -242,10 +243,16 @@ describe('autocomplete', () => {
|
|||
);
|
||||
const suggestionInertTextSorted = suggestions
|
||||
// simulate the editor behaviour for sorting suggestions
|
||||
.sort((a, b) => (a.sortText || '').localeCompare(b.sortText || ''))
|
||||
.map((i) => i.text);
|
||||
.sort((a, b) => (a.sortText || '').localeCompare(b.sortText || ''));
|
||||
for (const [index, receivedSuggestion] of suggestionInertTextSorted.entries()) {
|
||||
expect(receivedSuggestion).toEqual(expected[index]);
|
||||
if (typeof expected[index] === 'string') {
|
||||
expect(receivedSuggestion.text).toEqual(expected[index]);
|
||||
} else {
|
||||
// check all properties that are defined in the expected suggestion
|
||||
for (const [key, value] of Object.entries(expected[index])) {
|
||||
expect(receivedSuggestion[key as keyof SuggestionRawDefinition]).toEqual(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -571,7 +578,9 @@ describe('autocomplete', () => {
|
|||
evalMath: true,
|
||||
});
|
||||
testSuggestions('from a | stats ', ['var0 =', ...allAggFunctions, ...allEvaFunctions]);
|
||||
testSuggestions('from a | stats a ', ['= $0']);
|
||||
testSuggestions('from a | stats a ', [
|
||||
{ text: '= $0', asSnippet: true, command: TRIGGER_SUGGESTION_COMMAND },
|
||||
]);
|
||||
testSuggestions('from a | stats a=', [...allAggFunctions, ...allEvaFunctions]);
|
||||
testSuggestions('from a | stats a=max(b) by ', [
|
||||
'var0 =',
|
||||
|
|
|
@ -58,7 +58,7 @@ export function getSuggestionBuiltinDefinition(fn: FunctionDefinition): Suggesti
|
|||
return {
|
||||
label: fn.name,
|
||||
text: hasArgs ? `${fn.name} $0` : fn.name,
|
||||
...(hasArgs ? { insertTextRules: 4 } : {}), // kbn-esql-validation-autocomplete.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
||||
asSnippet: hasArgs,
|
||||
kind: 'Operator',
|
||||
detail: fn.description,
|
||||
documentation: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue