feat: FlinkSQL supports auto complete (#115)

* feat: add antlr4-c3 dependencies

* feat: distinguish table, catalog and database from uid

* feat: move semicolon from sqlStatements to sqlStatement

* chore: move antlr4ts-cli to devDependencies

* feat: improve basic parser and support suggestions of token and syntax

* feat: implement suggest method in sql parsers

* test: flink sql suggestion test cases

* feat: optimize ts defination of suggestion

* feat: add split listener and optimize performance of auto-completion

* test: supplementary flink suggestion unit tests
This commit is contained in:
Hayden
2023-06-09 11:22:53 +08:00
committed by GitHub
parent 2637f90295
commit 1b02ff5d75
25 changed files with 4521 additions and 3418 deletions

View File

@ -0,0 +1,33 @@
import { Token } from "antlr4ts";
import { CaretPosition } from "../../src/parser/common/basic-parser-types";
/**
* find token index via caret position (cursor position)
* @param caretPosition
* @param allTokens all the tokens
* @returns caretTokenIndex
*/
export function findCaretTokenIndex(caretPosition: CaretPosition, allTokens: Token[]) {
const { lineNumber: caretLine, column: caretCol } = caretPosition;
let left = 0;
let right = allTokens.length - 1;
while(left <= right) {
const mid = left + ((right - left) >> 1);
const token = allTokens[mid];
if (token.line > caretLine || (
token.line === caretLine
&& token.charPositionInLine + 1 >= caretCol
)) {
right = mid - 1;
} else if (token.line < caretLine || (
token.line === caretLine
&& token.charPositionInLine + token.text.length + 1 < caretCol
)) {
left = mid + 1;
} else {
return allTokens[mid].tokenIndex
}
}
return null;
}