diff --git a/src/autocomplete/autocomplete-types.ts b/src/autocomplete/autocomplete-types.ts index 3954edf9..ad940cb2 100644 --- a/src/autocomplete/autocomplete-types.ts +++ b/src/autocomplete/autocomplete-types.ts @@ -59,7 +59,8 @@ export type YQLEntity = | 'topic' | 'group' | 'user' - | 'tableIndex'; + | 'tableIndex' + | 'topicConsumer'; export interface YqlAutocompleteResult extends AutocompleteResultBase { suggestTableIndexes?: TableIndexSuggestion; @@ -70,7 +71,7 @@ export interface YqlAutocompleteResult extends AutocompleteResultBase { suggestTableFunctions?: boolean; suggestPragmas?: boolean; suggestTableHints?: string; - suggestTableSettings?: string; + suggestEntitySettings?: YQLEntity; } export interface ParserSyntaxError extends TokenPosition { diff --git a/src/autocomplete/databases/yql/helpers.ts b/src/autocomplete/databases/yql/helpers.ts index 1dfe5bdf..4d634fc9 100644 --- a/src/autocomplete/databases/yql/helpers.ts +++ b/src/autocomplete/databases/yql/helpers.ts @@ -357,14 +357,41 @@ function getTableHintsSuggestions({ return allRulesInList([YQLParser.RULE_an_id_hint, YQLParser.RULE_table_hint]); } -function getTableSettingsSuggestions({ +function getEntitySettingsSuggestions({ allRulesInList, anyRuleInList, -}: GetParticularSuggestionProps): boolean | undefined { - if (anyRuleInList(YQLParser.RULE_table_setting_value)) { +}: GetParticularSuggestionProps): YQLEntity | undefined { + if ( + anyRuleInList([ + YQLParser.RULE_table_setting_value, + YQLParser.RULE_topic_setting_value, + YQLParser.RULE_topic_consumer_setting_value, + ]) + ) { return; } - return allRulesInList([YQLParser.RULE_with_table_settings, YQLParser.RULE_an_id]); + if (allRulesInList([YQLParser.RULE_with_table_settings, YQLParser.RULE_an_id])) { + if (anyRuleInList(YQLParser.RULE_create_external_data_source_stmt)) { + return 'externalDataSource'; + } + if (anyRuleInList(YQLParser.RULE_create_view_stmt)) { + return 'view'; + } + if (anyRuleInList(YQLParser.RULE_create_table_stmt)) { + return 'table'; + } + return; + } + if (allRulesInList([YQLParser.RULE_with_topic_settings, YQLParser.RULE_an_id])) { + return 'topic'; + } + if (allRulesInList([YQLParser.RULE_topic_consumer_with_settings, YQLParser.RULE_an_id])) { + return 'topicConsumer'; + } + if (allRulesInList([YQLParser.RULE_replication_settings, YQLParser.RULE_an_id])) { + return 'replication'; + } + return; } const ruleNames = YQLParser.ruleNames; @@ -425,7 +452,7 @@ export function getGranularSuggestions( const suggestFunctions = getFunctionsSuggestions(props); const suggestAggregateFunctions = getAggregateFunctionsSuggestions(props); const shouldSuggestTableHints = getTableHintsSuggestions(props); - const shouldSuggestTableSettings = getTableSettingsSuggestions(props); + const suggestEntitySettings = getEntitySettingsSuggestions(props); return { suggestWindowFunctions, @@ -439,9 +466,7 @@ export function getGranularSuggestions( suggestFunctions, suggestAggregateFunctions, suggestTableHints: shouldSuggestTableHints ? getParticularStatement(ruleList) : undefined, - suggestTableSettings: shouldSuggestTableSettings - ? getParticularStatement(ruleList) - : undefined, + suggestEntitySettings, suggestObject, suggestTableStore, suggestTable, diff --git a/src/autocomplete/databases/yql/tests/yql/create/create-external.test.ts b/src/autocomplete/databases/yql/tests/yql/create/create-external.test.ts index 7283c9cc..49b3ca51 100644 --- a/src/autocomplete/databases/yql/tests/yql/create/create-external.test.ts +++ b/src/autocomplete/databases/yql/tests/yql/create/create-external.test.ts @@ -26,3 +26,10 @@ test('should suggest properly after source name', () => { const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}]; expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); }); +test('should suggest properly after WITH', () => { + const autocompleteResult = parseYqlQueryWithCursor('CREATE EXTERNAL DATA SOURCE test WITH (|'); + + const keywordsSuggestion: KeywordSuggestion[] = []; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); + expect(autocompleteResult.suggestEntitySettings).toEqual('externalDataSource'); +}); diff --git a/src/autocomplete/databases/yql/tests/yql/create/create-replication.test.ts b/src/autocomplete/databases/yql/tests/yql/create/create-replication.test.ts index 223bf138..2eb7d12e 100644 --- a/src/autocomplete/databases/yql/tests/yql/create/create-replication.test.ts +++ b/src/autocomplete/databases/yql/tests/yql/create/create-replication.test.ts @@ -29,3 +29,20 @@ test('should suggest properly after FOR', () => { expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); expect(autocompleteResult.suggestEntity).toEqual(['table']); }); +test('should suggest properly after FOR', () => { + const autocompleteResult = parseYqlQueryWithCursor( + 'CREATE ASYNC REPLICATION test FOR target AS target |', + ); + + const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}]; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); +}); +test('should suggest properly after WITH', () => { + const autocompleteResult = parseYqlQueryWithCursor( + 'CREATE ASYNC REPLICATION test FOR target AS target WITH (|', + ); + + const keywordsSuggestion: KeywordSuggestion[] = []; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); + expect(autocompleteResult.suggestEntitySettings).toEqual('replication'); +}); diff --git a/src/autocomplete/databases/yql/tests/yql/create/create-table.test.ts b/src/autocomplete/databases/yql/tests/yql/create/create-table.test.ts index b7c9c80b..22caecc8 100644 --- a/src/autocomplete/databases/yql/tests/yql/create/create-table.test.ts +++ b/src/autocomplete/databases/yql/tests/yql/create/create-table.test.ts @@ -93,7 +93,7 @@ test('should suggest properly table hints', () => { const keywordsSuggestion: KeywordSuggestion[] = [{value: 'COLUMNS'}, {value: 'SCHEMA'}]; expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); expect(autocompleteResult.suggestTableHints).toEqual('create_table_stmt'); - expect(autocompleteResult.suggestTableSettings).toBeFalsy(); + expect(autocompleteResult.suggestEntitySettings).toBeFalsy(); }); test('should suggest properly table settings', () => { const autocompleteResult = parseYqlQueryWithCursor( @@ -101,6 +101,6 @@ test('should suggest properly table settings', () => { ); const keywordsSuggestion: KeywordSuggestion[] = []; expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); - expect(autocompleteResult.suggestTableSettings).toEqual('create_table_stmt'); + expect(autocompleteResult.suggestEntitySettings).toEqual('table'); expect(autocompleteResult.suggestTableHints).toBeFalsy(); }); diff --git a/src/autocomplete/databases/yql/tests/yql/create/create-topic.test.ts b/src/autocomplete/databases/yql/tests/yql/create/create-topic.test.ts index 319a3766..e8749525 100644 --- a/src/autocomplete/databases/yql/tests/yql/create/create-topic.test.ts +++ b/src/autocomplete/databases/yql/tests/yql/create/create-topic.test.ts @@ -28,3 +28,28 @@ test('should suggest properly after consumer name', () => { const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}]; expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); }); +test('should suggest properly after consumer WITH', () => { + const autocompleteResult = parseYqlQueryWithCursor( + 'CREATE TOPIC test (CONSUMER test_consumer WITH (|', + ); + + const keywordsSuggestion: KeywordSuggestion[] = []; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); + expect(autocompleteResult.suggestEntitySettings).toEqual('topicConsumer'); +}); +test('should suggest properly after consumer statement', () => { + const autocompleteResult = parseYqlQueryWithCursor( + 'CREATE TOPIC test (CONSUMER test_consumer) |', + ); + const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}]; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); +}); +test('should suggest properly after WITH', () => { + const autocompleteResult = parseYqlQueryWithCursor( + 'CREATE TOPIC test (CONSUMER test_consumer) WITH (|', + ); + + const keywordsSuggestion: KeywordSuggestion[] = []; + expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion); + expect(autocompleteResult.suggestEntitySettings).toEqual('topic'); +}); diff --git a/src/autocomplete/databases/yql/types.ts b/src/autocomplete/databases/yql/types.ts index 1838f347..c5f69bc6 100644 --- a/src/autocomplete/databases/yql/types.ts +++ b/src/autocomplete/databases/yql/types.ts @@ -22,7 +22,7 @@ type YqlAutocompleteResultPartial = Pick< | 'suggestTableFunctions' | 'suggestPragmas' | 'suggestTableHints' - | 'suggestTableSettings' + | 'suggestEntitySettings' >; export interface InternalSuggestions