[ES|QL] Displays inline suggestions#235162
Conversation
| return { cache: fn.cache, memoizedSources: fn }; | ||
| }, []); | ||
|
|
||
| const { cache: historyStarredItemsCache, memoizedHistoryStarredItems } = useMemo(() => { |
There was a problem hiding this comment.
By caching the history it means that recent history items will be suggested with latency (10minutes). It is imho a goos compromise as requesting data from localStorage so often can be expensive.
| }), | ||
| queryString: `${fromCommand} | STATS count = COUNT(*) /* you can group by a field using the BY operator */`, | ||
| }, | ||
| { |
There was a problem hiding this comment.
Moving the search one first as we want to add priority in searching. Also changed the QSTR to KQL as we want to promote KQL instead
| range: InlineSuggestionItem['range'], | ||
| callbacks?: ESQLCallbacks | ||
| ): Promise<InlineSuggestionItem[]> { | ||
| const editorExtensions = await callbacks |
There was a problem hiding this comment.
Already cached endpoint
|
Pinging @elastic/kibana-esql (Team:ESQL) |
sddonne
left a comment
There was a problem hiding this comment.
Looks amazing! Approving as none of the comments is a blocker
| const historyItems = getHistoryItemsFn('desc'); | ||
| // exclude error queries from history items as | ||
| // we don't want to suggest them | ||
| const historyStarredItems = historyItems |
There was a problem hiding this comment.
Is this naming ok?
I see it holds the "regular" history querys besides the starred ones
There was a problem hiding this comment.
yes so it starts with adding the history items and later if you see it adds the starred, so its purpose is to have both
if (favoriteMetadata) {
Object.keys(favoriteMetadata).forEach((id) => {
const item = favoriteMetadata[id];
const { queryString } = item;
historyStarredItems.push(queryString);
});
}
return historyStarredItems;
| monaco.editor.addKeybindingRule({ | ||
| keybinding: monaco.KeyCode.Tab, | ||
| command: '-acceptSelectedSuggestion', | ||
| when: 'suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus && inlineSuggestionVisible', |
There was a problem hiding this comment.
wow! this is an interesting api.
There was a problem hiding this comment.
Kinda hidden in the monaco docs but it is very good to know yes 😄
|
|
||
| const FALLBACK_FROM_COMMAND = 'FROM *'; | ||
|
|
||
| export function getSourceFromQuery(esql?: string) { |
There was a problem hiding this comment.
Does this function need to be exported? it's used only here for now.
|
|
||
| export function getSourceFromQuery(esql?: string) { | ||
| const queryExpression = EsqlQuery.fromSrc(esql || '').ast; | ||
| const sourceCommand = queryExpression.commands.find(({ name }) => ['from', 'ts'].includes(name)); |
There was a problem hiding this comment.
Shall it also look for indexes in subquerys and lookup joins or are not relevant for the suggestions?
There was a problem hiding this comment.
No I am trying to start minimal, only for FROM and only at the end of the query. We can add more functionality depending on the user's feedback
| export async function inlineSuggest( | ||
| fullText: string, | ||
| textBeforeCursor: string, | ||
| range: InlineSuggestionItem['range'], |
There was a problem hiding this comment.
Why do we use the Monaco range, instead of the offset as in autocomplete and hover?
There was a problem hiding this comment.
We just send the range in the suggestions here, we don't really use it. So there is no point to use the offset here as we wont use it. The reason is that we dont suggest inline suggestions when the user types at the middle of the query, only at the end.
⏳ Build in-progress, with failures
Failed CI StepsTest Failures
History
|
paulinashakirova
left a comment
There was a problem hiding this comment.
SharedUX code review only, lgtm
Thank you
## Summary Closes elastic#199599 Enables inline suggestions to the editor. To accomplish that I had also to add the imports for the monaco plugin. The suggestions are being suggested only when the cursor is at the end of the query (inside the query was tricky, had a problematic behavior and it was kinda annoying) The pool of queries is from: - history - recommended queries - starred queries <img width="512" height="218" alt="image" src="https://github.com/user-attachments/assets/5d720909-4267-4d8d-bc85-70c913d26e3d" /> <img width="789" height="107" alt="image" src="https://github.com/user-attachments/assets/0dc23f19-c941-4630-9ad1-a556a8b3d41a" /> ### Checklist - [ ] [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: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Summary
Closes #199599
Enables inline suggestions to the editor. To accomplish that I had also to add the imports for the monaco plugin.
The suggestions are being suggested only when the cursor is at the end of the query (inside the query was tricky, had a problematic behavior and it was kinda annoying)
The pool of queries is from:
Checklist