Skip to content

Commit 8dd5739

Browse files
author
Dmitry Selivestrov
committed
fix(trino): add selectItem rule to candidates for column suggestions
1 parent f65a451 commit 8dd5739

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/parser/trino/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlPa
136136
}
137137
case TrinoSqlParser.RULE_columnName: {
138138
if (
139+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_selectItem) ||
139140
candidateRule.ruleList.includes(TrinoSqlParser.RULE_groupBy) ||
140141
candidateRule.ruleList.includes(TrinoSqlParser.RULE_sortItem) ||
141142
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whereClause) ||

test/parser/trino/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ SELECT * FROM users CROSS JOIN UNNEST(friends) WITH ordinality;
6161
SELECT FROM tb1;
6262

6363
SELECT age FROM tb1;
64+
65+
SELECT a. FROM tb1 a;

test/parser/trino/suggestion/syntaxSuggestion.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,25 @@ describe('Trino SQL Syntax Suggestion', () => {
598598
).toEqual([['age'], ['age']]);
599599
});
600600

601+
test('Select alias column', () => {
602+
const pos: CaretPosition = {
603+
lineNumber: 65,
604+
column: 10,
605+
};
606+
const syntaxes = trino.getSuggestionAtCaretPosition(
607+
commentOtherLine(syntaxSql, pos.lineNumber),
608+
pos
609+
)?.syntax;
610+
611+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
612+
613+
expect(wordRangesArr).not.toBeUndefined();
614+
expect(wordRangesArr.length).toBe(1);
615+
expect(
616+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
617+
).toEqual([['a', '.']]);
618+
});
619+
601620
test('Syntax suggestion after a comment', () => {
602621
const sql = `-- the comment\nSELECT * FROM db.`;
603622
const pos: CaretPosition = {

0 commit comments

Comments
 (0)