Skip to content

Commit ecbb5d0

Browse files
committed
do complete suggestions
1 parent 786e1b7 commit ecbb5d0

2 files changed

Lines changed: 50 additions & 54 deletions

File tree

packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.sort.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ describe('autocomplete.suggest', () => {
3636
test('when user starts to type ASC modifier', async () => {
3737
const { assertSuggestions } = await setup();
3838

39-
await assertSuggestions('from a | sort stringField A/', ['SC']);
39+
await assertSuggestions('from a | sort stringField A/', ['ASC']);
4040
});
4141

4242
test('when user starts to type DESC modifier', async () => {
4343
const { assertSuggestions } = await setup();
4444

45-
await assertSuggestions('from a | sort stringField d/', ['ESC']);
46-
await assertSuggestions('from a | sort stringField des/', ['C']);
47-
await assertSuggestions('from a | sort stringField DES/', ['C']);
45+
await assertSuggestions('from a | sort stringField d/', ['DESC']);
46+
await assertSuggestions('from a | sort stringField des/', ['DESC']);
47+
await assertSuggestions('from a | sort stringField DES/', ['DESC']);
4848
});
4949
});
5050

@@ -63,24 +63,24 @@ describe('autocomplete.suggest', () => {
6363
test('when user starts to type NULLS modifiers', async () => {
6464
const { assertSuggestions } = await setup();
6565

66-
await assertSuggestions('from a | sort stringField N/', ['ULLS FIRST', 'ULLS LAST']);
67-
await assertSuggestions('from a | sort stringField null/', ['S FIRST', 'S LAST']);
68-
await assertSuggestions('from a | sort stringField nulls/', [' FIRST', ' LAST']);
69-
await assertSuggestions('from a | sort stringField nulls /', ['FIRST', 'LAST']);
66+
await assertSuggestions('from a | sort stringField N/', ['NULLS FIRST', 'NULLS LAST']);
67+
await assertSuggestions('from a | sort stringField null/', ['NULLS FIRST', 'NULLS LAST']);
68+
await assertSuggestions('from a | sort stringField nulls/', ['NULLS FIRST', 'NULLS LAST']);
69+
await assertSuggestions('from a | sort stringField nulls /', ['NULLS FIRST', 'NULLS LAST']);
7070
});
7171

7272
test('when user types NULLS FIRST', async () => {
7373
const { assertSuggestions } = await setup();
7474

75-
await assertSuggestions('from a | sort stringField NULLS F/', ['IRST']);
76-
await assertSuggestions('from a | sort stringField NULLS FI/', ['RST']);
75+
await assertSuggestions('from a | sort stringField NULLS F/', ['NULLS FIRST']);
76+
await assertSuggestions('from a | sort stringField NULLS FI/', ['NULLS FIRST']);
7777
});
7878

7979
test('when user types NULLS LAST', async () => {
8080
const { assertSuggestions } = await setup();
8181

82-
await assertSuggestions('from a | sort stringField NULLS L/', ['AST']);
83-
await assertSuggestions('from a | sort stringField NULLS LAS/', ['T']);
82+
await assertSuggestions('from a | sort stringField NULLS L/', ['NULLS LAST']);
83+
await assertSuggestions('from a | sort stringField NULLS LAS/', ['NULLS LAST']);
8484
});
8585
});
8686
});

packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.ts

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,38 +1836,34 @@ async function getOptionArgsSuggestions(
18361836
}
18371837

18381838
const sortModifierSuggestions = {
1839-
ASC: (entered: string = '') =>
1840-
({
1841-
label: 'ASC',
1842-
text: 'ASC'.slice(entered.length),
1843-
detail: '',
1844-
kind: 'Keyword',
1845-
sortText: '1-ASC',
1846-
} as SuggestionRawDefinition),
1847-
DESC: (entered: string = '') =>
1848-
({
1849-
label: 'DESC',
1850-
text: 'DESC'.slice(entered.length),
1851-
detail: '',
1852-
kind: 'Keyword',
1853-
sortText: '1-DESC',
1854-
} as SuggestionRawDefinition),
1855-
NULLS_FIRST: (entered: string = '') =>
1856-
({
1857-
label: 'NULLS FIRST',
1858-
text: 'NULLS FIRST'.slice(entered.length),
1859-
detail: '',
1860-
kind: 'Keyword',
1861-
sortText: '2-NULLS FIRST',
1862-
} as SuggestionRawDefinition),
1863-
NULLS_LAST: (entered: string = '') =>
1864-
({
1865-
label: 'NULLS LAST',
1866-
text: 'NULLS LAST'.slice(entered.length),
1867-
detail: '',
1868-
kind: 'Keyword',
1869-
sortText: '2-NULLS LAST',
1870-
} as SuggestionRawDefinition),
1839+
ASC: {
1840+
label: 'ASC',
1841+
text: 'ASC',
1842+
detail: '',
1843+
kind: 'Keyword',
1844+
sortText: '1-ASC',
1845+
} as SuggestionRawDefinition,
1846+
DESC: {
1847+
label: 'DESC',
1848+
text: 'DESC',
1849+
detail: '',
1850+
kind: 'Keyword',
1851+
sortText: '1-DESC',
1852+
} as SuggestionRawDefinition,
1853+
NULLS_FIRST: {
1854+
label: 'NULLS FIRST',
1855+
text: 'NULLS FIRST',
1856+
detail: '',
1857+
kind: 'Keyword',
1858+
sortText: '2-NULLS FIRST',
1859+
} as SuggestionRawDefinition,
1860+
NULLS_LAST: {
1861+
label: 'NULLS LAST',
1862+
text: 'NULLS LAST',
1863+
detail: '',
1864+
kind: 'Keyword',
1865+
sortText: '2-NULLS LAST',
1866+
} as SuggestionRawDefinition,
18711867
};
18721868

18731869
export const suggestForSortCmd = async (innerText: string, getFieldsByType: GetFieldsByTypeFn) => {
@@ -1876,10 +1872,10 @@ export const suggestForSortCmd = async (innerText: string, getFieldsByType: GetF
18761872
switch (pos) {
18771873
case 'space2': {
18781874
return [
1879-
sortModifierSuggestions.ASC(),
1880-
sortModifierSuggestions.DESC(),
1881-
sortModifierSuggestions.NULLS_FIRST(),
1882-
sortModifierSuggestions.NULLS_LAST(),
1875+
sortModifierSuggestions.ASC,
1876+
sortModifierSuggestions.DESC,
1877+
sortModifierSuggestions.NULLS_FIRST,
1878+
sortModifierSuggestions.NULLS_LAST,
18831879
...getFinalSuggestions({
18841880
comma: true,
18851881
}),
@@ -1888,16 +1884,16 @@ export const suggestForSortCmd = async (innerText: string, getFieldsByType: GetF
18881884
case 'order': {
18891885
const suggestions: SuggestionRawDefinition[] = [];
18901886
for (const modifier of Object.values(sortModifierSuggestions)) {
1891-
if (modifier().label.startsWith(order)) {
1892-
suggestions.push(modifier(order));
1887+
if (modifier.label.startsWith(order)) {
1888+
suggestions.push(modifier);
18931889
}
18941890
}
18951891
return suggestions;
18961892
}
18971893
case 'space3': {
18981894
return [
1899-
sortModifierSuggestions.NULLS_FIRST(),
1900-
sortModifierSuggestions.NULLS_LAST(),
1895+
sortModifierSuggestions.NULLS_FIRST,
1896+
sortModifierSuggestions.NULLS_LAST,
19011897
...getFinalSuggestions({
19021898
comma: true,
19031899
}),
@@ -1906,8 +1902,8 @@ export const suggestForSortCmd = async (innerText: string, getFieldsByType: GetF
19061902
case 'nulls': {
19071903
const suggestions: SuggestionRawDefinition[] = [];
19081904
for (const modifier of Object.values(sortModifierSuggestions)) {
1909-
if (modifier().label.startsWith(nulls)) {
1910-
suggestions.push(modifier(nulls));
1905+
if (modifier.label.startsWith(nulls)) {
1906+
suggestions.push(modifier);
19111907
}
19121908
}
19131909
return suggestions;

0 commit comments

Comments
 (0)