Skip to content

sync main to next #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2024
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
3,812 changes: 946 additions & 2,866 deletions src/grammar/postgresql/PostgreSqlParser.g4

Large diffs are not rendered by default.

428 changes: 10 additions & 418 deletions src/lib/postgresql/PostgreSqlParser.interp

Large diffs are not rendered by default.

126,909 changes: 49,446 additions & 77,463 deletions src/lib/postgresql/PostgreSqlParser.ts

Large diffs are not rendered by default.

7,618 changes: 1,617 additions & 6,001 deletions src/lib/postgresql/PostgreSqlParserListener.ts

Large diffs are not rendered by default.

4,224 changes: 716 additions & 3,508 deletions src/lib/postgresql/PostgreSqlParserVisitor.ts

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions src/parser/common/basicSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ export abstract class BasicSQL<
return null;
}
const splitListener = this.splitListener;
// TODO: add splitListener to all sqlParser implements and remove following if
if (!splitListener) return null;

this.listen(splitListener, this._parseTree);

Expand All @@ -256,8 +254,6 @@ export abstract class BasicSQL<
caretPosition: CaretPosition
): Suggestions | null {
const splitListener = this.splitListener;
// TODO: add splitListener to all sqlParser implements and remove following if
if (!splitListener) return null;

this.parseWithCache(input);
if (!this._parseTree) return null;
Expand Down Expand Up @@ -383,10 +379,6 @@ export abstract class BasicSQL<
: void 0;

const collectListener = this.createEntityCollector(input, caretTokenIndex);
// TODO: add entityCollector to all sqlParser implements and remove following if
if (!collectListener) {
return null;
}
// const parser = this.createParserWithCache(input);

// parser.entityCollecting = true;
Expand Down
1 change: 1 addition & 0 deletions src/parser/common/entityCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum StmtContextType {
SELECT_STMT = 'selectStmt',
INSERT_STMT = 'insertStmt',
CREATE_FUNCTION_STMT = 'createFunctionStmt',
ALTER_TABLE_STMT = 'alterTableStmt',
}

export interface StmtContext {
Expand Down
7 changes: 7 additions & 0 deletions src/parser/postgresql/postgreEntityCollector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AltertablestmtContext,
ColumnCreateTableContext,
ColumnNameCreateContext,
CreateDatabaseContext,
Expand Down Expand Up @@ -145,4 +146,10 @@ export class PostgreSqlEntityCollector extends EntityCollector implements Postgr
exitCreatefunctionstmt(ctx: CreatefunctionstmtContext) {
this.popStmt();
}
enterAltertablestmt(ctx: AltertablestmtContext) {
this.pushStmt(ctx, StmtContextType.ALTER_TABLE_STMT);
}
exitAltertablestmt(ctx: AltertablestmtContext) {
this.popStmt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ INSERT INTO insert_tb SELECT id, age, FROM from_tb;

CREATE TABLE sorted_census_data AS SELECT FROM unsorted_census_data;

CREATE TABLE sorted_census_data AS SELECT id, age, FROM unsorted_census_data;
CREATE TABLE sorted_census_data AS SELECT id, age, FROM unsorted_census_data;

ALTER TABLE my_table DROP a_column;
21 changes: 21 additions & 0 deletions test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,25 @@ describe('PostgreSql Syntax Suggestion with collect entity', () => {
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
});

test('alter table drop column', () => {
const pos: CaretPosition = {
lineNumber: 13,
column: 35,
};
const sql = commentOtherLine(syntaxSql, pos.lineNumber);

const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
const suggestion = syntaxes?.find(
(syn) => syn.syntaxContextType === EntityContextType.COLUMN
);
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['a_column']);

const entities = postgre.getAllEntities(sql, pos);
expect(entities.length).toBe(1);
expect(entities[0].text).toBe('my_table');
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
expect(entities[0].belongStmt?.isContainCaret).toBeTruthy();
});
});
Loading