Skip to content

Commit 8af4d98

Browse files
feat: improved grammar for pg-regress select.sql (#672)
1 parent 047d5fb commit 8af4d98

40 files changed

Lines changed: 599377 additions & 395279 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

biome.jsonc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"include": ["packages/**/*"]
1212
},
1313
"formatter": {
14-
"enabled": true,
15-
"indentStyle": "tab"
14+
"enabled": true
1615
},
1716
"organizeImports": {
1817
"enabled": true

crates/pgls_completions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tree-sitter.workspace = true
2727
[dev-dependencies]
2828
criterion.workspace = true
2929
insta.workspace = true
30+
pgls_schema_cache = { workspace = true, features = ["db"] }
3031
pgls_test_utils.workspace = true
3132
regex = "1.12.2"
3233
sqlx.workspace = true

crates/pgls_completions/src/providers/keywords.rs

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ pub static ALL_KEYWORDS: &[SqlKeyword] = &[
4242
SqlKeyword::new("all"),
4343
SqlKeyword::new("alter").starts_statement(),
4444
SqlKeyword::new("always"),
45-
SqlKeyword::new("analyze").starts_statement(),
45+
SqlKeyword::new("analyze")
46+
.starts_statement()
47+
.require_prefix(),
4648
SqlKeyword::new("and").require_prefix(),
4749
SqlKeyword::new("any").require_prefix(),
4850
SqlKeyword::new("array").require_prefix(),
@@ -123,7 +125,9 @@ pub static ALL_KEYWORDS: &[SqlKeyword] = &[
123125
SqlKeyword::new("exclude"),
124126
SqlKeyword::new("execute"),
125127
SqlKeyword::new("exists").require_prefix(),
126-
SqlKeyword::new("explain").starts_statement(),
128+
SqlKeyword::new("explain")
129+
.starts_statement()
130+
.require_prefix(),
127131
SqlKeyword::new("extended"),
128132
SqlKeyword::new("extension"),
129133
SqlKeyword::new("external"),
@@ -174,7 +178,7 @@ pub static ALL_KEYWORDS: &[SqlKeyword] = &[
174178
SqlKeyword::new("interval").require_prefix(),
175179
SqlKeyword::new("into"),
176180
SqlKeyword::new("invoker"),
177-
SqlKeyword::new("is"),
181+
SqlKeyword::new("is").require_prefix(),
178182
SqlKeyword::new("isolation"),
179183
SqlKeyword::new("join"),
180184
SqlKeyword::new("json"),
@@ -430,6 +434,14 @@ mod tests {
430434
assert_complete_results(
431435
query.as_str(),
432436
vec![
437+
CompletionAssertion::LabelAndKind(
438+
"create".into(),
439+
crate::CompletionItemKind::Keyword,
440+
),
441+
CompletionAssertion::LabelAndKind(
442+
"drop".into(),
443+
crate::CompletionItemKind::Keyword,
444+
),
433445
CompletionAssertion::LabelAndKind(
434446
"insert".into(),
435447
crate::CompletionItemKind::Keyword,
@@ -609,10 +621,13 @@ mod tests {
609621

610622
assert_complete_results(
611623
query.as_str(),
612-
vec![CompletionAssertion::LabelAndKind(
613-
"from".into(),
614-
crate::CompletionItemKind::Keyword,
615-
)],
624+
vec![
625+
CompletionAssertion::LabelAndKind("for".into(), crate::CompletionItemKind::Keyword),
626+
CompletionAssertion::LabelAndKind(
627+
"from".into(),
628+
crate::CompletionItemKind::Keyword,
629+
),
630+
],
616631
Some(setup),
617632
&pool,
618633
)
@@ -635,10 +650,17 @@ mod tests {
635650

636651
assert_complete_results(
637652
query.as_str(),
638-
vec![CompletionAssertion::LabelAndKind(
639-
"from".into(),
640-
crate::CompletionItemKind::Keyword,
641-
)],
653+
vec![
654+
CompletionAssertion::LabelAndKind(
655+
"except".into(),
656+
crate::CompletionItemKind::Keyword,
657+
),
658+
CompletionAssertion::LabelAndKind("for".into(), crate::CompletionItemKind::Keyword),
659+
CompletionAssertion::LabelAndKind(
660+
"from".into(),
661+
crate::CompletionItemKind::Keyword,
662+
),
663+
],
642664
Some(setup),
643665
&pool,
644666
)
@@ -685,6 +707,11 @@ mod tests {
685707
"cross".into(),
686708
crate::CompletionItemKind::Keyword,
687709
),
710+
CompletionAssertion::LabelAndKind(
711+
"except".into(),
712+
crate::CompletionItemKind::Keyword,
713+
),
714+
CompletionAssertion::LabelAndKind("for".into(), crate::CompletionItemKind::Keyword),
688715
CompletionAssertion::LabelAndKind(
689716
"full".into(),
690717
crate::CompletionItemKind::Keyword,
@@ -697,6 +724,10 @@ mod tests {
697724
"inner".into(),
698725
crate::CompletionItemKind::Keyword,
699726
),
727+
CompletionAssertion::LabelAndKind(
728+
"intersect".into(),
729+
crate::CompletionItemKind::Keyword,
730+
),
700731
CompletionAssertion::LabelAndKind(
701732
"join".into(),
702733
crate::CompletionItemKind::Keyword,
@@ -713,10 +744,30 @@ mod tests {
713744
"natural".into(),
714745
crate::CompletionItemKind::Keyword,
715746
),
747+
CompletionAssertion::LabelAndKind(
748+
"offset".into(),
749+
crate::CompletionItemKind::Keyword,
750+
),
716751
CompletionAssertion::LabelAndKind(
717752
"order".into(),
718753
crate::CompletionItemKind::Keyword,
719754
),
755+
CompletionAssertion::LabelAndKind(
756+
"right".into(),
757+
crate::CompletionItemKind::Keyword,
758+
),
759+
CompletionAssertion::LabelAndKind(
760+
"union".into(),
761+
crate::CompletionItemKind::Keyword,
762+
),
763+
CompletionAssertion::LabelAndKind(
764+
"where".into(),
765+
crate::CompletionItemKind::Keyword,
766+
),
767+
CompletionAssertion::LabelAndKind(
768+
"window".into(),
769+
crate::CompletionItemKind::Keyword,
770+
),
720771
],
721772
Some(setup),
722773
&pool,
@@ -797,9 +848,12 @@ mod tests {
797848
query.as_str(),
798849
vec![
799850
CompletionAssertion::LabelAndKind("cross".into(), CompletionItemKind::Keyword),
851+
CompletionAssertion::LabelAndKind("except".into(), CompletionItemKind::Keyword),
852+
CompletionAssertion::LabelAndKind("for".into(), CompletionItemKind::Keyword),
800853
CompletionAssertion::LabelAndKind("full".into(), CompletionItemKind::Keyword),
801854
CompletionAssertion::LabelAndKind("group".into(), CompletionItemKind::Keyword),
802855
CompletionAssertion::LabelAndKind("inner".into(), CompletionItemKind::Keyword),
856+
CompletionAssertion::LabelAndKind("intersect".into(), CompletionItemKind::Keyword),
803857
CompletionAssertion::LabelAndKind("join".into(), CompletionItemKind::Keyword),
804858
],
805859
Some(setup),

crates/pgls_completions/src/relevance/filtering.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,41 @@ mod tests {
629629

630630
assert_complete_results(
631631
format!("select * {}", QueryWithCursorPosition::cursor_marker()).as_str(),
632-
vec![CompletionAssertion::LabelAndKind(
633-
"from".into(),
634-
crate::CompletionItemKind::Keyword,
635-
)],
632+
vec![
633+
CompletionAssertion::LabelAndKind(
634+
"except".into(),
635+
crate::CompletionItemKind::Keyword,
636+
),
637+
CompletionAssertion::LabelAndKind("for".into(), crate::CompletionItemKind::Keyword),
638+
CompletionAssertion::LabelAndKind(
639+
"from".into(),
640+
crate::CompletionItemKind::Keyword,
641+
),
642+
CompletionAssertion::LabelAndKind(
643+
"group".into(),
644+
crate::CompletionItemKind::Keyword,
645+
),
646+
CompletionAssertion::LabelAndKind(
647+
"intersect".into(),
648+
crate::CompletionItemKind::Keyword,
649+
),
650+
CompletionAssertion::LabelAndKind(
651+
"limit".into(),
652+
crate::CompletionItemKind::Keyword,
653+
),
654+
CompletionAssertion::LabelAndKind(
655+
"offset".into(),
656+
crate::CompletionItemKind::Keyword,
657+
),
658+
CompletionAssertion::LabelAndKind(
659+
"order".into(),
660+
crate::CompletionItemKind::Keyword,
661+
),
662+
CompletionAssertion::LabelAndKind(
663+
"union".into(),
664+
crate::CompletionItemKind::Keyword,
665+
),
666+
],
636667
None,
637668
&pool,
638669
)

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__after_from_clause.snap

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ select email from users |
1616

1717
Results:
1818
cross - cross (Keyword)
19+
except - except (Keyword)
20+
for - for (Keyword)
1921
full - full (Keyword)
2022
group - group (Keyword)
21-
inner - inner (Keyword)
22-
join - join (Keyword)
2323

2424
--------------
2525

@@ -56,10 +56,11 @@ identity_generation - information_schema.columns.identity_generation (Column)
5656
select email from users where id |
5757

5858
Results:
59+
except - except (Keyword)
60+
for - for (Keyword)
5961
group - group (Keyword)
62+
intersect - intersect (Keyword)
6063
limit - limit (Keyword)
61-
order - order (Keyword)
62-
window - window (Keyword)
6364

6465
--------------
6566

@@ -78,10 +79,10 @@ select email from users where id = 1|
7879
select email from users where id = 1; |
7980

8081
Results:
82+
create - create (Keyword)
83+
drop - drop (Keyword)
8184
insert - insert (Keyword)
8285
reset - reset (Keyword)
8386
select - select (Keyword)
84-
set - set (Keyword)
85-
truncate - truncate (Keyword)
8687

8788
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_in_join_on_clause.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ select u.id, auth.posts.content from auth.users u join auth.posts p on p.user_id
5959

6060
Results:
6161
cross - cross (Keyword)
62+
except - except (Keyword)
63+
for - for (Keyword)
6264
full - full (Keyword)
6365
group - group (Keyword)
64-
inner - inner (Keyword)
65-
join - join (Keyword)
6666

6767
--------------
6868

@@ -98,10 +98,10 @@ uid - auth.users.uid (Column)
9898
select u.id, auth.posts.content from auth.users u join auth.posts p on p.user_id = u.uid; |
9999

100100
Results:
101+
create - create (Keyword)
102+
drop - drop (Keyword)
101103
insert - insert (Keyword)
102104
reset - reset (Keyword)
103105
select - select (Keyword)
104-
set - set (Keyword)
105-
truncate - truncate (Keyword)
106106

107107
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,20 @@ encoding - pg_catalog.pg_database.encoding (Column)
7474
select "email" |
7575

7676
Results:
77+
except - except (Keyword)
78+
for - for (Keyword)
7779
from - from (Keyword)
80+
group - group (Keyword)
81+
intersect - intersect (Keyword)
7882

7983
--------------
8084

8185
select "email" f|
8286

8387
Results:
88+
for - for (Keyword)
8489
from - from (Keyword)
90+
offset - offset (Keyword)
8591

8692
--------------
8793

@@ -140,10 +146,10 @@ select "email" from "private".u|
140146
select "email" from "private".users; |
141147

142148
Results:
149+
create - create (Keyword)
150+
drop - drop (Keyword)
143151
insert - insert (Keyword)
144152
reset - reset (Keyword)
145153
select - select (Keyword)
146-
set - set (Keyword)
147-
truncate - truncate (Keyword)
148154

149155
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ select "pr"."e|"
8585
select "pr"."email" |
8686

8787
Results:
88+
except - except (Keyword)
89+
for - for (Keyword)
8890
from - from (Keyword)
91+
group - group (Keyword)
92+
intersect - intersect (Keyword)
8993

9094
--------------
9195

9296
select "pr"."email" f|
9397

9498
Results:
99+
for - for (Keyword)
95100
from - from (Keyword)
101+
offset - offset (Keyword)
96102

97103
--------------
98104

@@ -136,10 +142,10 @@ select "pr"."email" from private.users |
136142

137143
Results:
138144
cross - cross (Keyword)
145+
except - except (Keyword)
146+
for - for (Keyword)
139147
full - full (Keyword)
140148
group - group (Keyword)
141-
inner - inner (Keyword)
142-
join - join (Keyword)
143149

144150
--------------
145151

@@ -150,10 +156,10 @@ select "pr"."email" from private.users "pr" |
150156

151157
Results:
152158
cross - cross (Keyword)
159+
except - except (Keyword)
160+
for - for (Keyword)
153161
full - full (Keyword)
154162
group - group (Keyword)
155-
inner - inner (Keyword)
156-
join - join (Keyword)
157163

158164
--------------
159165

0 commit comments

Comments
 (0)