Skip to content

Commit 9c07d91

Browse files
accept snaps
1 parent 324c4f5 commit 9c07d91

File tree

5 files changed

+51
-41
lines changed

5 files changed

+51
-41
lines changed

crates/pgls_completions/src/providers/columns.rs

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

544-
TestCompletionsSuite::new(&pool, Some(setup))
545-
.with_case(
546-
TestCompletionsCase::new().type_sql(r#"select "email" from "private"."users";"#),
547-
)
548-
.snapshot("completes_quoted_columns")
549-
.await;
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";"#),
554+
// )
555+
// .snapshot("completes_quoted_columns")
556+
// .await;
550557
}
551558

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

crates/pgls_completions/src/relevance/filtering.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ impl CompletionFilter<'_> {
4545
return None;
4646
}
4747

48-
// if ctx
49-
// .get_node_under_cursor_content()
50-
// .is_some_and(|c| is_sanitized_token(c.as_str()))
51-
// && ctx.before_cursor_matches_kind(&["ERROR"])
52-
// {
53-
// return None;
54-
// }
48+
if ctx
49+
.get_node_under_cursor_content()
50+
.is_some_and(|c| is_sanitized_token(c.as_str()))
51+
&& ctx.before_cursor_matches_kind(&["ERROR"])
52+
{
53+
return None;
54+
}
5555

5656
// "literal" nodes can be identfiers wrapped in quotes:
5757
// `select "email" from auth.users;`

crates/pgls_completions/src/relevance/scoring.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ impl CompletionScore<'_> {
9292
}
9393
}
9494

95-
// no qualifier whatsoever, we'll check the full qualified name of the item.
96-
_ => self.get_fully_qualified_name(),
95+
_ => match self.data {
96+
// for columns and functions, we fuzzy match with a possible alias.
97+
CompletionRelevanceData::Column(_) | CompletionRelevanceData::Policy(_) => self
98+
.get_table_name()
99+
.and_then(|tbl| ctx.get_used_alias_for_table(tbl))
100+
.map(|t| format!("{}.{}", t, name))
101+
.unwrap_or(name.clone()),
102+
103+
// everything else is just fuzzy matched against its name.
104+
_ => name.clone(),
105+
},
97106
};
98107

99108
match fz_matcher.fuzzy_match(

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap

Lines changed: 6 additions & 12 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)
5758
name - private.users.name (Column)
5859
quoted_column - private.users.quoted_column (Column)
59-
id - private.users.id (Column)
60-
elem_count_histogram - pg_catalog.pg_stats.elem_count_histogram (Column)
60+
apply_error_count - pg_catalog.pg_stat_subscription_stats.apply_error_count (Column)
6161

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

@@ -91,8 +91,8 @@ Results:
9191
public - public (Schema)
9292
private - private (Schema)
9393
private"."users - private.users (Table)
94-
information_schema"."_pg_foreign_data_wrappers - information_schema._pg_foreign_data_wrappers (Table)
95-
information_schema"."_pg_foreign_servers - information_schema._pg_foreign_servers (Table)
94+
information_schema - information_schema (Schema)
95+
pg_catalog - pg_catalog (Schema)
9696

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

@@ -102,8 +102,8 @@ Results:
102102
public - public (Schema)
103103
private - private (Schema)
104104
private"."users - private.users (Table)
105-
information_schema"."parameters - information_schema.parameters (Table)
106-
pg_catalog"."pg_aggregate - pg_catalog.pg_aggregate (Table)
105+
pg_catalog - pg_catalog (Schema)
106+
pg_toast - pg_toast (Schema)
107107

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

@@ -115,10 +115,4 @@ users - private.users (Table)
115115
--------------
116116

117117
select "email" from "private".u|
118-
119-
Results:
120-
users - private.users (Table)
121-
122-
--------------
123-
124118
select "email" from "private".users; |

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ name - private.users.name (Column)
6060
select "p|"
6161

6262
Results:
63-
name - public.names.name (Column)
64-
uid - public.names.uid (Column)
65-
email - private.users.email (Column)
66-
id - private.users.id (Column)
67-
name - private.users.name (Column)
63+
pad_attribute - information_schema.collations.pad_attribute (Column)
64+
page - pg_catalog.pg_locks.page (Column)
65+
pageno - pg_catalog.pg_largeobject.pageno (Column)
66+
paracl - pg_catalog.pg_parameter_acl.paracl (Column)
67+
parameter_default - information_schema.parameters.parameter_default (Column)
6868

6969
--------------
7070

@@ -90,9 +90,9 @@ select "pr"."email" from p|
9090
Results:
9191
public - public (Schema)
9292
private - private (Schema)
93-
names - public.names (Table)
94-
private.users - private.users (Table)
95-
pg_catalog - pg_catalog (Schema)
93+
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

@@ -159,10 +159,10 @@ select "e|" from private.users "pr"
159159

160160
Results:
161161
pr"."email - private.users.email (Column)
162-
pr"."id - private.users.id (Column)
163162
pr"."name - private.users.name (Column)
164163
pr"."quoted_column - private.users.quoted_column (Column)
165164
name - public.names.name (Column)
165+
elem_count_histogram - pg_catalog.pg_stats.elem_count_histogram (Column)
166166

167167
--------------
168168

@@ -192,7 +192,7 @@ Results:
192192
"pr".id - private.users.id (Column)
193193
"pr".name - private.users.name (Column)
194194
"pr".quoted_column - private.users.quoted_column (Column)
195-
name - public.names.name (Column)
195+
pad_attribute - information_schema.collations.pad_attribute (Column)
196196

197197
--------------
198198

@@ -283,7 +283,7 @@ pr"."email - private.users.email (Column)
283283
pr"."id - private.users.id (Column)
284284
pr"."name - private.users.name (Column)
285285
pr"."quoted_column - private.users.quoted_column (Column)
286-
name - public.names.name (Column)
286+
pad_attribute - information_schema.collations.pad_attribute (Column)
287287

288288
--------------
289289

@@ -352,7 +352,7 @@ Results:
352352
"pr".id - private.users.id (Column)
353353
"pr".name - private.users.name (Column)
354354
"pr".quoted_column - private.users.quoted_column (Column)
355-
name - public.names.name (Column)
355+
pad_attribute - information_schema.collations.pad_attribute (Column)
356356

357357
--------------
358358

@@ -420,11 +420,11 @@ pr"."name - private.users.name (Column)
420420
select "p|" from private.users "pr" join public.names n on pr.id = n.uid;
421421

422422
Results:
423-
n"."name - public.names.name (Column)
424-
n"."uid - public.names.uid (Column)
425423
pr"."email - private.users.email (Column)
426424
pr"."id - private.users.id (Column)
427425
pr"."name - private.users.name (Column)
426+
pr"."quoted_column - private.users.quoted_column (Column)
427+
pad_attribute - information_schema.collations.pad_attribute (Column)
428428

429429
--------------
430430

0 commit comments

Comments
 (0)