Skip to content

Commit 359a8ff

Browse files
ok?
1 parent 9c07d91 commit 359a8ff

18 files changed

+231
-308
lines changed

crates/pgls_completions/src/providers/columns.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -541,19 +541,23 @@ mod tests {
541541
);
542542
"#;
543543

544-
assert_no_complete_results(
545-
format!(r#"select "e{}""#, QueryWithCursorPosition::cursor_marker()).as_str(),
546-
Some(setup),
547-
&pool,
548-
)
549-
.await;
550-
551-
// TestCompletionsSuite::new(&pool, Some(setup))
552-
// .with_case(
553-
// TestCompletionsCase::new().type_sql(r#"select "email" from "private"."users";"#),
544+
// assert_no_complete_results(
545+
// format!(
546+
// r#"select "email" from "p{}""#,
547+
// QueryWithCursorPosition::cursor_marker()
554548
// )
555-
// .snapshot("completes_quoted_columns")
556-
// .await;
549+
// .as_str(),
550+
// Some(setup),
551+
// &pool,
552+
// )
553+
// .await;
554+
555+
TestCompletionsSuite::new(&pool, Some(setup))
556+
.with_case(
557+
TestCompletionsCase::new().type_sql(r#"select "email" from "private"."users";"#),
558+
)
559+
.snapshot("completes_quoted_columns")
560+
.await;
557561
}
558562

559563
#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]

crates/pgls_completions/src/relevance/scoring.rs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,52 @@ impl CompletionScore<'_> {
3333
}
3434

3535
pub fn calc_score(&mut self, ctx: &TreesitterContext) {
36+
let case = (matches!(self.data, CompletionRelevanceData::Schema(_))
37+
&& self.get_schema_name().is_some_and(|s| s == "pg_catalog"))
38+
|| (matches!(self.data, CompletionRelevanceData::Table(_))
39+
&& self.get_table_name().is_some_and(|s| s == "parameters"));
40+
41+
if case {
42+
println!("checking {}", self.get_fully_qualified_name())
43+
}
44+
3645
self.check_is_user_defined();
46+
if case {
47+
println!("{} after user-defined check", self.score);
48+
}
49+
3750
self.check_matches_schema(ctx);
51+
if case {
52+
println!("{} after schema match check", self.score);
53+
}
3854
self.check_matches_query_input(ctx);
55+
if case {
56+
println!("{} after query input match check", self.score);
57+
}
3958
self.check_is_invocation(ctx);
59+
if case {
60+
println!("{} after invocation check", self.score);
61+
}
4062
self.check_matching_clause_type(ctx);
63+
if case {
64+
println!("{} after clause type check", self.score);
65+
}
4166
self.check_matching_wrapping_node(ctx);
67+
if case {
68+
println!("{} after wrapping node check", self.score);
69+
}
4270
self.check_relations_in_stmt(ctx);
71+
if case {
72+
println!("{} after relations in stmt check", self.score);
73+
}
4374
self.check_columns_in_stmt(ctx);
75+
if case {
76+
println!("{} after columns in stmt check", self.score);
77+
}
4478
self.check_is_not_wellknown_migration(ctx);
79+
if case {
80+
println!("{} after well-known migration check", self.score);
81+
}
4582
}
4683

4784
fn check_matches_query_input(&mut self, ctx: &TreesitterContext) {
@@ -125,6 +162,21 @@ impl CompletionScore<'_> {
125162
} else {
126163
scorei32 / 3
127164
};
165+
166+
if matches!(self.data, CompletionRelevanceData::Schema(_))
167+
&& self.get_schema_name().is_some_and(|s| s == "pg_catalog")
168+
{
169+
println!("Debug: Schema pg_catalog match score {}", self.score);
170+
}
171+
172+
if matches!(self.data, CompletionRelevanceData::Table(_))
173+
&& self.get_table_name().is_some_and(|s| s == "parameters")
174+
{
175+
println!(
176+
"Debug: Table information_schema.parameters match score {}",
177+
self.score
178+
);
179+
}
128180
}
129181
None => self.skip = true,
130182
}
@@ -202,9 +254,6 @@ impl CompletionScore<'_> {
202254
};
203255

204256
let has_qualifier = ctx.has_any_qualifier();
205-
let has_node_text = ctx
206-
.get_node_under_cursor_content()
207-
.is_some_and(|txt| !sanitization::is_sanitized_token(txt.as_str()));
208257

209258
self.score += match self.data {
210259
CompletionRelevanceData::Table(_) => match wrapping_node {
@@ -224,8 +273,7 @@ impl CompletionScore<'_> {
224273
_ => -15,
225274
},
226275
CompletionRelevanceData::Schema(_) => match wrapping_node {
227-
WrappingNode::Relation if !has_qualifier && !has_node_text => 15,
228-
WrappingNode::Relation if !has_qualifier && has_node_text => 0,
276+
WrappingNode::Relation if !has_qualifier => 15,
229277
_ => -50,
230278
},
231279
CompletionRelevanceData::Policy(_) => 0,

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ select "e|"
5454

5555
Results:
5656
email - private.users.email (Column)
57-
id - private.users.id (Column)
5857
name - private.users.name (Column)
5958
quoted_column - private.users.quoted_column (Column)
60-
apply_error_count - pg_catalog.pg_stat_subscription_stats.apply_error_count (Column)
59+
elem_count_histogram - pg_catalog.pg_stats.elem_count_histogram (Column)
60+
encoding - pg_catalog.pg_database.encoding (Column)
6161

6262
--------------
6363

@@ -101,9 +101,9 @@ select "email" from "p|"
101101
Results:
102102
public - public (Schema)
103103
private - private (Schema)
104-
private"."users - private.users (Table)
105104
pg_catalog - pg_catalog (Schema)
106105
pg_toast - pg_toast (Schema)
106+
information_schema"."parameters - information_schema.parameters (Table)
107107

108108
--------------
109109

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ select "pr"."email" from p|
9090
Results:
9191
public - public (Schema)
9292
private - private (Schema)
93+
pg_catalog - pg_catalog (Schema)
94+
pg_toast - pg_toast (Schema)
9395
information_schema.parameters - information_schema.parameters (Table)
94-
pg_catalog.pg_aggregate - pg_catalog.pg_aggregate (Table)
95-
pg_catalog.pg_am - pg_catalog.pg_am (Table)
9696

9797
--------------
9898

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ select u.uid, p.content from a|
6969

7070
Results:
7171
auth - auth (Schema)
72-
public - public (Schema)
73-
auth.posts - auth.posts (Table)
74-
auth.users - auth.users (Table)
72+
information_schema - information_schema (Schema)
73+
pg_catalog - pg_catalog (Schema)
74+
pg_toast - pg_toast (Schema)
7575
information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table)
7676

7777
--------------
@@ -90,7 +90,6 @@ select u.uid, p.content from auth.u|
9090

9191
Results:
9292
users - auth.users (Table)
93-
posts - auth.posts (Table)
9493

9594
--------------
9695

@@ -112,9 +111,9 @@ select u.uid, p.content from auth.users u join a|
112111

113112
Results:
114113
auth - auth (Schema)
115-
public - public (Schema)
116-
auth.posts - auth.posts (Table)
117-
auth.users - auth.users (Table)
114+
information_schema - information_schema (Schema)
115+
pg_catalog - pg_catalog (Schema)
116+
pg_toast - pg_toast (Schema)
118117
information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table)
119118

120119
--------------
@@ -131,7 +130,6 @@ select u.uid, p.content from auth.users u join auth.p|
131130

132131
Results:
133132
posts - auth.posts (Table)
134-
users - auth.users (Table)
135133

136134
--------------
137135

@@ -162,22 +160,10 @@ select u.uid, p.content from auth.users u join auth.posts p on u.u|
162160

163161
Results:
164162
uid - auth.users.uid (Column)
165-
email - auth.users.email (Column)
166-
name - auth.users.name (Column)
167163

168164
--------------
169165

170166
select u.uid, p.content from auth.users u join auth.posts p on u.uid |
171-
172-
Results:
173-
p.pid - auth.posts.pid (Column)
174-
u.uid - auth.users.uid (Column)
175-
p.content - auth.posts.content (Column)
176-
p.created_at - auth.posts.created_at (Column)
177-
u.email - auth.users.email (Column)
178-
179-
--------------
180-
181167
select u.uid, p.content from auth.users u join auth.posts p on u.uid = |
182168

183169
Results:
@@ -204,20 +190,7 @@ select u.uid, p.content from auth.users u join auth.posts p on u.uid = p.u|
204190

205191
Results:
206192
user_id - auth.posts.user_id (Column)
207-
pid - auth.posts.pid (Column)
208-
content - auth.posts.content (Column)
209-
created_at - auth.posts.created_at (Column)
210-
title - auth.posts.title (Column)
211193

212194
--------------
213195

214196
select u.uid, p.content from auth.users u join auth.posts p on u.uid = p.user_id |
215-
216-
Results:
217-
p.pid - auth.posts.pid (Column)
218-
u.uid - auth.users.uid (Column)
219-
p.content - auth.posts.content (Column)
220-
p.created_at - auth.posts.created_at (Column)
221-
u.email - auth.users.email (Column)
222-
223-
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,10 @@ select u.id, p.content from auth.users u join auth.posts p on u.i|
5151
Results:
5252
uid - auth.users.uid (Column)
5353
email - auth.users.email (Column)
54-
name - auth.users.name (Column)
5554

5655
--------------
5756

5857
select u.id, p.content from auth.users u join auth.posts p on u.id |
59-
60-
Results:
61-
p.pid - auth.posts.pid (Column)
62-
u.uid - auth.users.uid (Column)
63-
p.content - auth.posts.content (Column)
64-
p.created_at - auth.posts.created_at (Column)
65-
u.email - auth.users.email (Column)
66-
67-
--------------
68-
6958
select u.id, p.content from auth.users u join auth.posts p on u.id = |
7059

7160
Results:
@@ -93,20 +82,7 @@ select u.id, p.content from auth.users u join auth.posts p on u.id = p.u|
9382

9483
Results:
9584
user_id - auth.posts.user_id (Column)
96-
pid - auth.posts.pid (Column)
97-
content - auth.posts.content (Column)
98-
created_at - auth.posts.created_at (Column)
99-
title - auth.posts.title (Column)
10085

10186
--------------
10287

10388
select u.id, p.content from auth.users u join auth.posts p on u.id = p.user_id |
104-
105-
Results:
106-
p.pid - auth.posts.pid (Column)
107-
u.uid - auth.users.uid (Column)
108-
p.content - auth.posts.content (Column)
109-
p.created_at - auth.posts.created_at (Column)
110-
u.email - auth.users.email (Column)
111-
112-
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_select.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ select u.i| from auth.users u join auth.posts p on u.id = p.user_id;
4949
Results:
5050
email - auth.users.email (Column)
5151
uid - auth.users.uid (Column)
52-
name - auth.users.name (Column)
5352

5453
--------------
5554

@@ -81,10 +80,6 @@ select u.id, p.p| from auth.users u join auth.posts p on u.id = p.user_id;
8180

8281
Results:
8382
pid - auth.posts.pid (Column)
84-
content - auth.posts.content (Column)
85-
created_at - auth.posts.created_at (Column)
86-
title - auth.posts.title (Column)
87-
user_id - auth.posts.user_id (Column)
8883

8984
--------------
9085

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__handles_nested_queries.snap

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,11 @@ select * from (
2929
) as subquery
3030
join public.users u
3131
on u.id = subquery.id;
32-
33-
Results:
34-
audio_books - public.audio_books (Table)
35-
users - public.users (Table)
36-
private.audio_books - private.audio_books (Table)
37-
information_schema._pg_foreign_data_wrappers - information_schema._pg_foreign_data_wrappers (Table)
38-
information_schema._pg_foreign_servers - information_schema._pg_foreign_servers (Table)
39-
40-
--------------
41-
4232
select * from (
4333
s|
4434
) as subquery
4535
join public.users u
4636
on u.id = subquery.id;
47-
48-
Results:
49-
audio_books - public.audio_books (Table)
50-
users - public.users (Table)
51-
private.audio_books - private.audio_books (Table)
52-
information_schema._pg_foreign_data_wrappers - information_schema._pg_foreign_data_wrappers (Table)
53-
information_schema._pg_foreign_servers - information_schema._pg_foreign_servers (Table)
54-
55-
--------------
56-
5737
select * from (
5838
select |
5939
) as subquery
@@ -150,9 +130,9 @@ on u.id = subquery.id;
150130
Results:
151131
public - public (Schema)
152132
private - private (Schema)
153-
audio_books - public.audio_books (Table)
154-
users - public.users (Table)
155-
private.audio_books - private.audio_books (Table)
133+
pg_catalog - pg_catalog (Schema)
134+
pg_toast - pg_toast (Schema)
135+
information_schema.parameters - information_schema.parameters (Table)
156136

157137
--------------
158138

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ select * from p|
3535
Results:
3636
public - public (Schema)
3737
private - private (Schema)
38-
private.users - private.users (Table)
38+
pg_catalog - pg_catalog (Schema)
39+
pg_toast - pg_toast (Schema)
3940
information_schema.parameters - information_schema.parameters (Table)
40-
pg_catalog.pg_aggregate - pg_catalog.pg_aggregate (Table)
4141

4242
--------------
4343

0 commit comments

Comments
 (0)