Skip to content

Commit

Permalink
feat(YQL): suggest simple types in expressions (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Makarova <[email protected]>
  • Loading branch information
Raubzeug and Elena Makarova authored Jun 6, 2024
1 parent c451173 commit 6c81be6
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/autocomplete/databases/yql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,12 @@ function getColumnsSuggestions({

function getSimpleTypesSuggestions({
anyRuleInList,
allRulesInList,
}: GetParticularSuggestionProps): boolean | undefined {
return anyRuleInList(YQLParser.RULE_type_name_simple);
const simpleTypeInExpression =
allRulesInList([YQLParser.RULE_id_expr, YQLParser.RULE_select_stmt]) &&
!anyRuleInList(YQLParser.RULE_table_ref);
return anyRuleInList(YQLParser.RULE_type_name_simple) || simpleTypeInExpression;
}

function getPragmasSuggestions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function getAfterGroupByCommonExpections(autocompleteResult: YqlAutocompleteResu
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ test('should suggest tables after JOIN', () => {
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeFalsy();
expect(autocompleteResult.suggestSimpleTypes).toBeFalsy();
expect(autocompleteResult.suggestUdfs).toBeFalsy();
expect(autocompleteResult.suggestTableFunctions).toBeTruthy();
});
Expand All @@ -84,6 +85,7 @@ test('should suggest tables after JOIN between statements', () => {
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeFalsy();
expect(autocompleteResult.suggestSimpleTypes).toBeFalsy();
expect(autocompleteResult.suggestUdfs).toBeFalsy();
expect(autocompleteResult.suggestTableFunctions).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getAfterOrderByCommonExpections(autocompleteResult: YqlAutocompleteResu
expect(autocompleteResult.suggestAggregateFunctions).toBeTruthy();
expect(autocompleteResult.suggestWindowFunctions).toBeTruthy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
expect(autocompleteResult.suggestKeywords).toEqual(afterOrderByKeywords);
Expand Down
7 changes: 5 additions & 2 deletions src/autocomplete/databases/yql/tests/yq/select/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ test('should suggest properly after SELECT', () => {
{value: 'TAGGED'},
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toEqual(true);
expect(autocompleteResult.suggestUdfs).toEqual(true);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
});
test('should suggest properly after FROM', () => {
const autocompleteResult = parseYqQueryWithCursor('FROM |');
Expand Down Expand Up @@ -258,6 +259,7 @@ test('should suggest properly after HAVING', () => {
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestColumns).toBeTruthy();
});
Expand Down Expand Up @@ -293,6 +295,7 @@ test('should suggest properly after LIMIT', () => {
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function getAfterWhereCommonExpections(autocompleteResult: YqlAutocompleteResult
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
expect(autocompleteResult.suggestKeywords).toEqual(AfterWhereKeywords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ test('should suggest properly after PASSWORD', () => {
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toBeFalsy();
expect(autocompleteResult.suggestSimpleTypes).toBeFalsy();
expect(autocompleteResult.suggestUdfs).toBeFalsy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function getAfterGroupByCommonExpections(autocompleteResult: YqlAutocompleteResu
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ test('should suggest tables after JOIN', () => {
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeFalsy();
expect(autocompleteResult.suggestSimpleTypes).toBeFalsy();
expect(autocompleteResult.suggestUdfs).toBeFalsy();
expect(autocompleteResult.suggestTableFunctions).toBeTruthy();
});
Expand All @@ -84,6 +85,7 @@ test('should suggest tables after JOIN between statements', () => {
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeFalsy();
expect(autocompleteResult.suggestSimpleTypes).toBeFalsy();
expect(autocompleteResult.suggestUdfs).toBeFalsy();
expect(autocompleteResult.suggestTableFunctions).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getAfterOrderByCommonExpections(autocompleteResult: YqlAutocompleteResu
expect(autocompleteResult.suggestAggregateFunctions).toBeTruthy();
expect(autocompleteResult.suggestWindowFunctions).toBeTruthy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
expect(autocompleteResult.suggestKeywords).toEqual(afterOrderByKeywords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ test('should suggest properly after SELECT', () => {
{value: 'TAGGED'},
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toEqual(true);
expect(autocompleteResult.suggestUdfs).toEqual(true);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
});
test('should suggest properly after FROM', () => {
const autocompleteResult = parseYqlQueryWithCursor('FROM |');
Expand Down Expand Up @@ -258,6 +259,7 @@ test('should suggest properly after HAVING', () => {
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestColumns).toBeTruthy();
});
Expand Down Expand Up @@ -293,6 +295,7 @@ test('should suggest properly after LIMIT', () => {
];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function getAfterWhereCommonExpections(autocompleteResult: YqlAutocompleteResult
expect(autocompleteResult.suggestAggregateFunctions).toBeFalsy();
expect(autocompleteResult.suggestWindowFunctions).toBeFalsy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
expect(autocompleteResult.suggestKeywords).toEqual(AfterWhereKeywords);
Expand Down Expand Up @@ -66,6 +67,7 @@ test('should suggest properly after WHERE expr', () => {
expect(autocompleteResult.suggestAggregateFunctions).toBeTruthy();
expect(autocompleteResult.suggestWindowFunctions).toBeTruthy();
expect(autocompleteResult.suggestFunctions).toBeTruthy();
expect(autocompleteResult.suggestSimpleTypes).toBeTruthy();
expect(autocompleteResult.suggestUdfs).toBeTruthy();
expect(autocompleteResult.suggestTableFunctions).toBeFalsy();
expect(autocompleteResult.suggestKeywords).toEqual(AfterWhereKeywords);
Expand Down

0 comments on commit 6c81be6

Please sign in to comment.