feat: optimize suggestion (#231)

* feat: optimize the strategy of finding the right range

* test: apply commentOtherLine util to all suggestion tests

* test: decomment suggestion test cases

* test: add suggestion test cases in multiple statements

* chore: improve comments

* test: update log info in test
This commit is contained in:
Hayden
2023-12-13 11:33:47 +08:00
committed by GitHub
parent fd50c09a86
commit 3c7c59fb70
29 changed files with 930 additions and 155 deletions

View File

@ -638,29 +638,28 @@ describe('Postgre SQL Syntax Suggestion', () => {
lineNumber: 59,
column: 48,
};
// const pos1: CaretPosition = {
// lineNumber: 59,
// column: 93,
// };
const pos1: CaretPosition = {
lineNumber: 59,
column: 93,
};
const syntaxes = parser.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
// const syntaxes1 = parser.getSuggestionAtCaretPosition(
// commentOtherLine(syntaxSql, pos1.lineNumber),
// pos1
// )?.syntax;
const syntaxes1 = parser.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos1.lineNumber),
pos1
)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === SyntaxContextType.COLUMN
);
// const suggestion1 = syntaxes1?.find(
// (syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
// );
const suggestion1 = syntaxes1?.find(
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['column_name']);
// TODO: fix bug of basic parser and decomment following case
// expect(suggestion1).not.toBeUndefined();
// expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['function_name']);
expect(suggestion1).not.toBeUndefined();
expect(suggestion1?.wordRanges.map((token) => token.text)).toEqual(['function_name']);
});
test('GRANT With Column', () => {