Skip to content

[ES|QL] Displays inline suggestions#235162

Merged
stratoula merged 40 commits intoelastic:mainfrom
stratoula:inline-suggestions-search-poc
Nov 13, 2025
Merged

[ES|QL] Displays inline suggestions#235162
stratoula merged 40 commits intoelastic:mainfrom
stratoula:inline-suggestions-search-poc

Conversation

@stratoula
Copy link
Contributor

@stratoula stratoula commented Sep 16, 2025

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:

  • history
  • recommended queries
  • starred queries
image image

Checklist

return { cache: fn.cache, memoizedSources: fn };
}, []);

const { cache: historyStarredItemsCache, memoizedHistoryStarredItems } = useMemo(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 */`,
},
{
Copy link
Contributor Author

@stratoula stratoula Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already cached endpoint

@stratoula stratoula changed the title Inline suggestions search poc Nov 3, 2025
@stratoula stratoula added v9.3.0 Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// release_note:enhancement backport:skip This PR does not require backporting labels Nov 4, 2025
@stratoula stratoula marked this pull request as ready for review November 10, 2025 11:39
@stratoula stratoula requested review from a team as code owners November 10, 2025 11:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Contributor

@sddonne sddonne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this naming ok?
I see it holds the "regular" history querys besides the starred ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow! this is an interesting api.

Copy link
Contributor Author

@stratoula stratoula Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda hidden in the monaco docs but it is very good to know yes 😄


const FALLBACK_FROM_COMMAND = 'FROM *';

export function getSourceFromQuery(esql?: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function need to be exported? it's used only here for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it doesnt! a6bc6c0


export function getSourceFromQuery(esql?: string) {
const queryExpression = EsqlQuery.fromSrc(esql || '').ast;
const sourceCommand = queryExpression.commands.find(({ name }) => ['from', 'ts'].includes(name));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall it also look for indexes in subquerys and lookup joins or are not relevant for the suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use the Monaco range, instead of the offset as in autocomplete and hover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #54 / integrations For each artifact list under management "after all" hook in "For each artifact list under management"
  • [job] [logs] FTR Configs #137 / X-Pack Accessibility Tests - Group 3 Kibana Tags Page Accessibility bulk actions panel meets a11y requirements
  • [job] [logs] FTR Configs #137 / X-Pack Accessibility Tests - Group 3 Kibana Tags Page Accessibility tag actions panel meets a11y requirements

History

Copy link
Contributor

@paulinashakirova paulinashakirova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedUX code review only, lgtm
Thank you

@stratoula stratoula enabled auto-merge (squash) November 13, 2025 09:47
@stratoula stratoula merged commit 1fbb5cd into elastic:main Nov 13, 2025
12 checks passed
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Dec 2, 2025
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana needs_docs release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v9.3.0

6 participants