Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/trino/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlPa
}
case TrinoSqlParser.RULE_columnName: {
if (
candidateRule.ruleList.includes(TrinoSqlParser.RULE_selectItem) ||
candidateRule.ruleList.includes(TrinoSqlParser.RULE_groupBy) ||
candidateRule.ruleList.includes(TrinoSqlParser.RULE_sortItem) ||
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whereClause) ||
Expand Down
2 changes: 2 additions & 0 deletions test/parser/trino/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ SELECT * FROM users CROSS JOIN UNNEST(friends) WITH ordinality;
SELECT FROM tb1;

SELECT age FROM tb1;

SELECT a. FROM tb1 a;
19 changes: 19 additions & 0 deletions test/parser/trino/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,25 @@ describe('Trino SQL Syntax Suggestion', () => {
).toEqual([['age'], ['age']]);
});

test('Select alias column', () => {
const pos: CaretPosition = {
lineNumber: 65,
column: 10,
};
const syntaxes = trino.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;

const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(1);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['a', '.']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down