supabase-community / postgres_lsp

A Language Server for Postgres
https://supabase.com
MIT License
3.32k stars 62 forks source link

feat: support "create schema" #63

Closed cvng closed 11 months ago

cvng commented 11 months ago

What kind of change does this PR introduce?

In the continuation of #61 & #51. Ultimately, being able to parse most of the DDL statements would be nice

What is the current behavior?

Parser panics:

could not find node for token Token { kind: Create, text: "CREATE", span: 0..6, token_type: ReservedKeyword } at depth 1

What is the new behavior?

Parser returns:

        CreateSchemaStmt(
            CreateSchemaStmt {
                schemaname: "test",
                authrole: Some(
                    RoleSpec {
                        roletype: RolespecCstring,
                        rolename: "joe",
                        location: 47,
                    },
                ),
                schema_elts: [],
                if_not_exists: true,
            },
        ),

Additional context

Add any other context or screenshots.

psteinroe commented 11 months ago

thanks @cvng! for an easier review, could you always put the output from libpg_query into the pr? I added the respective log in #64. I will also create a pr template for it. example for a different statement:

CreateDomainStmt(
            CreateDomainStmt {
                domainname: [
                    Node {
                        node: Some(
                            String(
                                String {
                                    sval: "us_postal_code",
                                },
                            ),
                        ),
                    },
                ],
                type_name: Some(
                    TypeName {
                        names: [
                            Node {
                                node: Some(
                                    String(
                                        String {
                                            sval: "text",
                                        },
                                    ),
                                ),
                            },
                        ],
                        type_oid: 0,
                        setof: false,
                        pct_type: false,
                        typmods: [],
                        typemod: -1,
                        array_bounds: [],
                        location: 32,
                    },
                ),
                coll_clause: None,
                constraints: [
                    Node {
                        node: Some(
                            Constraint(
                                Constraint {
                                    contype: ConstrCheck,
                                    conname: "",
                                    deferrable: false,
                                    initdeferred: false,
                                    location: 37,
                                    is_no_inherit: false,
                                    raw_expr: Some(
                                        Node {
                                            node: Some(
                                                NullTest(
                                                    NullTest {
                                                        xpr: None,
                                                        arg: Some(
                                                            Node {
                                                                node: Some(
                                                                    ColumnRef(
                                                                        ColumnRef {
                                                                            fields: [
                                                                                Node {
                                                                                    node: Some(
                                                                                        String(
                                                                                            String {
                                                                                                sval: "value",
                                                                                            },
                                                                                        ),
                                                                                    ),
                                                                                },
                                                                            ],
                                                                            location: 44,
                                                                        },
                                                                    ),
                                                                ),
                                                            },
                                                        ),
                                                        nulltesttype: IsNotNull,
                                                        argisrow: false,
                                                        location: 50,
                                                    },
                                                ),
                                            ),
                                        },
                                    ),
                                    cooked_expr: "",
                                    generated_when: "",
                                    nulls_not_distinct: false,
                                    keys: [],
                                    including: [],
                                    exclusions: [],
                                    options: [],
                                    indexname: "",
                                    indexspace: "",
                                    reset_default_tblspc: false,
                                    access_method: "",
                                    where_clause: None,
                                    pktable: None,
                                    fk_attrs: [],
                                    pk_attrs: [],
                                    fk_matchtype: "",
                                    fk_upd_action: "",
                                    fk_del_action: "",
                                    fk_del_set_cols: [],
                                    old_conpfeqop: [],
                                    old_pktable_oid: 0,
                                    skip_validation: false,
                                    initially_valid: true,
                                },
                            ),
                        ),
                    },
                ],
            },
        ),
cvng commented 11 months ago

sure! I will rebase once #64 merged. +1 for a pr template