Skip to content

[ES|QL] Computed suggestions for expression#246421

Merged
bartoval merged 6 commits intoelastic:mainfrom
bartoval:computed_suggestion_for_expression
Dec 17, 2025
Merged

[ES|QL] Computed suggestions for expression#246421
bartoval merged 6 commits intoelastic:mainfrom
bartoval:computed_suggestion_for_expression

Conversation

@bartoval
Copy link
Contributor

@bartoval bartoval commented Dec 15, 2025

Summary

#244952

moved a little bit of unnecessary logic out of the commands

also fixed a couple of bugs

  • All(*) not at top position
  • In Completion we suggest inside literals
@bartoval bartoval self-assigned this Dec 15, 2025
@bartoval bartoval requested a review from a team as a code owner December 15, 2025 16:53
@bartoval bartoval added release_note:enhancement backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// v9.3.0 labels Dec 15, 2025
@elasticmachine
Copy link
Contributor

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

});

it('suggests WITH after the user writes a param as prompt', async () => {
await completionExpectSuggestions(`FROM a | COMPLETION ? /`, ['WITH { $0 }']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just a test issue because the parser consider ?/ together

* Finds the rightmost non-variadic operator in an expression tree.
* Useful for locating the most specific node near the cursor.
*/
export function getRightmostNonVariadicOperator(root: ESQLSingleAstItem): ESQLSingleAstItem {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved here

@bartoval
Copy link
Contributor Author

house cleaning PR
Animazione di esempio

@bartoval bartoval force-pushed the computed_suggestion_for_expression branch from c486fa1 to 48fa409 Compare December 15, 2025 17:11
@bartoval bartoval force-pushed the computed_suggestion_for_expression branch from 48fa409 to 75921ed Compare December 15, 2025 17:12
if (targetField && !targetField.incomplete) {
return CompletionPosition.AFTER_TARGET_ID;
// (function, literal, or existing column) - handle as primaryExpression
if (isFunctionExpression(expressionRoot) || isLiteral(prompt) || isExistingColumn) {
Copy link
Contributor Author

@bartoval bartoval Dec 15, 2025

Choose a reason for hiding this comment

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

I've refactored Completion logic a bit more than the others . It's more similar to grammar logic and Rerank.

Mainly because I no longer wanted to use external checks like isExpressionComplete. That logic is already inside suggestForExpression, (calling it is not expensive for the cases that were previously handled by the functions we replaced)

@bartoval bartoval changed the title [ES|QL] Computed suggestion for expression Dec 15, 2025
@bartoval bartoval force-pushed the computed_suggestion_for_expression branch from 5941552 to ca460b5 Compare December 16, 2025 05:41
@stratoula
Copy link
Contributor

@bartoval sorry for this but do you mind merging after #246407? It will be easier to handle the conflicts in this PR 🙏

@bartoval
Copy link
Contributor Author

@bartoval sorry for this but do you mind merging after #246407? It will be easier to handle the conflicts in this PR 🙏

Yes I know. I've already done 4 rebase XD. I'm trained. When you've finished all the PR. I'll come back to this

@stratoula
Copy link
Contributor

Thanks Val and sorry for this. We will merge it immediately after!

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.

Nice refactor! commands looks more simpler now :), found a bug, but it's not being added by this PR.

}

/** Computes derived state from the expression context */
function computeDerivedState(ctx: ExpressionContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function computeDerivedState(ctx: ExpressionContext) {
function computeDerivedState(ctx: ExpressionContext): ExpressionComputedMetadata {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related with this PR, but found that rerank is not suggesting the inference_id's (problem is in main too).

  1. getCommandContext is not adding the inference endpoints for RERANK.
    Something like this would be needed:
    case 'rerank':
      return {
        inferenceEndpoints:
          (await callbacks?.getInferenceEndpoints?.('rerank'))?.inferenceEndpoints || [],
      };
  1. When the cursor is inside the empty quotes not suggestions are provided
    FROM ebt-kibana-browser | RERANK "Your search query" ON context.branch WITH { "inference_id": "^CURSOR" }
    This is because withinQuotes is generating an early return here.

Tell me if you want to take those in this PR, otherwise I can wait for this to be merged and create another PR if you want to avoid conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
Yes, I have to apply the same refactor that I did for Completion here to handle the case. I'll try to make changes here. It should be a mirrior of Completion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Here I would expect the WITH operator to be suggested

image

But this is happening in main so we can improve in a follow up. In general I am trying to not mix the PRs

@bartoval bartoval force-pushed the computed_suggestion_for_expression branch from 01db5e2 to d7afbae Compare December 16, 2025 11:00
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
unifiedSearch 556 555 -1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 4.3MB 4.3MB -727.0B

History

cc @bartoval

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Very nice cleanup! Let's merge when CI is green because I have a last step on the unification of the packages and it is better this to get merged first

Copy link
Contributor

Choose a reason for hiding this comment

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

Here I would expect the WITH operator to be suggested

image

But this is happening in main so we can improve in a follow up. In general I am trying to not mix the PRs

@bartoval bartoval merged commit e902181 into elastic:main Dec 17, 2025
19 checks passed
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 refactoring release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v9.3.0

4 participants