Fix/basic suggestion (#119)

* fix: correct suggetion logic in multiple sql case

* test: add multiple sql test case of suggestion

* feat: export SyntaxContextType as enum
This commit is contained in:
Hayden
2023-06-12 15:21:27 +08:00
committed by GitHub
parent 1b02ff5d75
commit e34a9f6128
5 changed files with 42 additions and 11 deletions

View File

@ -0,0 +1,19 @@
CREATE TABLE orders (
order_uid BIGINT,
product_id BIGINT,
price DECIMAL(32, 2),
order_time TIMESTAMP(3)
) WITH (
'connector' = 'datagen'
);
CREATE TABLE orders (
order_uid BIGINT,
product_id BIGINT,
price DECIMAL(32, 2),
order_time TIMESTAMP(3)
) WITH (
'connector' = 'datagen'
);
use cat1.

View File

@ -4,6 +4,7 @@ import { CaretPosition, SyntaxContextType } from '../../../../src/parser/common/
import FlinkSQL from '../../../../src/parser/flinksql'
const syntaxSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'), 'utf-8');
const multipleSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'multipleSql.sql'), 'utf-8');
describe('Flink SQL Syntax Suggestion', () => {
const parser = new FlinkSQL();
@ -84,7 +85,19 @@ describe('Flink SQL Syntax Suggestion', () => {
expect(suggestion?.syntaxContextType === SyntaxContextType.DATABASE)
expect(suggestion?.wordRanges.map(token => token.text))
.toEqual([ 'cat', '.' ])
.toEqual([ 'cat', '.' ]);
})
test("Multiple SQL use database", () => {
const pos: CaretPosition = {
lineNumber: 19,
column: 10,
}
const suggestion = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax?.[0];
console.log(suggestion);
expect(suggestion?.syntaxContextType === SyntaxContextType.DATABASE);
expect(suggestion?.wordRanges.map(token => token.text))
.toEqual([ 'cat1', '.' ]);
})
})