Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5707bb8
pickin up fast
juleswritescode Nov 7, 2025
8b96f00
so far
juleswritescode Nov 8, 2025
799f52d
changie
juleswritescode Nov 8, 2025
f8ca407
readied
juleswritescode Nov 8, 2025
6365f80
more removed
juleswritescode Nov 8, 2025
4324377
minor changes
juleswritescode Nov 8, 2025
9586d8c
Update crates/pgls_completions/src/relevance/filtering.rs
juleswritescode Nov 8, 2025
c3201e7
use indoc, add setup
juleswritescode Nov 9, 2025
cbbe1f2
Merge branch 'feat/completions-test-suite' of https://github.com/supa…
juleswritescode Nov 9, 2025
09664c1
ok
juleswritescode Nov 9, 2025
853929c
many fixings
juleswritescode Nov 22, 2025
ad45958
Merge branch 'main' of https://github.com/supabase-community/postgres…
juleswritescode Nov 22, 2025
0a9be8a
remove all commata?
juleswritescode Nov 22, 2025
6fabed2
use current version of bun
juleswritescode Nov 22, 2025
cdb4355
Merge branch 'feat/completions-test-suite' of https://github.com/supa…
juleswritescode Nov 22, 2025
c0e2d35
fixed aaaaaaaaaaaaaaat
juleswritescode Nov 22, 2025
324c4f5
commit
juleswritescode Nov 22, 2025
9c07d91
accept snaps
juleswritescode Nov 22, 2025
359a8ff
ok?
juleswritescode Nov 22, 2025
195c706
do not prefer public schema
juleswritescode Nov 22, 2025
9f8435f
more adjustments
juleswritescode Nov 22, 2025
61b02ff
snaps
juleswritescode Nov 22, 2025
0dc7f2b
ok
juleswritescode Nov 22, 2025
46c2596
slight improvement
juleswritescode Nov 22, 2025
faf3793
intermediary
juleswritescode Nov 29, 2025
f55386a
merged
juleswritescode Dec 12, 2025
4cf53b4
many changes
juleswritescode Dec 12, 2025
cf0c98d
this is gret
juleswritescode Dec 12, 2025
21217b5
commitered
juleswritescode Dec 13, 2025
0accdf2
many cheeeenges
juleswritescode Dec 13, 2025
f8daaf3
fix: rest of tests
juleswritescode Dec 13, 2025
7ce97c6
removed many stuffs
juleswritescode Dec 13, 2025
9e29117
squieliex
juleswritescode Dec 13, 2025
2f97f7f
readied
juleswritescode Dec 13, 2025
db53efd
Merge branch 'main' of https://github.com/supabase-community/postgres…
juleswritescode Dec 13, 2025
d4e8b48
only install if no cache
juleswritescode Dec 13, 2025
71969bb
rename test bin?
juleswritescode Dec 13, 2025
c484d0b
that one, too
juleswritescode Dec 13, 2025
a6cbde6
aha!
juleswritescode Dec 13, 2025
78cecce
remove depr tests
juleswritescode Dec 13, 2025
0068c2a
disable-db
juleswritescode Dec 13, 2025
87925f2
clean
juleswritescode Dec 13, 2025
c4e5747
ack
juleswritescode Dec 13, 2025
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
21 changes: 6 additions & 15 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ jobs:
path: |
~/.cargo/bin/tree-sitter
~/.cargo/bin/sqlx
~/.cargo/bin/cargo-sqlx
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup tree-sitter
run: cargo install tree-sitter-cli
run: command -v tree-sitter || cargo install tree-sitter-cli

- name: Setup sqlx-cli
run: cargo install sqlx-cli
run: command -v sqlx ||cargo install sqlx-cli

- name: Setup Bun
uses: oven-sh/setup-bun@v2
Expand Down Expand Up @@ -186,7 +187,7 @@ jobs:
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup Postgres
run: cargo install tree-sitter-cli
run: command -v tree-sitter || cargo install tree-sitter-cli

- name: Run tests
run: cargo test --workspace
Expand Down Expand Up @@ -222,24 +223,14 @@ jobs:
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
- name: setup tree-sitter
run: cargo install tree-sitter-cli
run: command -v tree-sitter || cargo install tree-sitter-cli
- name: Build main binary
run: cargo build -p pgls_cli --release
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install JS dependencies
run: bun install

- name: Build backend-jsonrpc (deprecated)
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run build
- name: Run backend-jsonrpc test (deprecated)
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run test
- name: Run cli test (deprecated)
working-directory: packages/@postgrestools/postgrestools
run: bun run test

- name: Build backend-jsonrpc
working-directory: packages/@postgres-language-server/backend-jsonrpc
run: bun run build
Expand Down Expand Up @@ -281,7 +272,7 @@ jobs:
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
- name: setup tree-sitter
run: cargo install tree-sitter-cli
run: command -v tree-sitter || cargo install tree-sitter-cli
- name: Ensure RustFMT on nightly toolchain
run: rustup component add rustfmt --toolchain nightly
- name: echo toolchain
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup tree-sitter
run: cargo install tree-sitter-cli
run: command -v tree-sitter || cargo install tree-sitter-cli

- name: Setup Postgres
uses: ./.github/actions/setup-postgres
Expand Down
2 changes: 2 additions & 0 deletions crates/pgls_completions/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl<'a> CompletionBuilder<'a> {
item.score.calc_score(self.ctx);
}

items.retain(|i| !i.score.should_skip());

items.sort_by(|a, b| {
b.score
.get_score()
Expand Down
13 changes: 5 additions & 8 deletions crates/pgls_completions/src/providers/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ mod tests {
TestCompletionsCase::new()
.inside_static_statement(r#"
select * from (
<sql>
<sql> from private.audio_books
) as subquery
join public.users u
on u.id = subquery.id;
"#)
.type_sql("select id, narrator_id<1> from private.audio_books")
.type_sql("select id, narrator_id<1>")
.comment("Should prefer the one from private.audio_audiobooks, since the other tables are out of scope.")
)
.snapshot("handles_nested_queries")
Expand Down Expand Up @@ -439,9 +439,9 @@ mod tests {
"select name from instruments i join others o on i.z = o.a <sql>",
)
.type_sql("where o.<1>a = <2>i.z and <3>i.id > 5;")
.comment("should respect alias speciifcation")
.comment("should not prioritize suggest columns or schemas (right side of binary expression)")
.comment("should prioritize columns that aren't already mentioned")
.comment("should respect alias speciifcation")
.comment("should not prioritize suggest columns or schemas (right side of binary expression)")
.comment("should prioritize columns that aren't already mentioned"),
)
.snapshot("suggests_columns_in_where_clause")
.await;
Expand All @@ -459,9 +459,6 @@ mod tests {
"#;

TestCompletionsSuite::new(&pool, Some(setup))
.with_case(
TestCompletionsCase::new().type_sql("alter table instruments drop column name"),
)
.with_case(
TestCompletionsCase::new().type_sql("alter table instruments drop column name"),
)
Expand Down
8 changes: 4 additions & 4 deletions crates/pgls_completions/src/providers/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ mod tests {
assert_complete_results(
format!("select * from {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![
CompletionAssertion::LabelAndKind("public".to_string(), CompletionItemKind::Schema),
// users table still preferred over schemas
CompletionAssertion::LabelAndKind("users".to_string(), CompletionItemKind::Table),
CompletionAssertion::LabelAndKind("auth".to_string(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind(
"internal".to_string(),
Expand All @@ -69,8 +70,7 @@ mod tests {
"private".to_string(),
CompletionItemKind::Schema,
),
// users table still preferred over system schemas
CompletionAssertion::LabelAndKind("users".to_string(), CompletionItemKind::Table),
// system schemas have lowest preference
CompletionAssertion::LabelAndKind(
"information_schema".to_string(),
CompletionItemKind::Schema,
Expand Down Expand Up @@ -110,8 +110,8 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
CompletionAssertion::LabelAndKind("ultimate".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
],
Some(setup),
&pool,
Expand Down
33 changes: 19 additions & 14 deletions crates/pgls_completions/src/providers/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ mod tests {
assert_complete_results(
format!("update {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![CompletionAssertion::LabelAndKind(
"public".into(),
CompletionItemKind::Schema,
"coos".into(),
CompletionItemKind::Table,
)],
None,
&pool,
Expand Down Expand Up @@ -354,10 +354,10 @@ mod tests {

assert_complete_results(
format!("delete from {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("coos".into(), CompletionItemKind::Table),
],
vec![CompletionAssertion::LabelAndKind(
"coos".into(),
CompletionItemKind::Table,
)],
None,
&pool,
)
Expand Down Expand Up @@ -418,8 +418,13 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind(
"information_schema".into(),
CompletionItemKind::Schema,
),
CompletionAssertion::LabelAndKind("pg_catalog".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("pg_toast".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
],
Expand Down Expand Up @@ -454,7 +459,6 @@ mod tests {
assert_complete_results(
format!("alter table {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
Expand All @@ -471,7 +475,6 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
Expand All @@ -484,7 +487,6 @@ mod tests {
assert_complete_results(
format!("drop table {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
Expand All @@ -501,7 +503,6 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
Expand Down Expand Up @@ -529,7 +530,6 @@ mod tests {
assert_complete_results(
format!("insert into {}", QueryWithCursorPosition::cursor_marker()).as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
],
Expand Down Expand Up @@ -561,7 +561,6 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
],
Expand Down Expand Up @@ -686,8 +685,14 @@ mod tests {
)
.as_str(),
vec![
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind(
"information_schema".into(),
CompletionItemKind::Schema,
),
CompletionAssertion::LabelAndKind("pg_catalog".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("pg_toast".into(), CompletionItemKind::Schema),
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
],
None,
&pool,
Expand Down
42 changes: 29 additions & 13 deletions crates/pgls_completions/src/relevance/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl CompletionFilter<'_> {
return None;
}

if ctx.before_cursor_matches_kind(&["ERROR"]) {
return None;
}

// "literal" nodes can be identfiers wrapped in quotes:
// `select "email" from auth.users;`
// Here, "email" is a literal node.
Expand Down Expand Up @@ -111,7 +115,8 @@ impl CompletionFilter<'_> {
"column_reference_1of1",
"column_reference_2of2",
"column_reference_3of3",
]) && !ctx.node_under_cursor_is_within_field(&["binary_expr_right"])
]) && (!ctx.node_under_cursor_is_within_field(&["binary_expr_right"])
|| ctx.has_any_qualifier())
}

CompletionRelevanceData::Schema(_) => ctx.node_under_cursor_is_within_field(&[
Expand All @@ -138,17 +143,23 @@ impl CompletionFilter<'_> {
]) && matches!(f.kind, ProcKind::Aggregate))
}

CompletionRelevanceData::Table(_) => ctx.node_under_cursor_is_within_field(&[
"object_reference_1of1",
"object_reference_1of2",
"object_reference_2of2",
"object_reference_2of3",
"table_reference_1of1",
"column_reference_1of1",
"column_reference_1of2",
"column_reference_2of2",
]),

CompletionRelevanceData::Table(_) => {
ctx.node_under_cursor_is_within_field(&[
"object_reference_1of1",
"object_reference_1of2",
"object_reference_2of2",
"object_reference_2of3",
"table_reference_1of1",
"column_reference_1of1",
"column_reference_1of2",
"column_reference_2of2",
]) && !ctx.history_ends_with(&[
"update",
"assignment",
"column_reference",
"any_identifier",
])
}
_ => false,
},

Expand All @@ -164,7 +175,12 @@ impl CompletionFilter<'_> {
.map(|clause| {
match self.data {
CompletionRelevanceData::Table(_) => match clause {
WrappingClause::From | WrappingClause::Update => true,
WrappingClause::From => true,

WrappingClause::Update => ctx
.wrapping_node_kind
.as_ref()
.is_none_or(|n| n != &WrappingNode::Assignment),

WrappingClause::RevokeStatement | WrappingClause::GrantStatement => ctx
.history_ends_with(&[
Expand Down
Loading