Skip to content

Commit 2759665

Browse files
committed
enable subqueries by feature flag
1 parent a3a0e5a commit 2759665

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/platform/packages/shared/kbn-esql-ast/src/commands_registry/commands/from/autocomplete.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { ICommandCallbacks } from '../../types';
2121
import { type ISuggestionItem, type ICommandContext } from '../../types';
2222
import { getOverlapRange, isRestartingExpression } from '../../../definitions/utils/shared';
2323
import { isSubQuery, isSource } from '../../../ast/is';
24+
import { esqlCommandRegistry } from '../../../..';
2425

2526
const SOURCE_TYPE_INDEX = 'index';
2627
const METADATA_KEYWORD = 'METADATA';
@@ -110,8 +111,7 @@ function suggestInitialSources(
110111

111112
const suggestions = getSourceSuggestions(sources, [], innerText);
112113

113-
// Only suggest subqueries when not already inside a subquery
114-
if (!context?.isCursorInSubquery) {
114+
if (shouldSuggestSubquery(context)) {
115115
suggestions.push(subqueryCompleteItem);
116116
}
117117

@@ -174,10 +174,18 @@ async function suggestAdditionalSources(
174174
recommendedQueries
175175
);
176176

177-
// Add subquery suggestion when restarting after comma (only if not already in subquery)
178-
if (isRestartingExpression(innerText) && !context?.isCursorInSubquery) {
177+
if (isRestartingExpression(innerText) && shouldSuggestSubquery(context)) {
179178
suggestions.push(subqueryCompleteItem);
180179
}
181180

182181
return suggestions;
183182
}
183+
184+
function shouldSuggestSubquery(context: ICommandContext | undefined): boolean {
185+
if (context?.isCursorInSubquery) {
186+
return false;
187+
}
188+
189+
const fromCommand = esqlCommandRegistry.getCommandByName('from');
190+
return fromCommand?.metadata?.subquerySupport ?? true;
191+
}

src/platform/packages/shared/kbn-esql-ast/src/commands_registry/commands/from/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const fromCommand = {
2323
name: 'from',
2424
methods: fromCommandMethods,
2525
metadata: {
26+
subquerySupport: false,
2627
description: i18n.translate('kbn-esql-ast.esql.definitions.fromDoc', {
2728
defaultMessage:
2829
'Retrieves data from one or more data streams, indices, or aliases. In a query or subquery, you must use the from command first and it does not need a leading pipe. For example, to retrieve data from an index:',

src/platform/packages/shared/kbn-esql-ast/src/commands_registry/registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface ICommandMethods<TContext = any> {
7272

7373
export interface ICommandMetadata {
7474
preview?: boolean; // Optional property to indicate if the command is in preview mode
75+
subquerySupport?: boolean; // Optional property to indicate if the command supports subqueries (ONLY FROM)
7576
description: string; // Optional property for a brief description of the command
7677
declaration: string; // The pattern for declaring this command statement. Displayed in the autocomplete.
7778
examples: string[]; // A list of examples of how to use the command. Displayed in the autocomplete.

0 commit comments

Comments
 (0)