Repository navigation
Conversation
| $.grantable, | ||
| $.default_privileges_target, | ||
| $.keyword_to, | ||
| comma_list(field("end", $.role_specification), true), |
There was a problem hiding this comment.
With a catalog containing bob, completing alter default privileges grant select on tables to b returns the bob Role item on the base commit, but an empty list here. The same regression occurs after REVOKE ... FROM, and existing roles also disappear after FOR ROLE.
The new tree correctly contains a role_identifier, but these clauses have no recognized wrapping context, so completable_context rejects catalog completions.
We should connect the new clauses to the completion context and add assertions for actual Role items alongside the keyword tests.
| optional($.default_privileges_for_role), | ||
| optional($.default_privileges_in_schema), |
There was a problem hiding this comment.
alter default privileges in schema public for role admin grant select on tables to bob; is valid PostgreSQL syntax. I verified it with the PostgreSQL 18 parser and executed both option orders successfully on PostgreSQL 15.
This sequence only accepts FOR ROLE followed by IN SCHEMA; reversing them leaves an ERROR node around FOR ROLE admin.
I think these options should remain order-independent, with a grammar test covering the reversed order and its completion states.
| SqlKeyword::new("parallel"), | ||
| SqlKeyword::new("partition"), | ||
| SqlKeyword::new("password"), | ||
| SqlKeyword::new("period"), |
There was a problem hiding this comment.
With public.t.period in the catalog, completing create table t (period int, primary key (period)); inside period now returns a Keyword item with no description or type detail. The base returned a Column item with its catalog metadata.
The tree still identifies this token as a column_identifier, and hover remains correct; the inserted text is also unchanged.
Maybe we could prefer the catalog Column item over the keyword candidate in this context, and assert the completion kind and metadata in the compatibility test.
Since #1055 we parse Postgres 18, but the tree-sitter grammar didn't know the new syntax, so completions inside it got an error tree and fell back to every keyword. This teaches the grammar the Postgres 18 additions to gram.y and adds their keywords to the completion list.
What changed
enforced,virtual,period,overlaps,large,objects, plussequences,types,schemasandusagefor the default-privilege targets. They are inALL_KEYWORDS, whose tests check that it matches the grammar.GENERATED ALWAYS AS (...) VIRTUAL,[NOT] ENFORCED,NOT NULL NO INHERIT,CONSTRAINT namebefore a column constraint, andREFERENCES twithout a column list.constraint_attributesnode after a constraint ([NOT] DEFERRABLE,INITIALLY ...,[NOT] ENFORCED,NOT VALID,NO INHERIT), named foreign key and unique constraints,[CONSTRAINT n] NOT NULL col,WITHOUT OVERLAPSin key columns andPERIODin foreign key columns (both sides). A column namedperiodstays a column.ALTER TABLE ... ALTER CONSTRAINT namewith the attributes it accepts:[NO] INHERITand noNOT VALID.ALTER DEFAULT PRIVILEGES [FOR ROLE ...] [IN SCHEMA ...] GRANT | REVOKE ... ON {TABLES | SEQUENCES | FUNCTIONS | ROUTINES | TYPES | SCHEMAS | LARGE OBJECTS}, a new statement. Each part is a partial rule withendfields, so completions work while it is typed.MERGE ... RETURNING(whereold/neware new in 18), and a list of relations, each with its ownONLY, forVACUUMandANALYZE.returning_withandANALYZE ONLYnow parse while they are typed (returning with (),analyze only).grantableandrole_specificationmark theirend.grantablealso takesusageandcreate.The
RETURNING WITH (...),old.*/new.*and the newCOPYoptions already parsed.Backwards compatibility
I parsed every statement that Postgres accepts in the 15–18 regression fixtures (127,026) with the old and the new grammar: none that parsed before has an error now, and 837 more parse.
Tests
grammar_tests.rs: one snapshot per construct, each asserting that the tree has no error. On main all but three have errors:UPDATE ... RETURNING WITHand theCOPYoptions already parsed, andpostgres_18_period_columnchecks that a column namedperiodstill parses.partial-sqls/pg18.sqlruns the typing-state test overRETURNING WITH (OLD AS ...),old.*/new.*andANALYZE ONLY t, ONLY u. It fails on main atreturning with ()andanalyze only.completes_default_privileges_targetsandcompletes_constraint_attributescheck the exact keywords after... ON,... ON LARGE,ALTER CONSTRAINT cand... NOT. On main the tree has an error there, so every keyword is offered.cargo test -p pgls_treesitter_grammar -p pgls_treesitter -p pgls_completions -p pgls_hover -p pgls_typecheck,cargo clippy --workspace --all-targets -- -D warnings.Not covered
VACUUM (options),CREATE TABLE ... INHERITS, partitions andOVERLAPSas an operator didn't parse before and still don't.CREATE TABLEandALTER TABLEaren't partial rules yet, so completions inside a half-typed column definition still see an error tree.ALTER DEFAULT PRIVILEGESis, fromalter defaulton.usage,largeand so on is still fine.Update:
GRANT role TO rolefollows Postgres again. WithoutON, the list afterGRANT/REVOKEis a list of roles, and the unreserved privilege names (insert,update,delete,truncate,trigger,maintain,execute,usage) are role names there, sogrant usage, update to bobparses with tworole_identifiers. The grammar declares the conflict betweengrantableand these role names, and theONdecides. Keyword completion now skips a keyword that the grammar would read as a name at the cursor, sogrant | to ownerstill offers roles first. New snapshotsgrant_role_named_usage,revoke_role_named_usageandgrant_usage_privilege. The comparison over the regression fixtures still finds no statement that parsed on main and fails now.