Skip to content

Commit 4cf53b4

Browse files
many changes
1 parent f55386a commit 4cf53b4

9 files changed

+37
-146
lines changed

crates/pgls_completions/src/providers/columns.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,6 @@ mod tests {
459459
"#;
460460

461461
TestCompletionsSuite::new(&pool, Some(setup))
462-
.with_case(
463-
TestCompletionsCase::new().type_sql("alter table instruments drop column name"),
464-
)
465462
.with_case(
466463
TestCompletionsCase::new().type_sql("alter table instruments drop column name"),
467464
)

crates/pgls_completions/src/relevance/filtering.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ 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-
{
48+
if ctx.before_cursor_matches_kind(&["ERROR"]) {
5349
return None;
5450
}
5551

crates/pgls_completions/src/relevance/scoring.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,21 @@ impl CompletionScore<'_> {
142142
},
143143
};
144144

145-
match fz_matcher.fuzzy_match(
146-
check_against.to_ascii_lowercase().as_str(),
147-
content.to_ascii_lowercase().as_str(),
148-
) {
145+
let content_lower = content.to_ascii_lowercase();
146+
let check_against_lower = check_against.to_ascii_lowercase();
147+
148+
match fz_matcher.fuzzy_match(check_against_lower.as_str(), content_lower.as_str()) {
149149
Some(score) => {
150-
let scorei32: i32 = score
150+
let mut scorei32: i32 = score
151151
.try_into()
152152
.expect("The length of the input exceeds i32 capacity");
153153

154+
// give a significant bonus for prefix matches since these are much more
155+
// likely what the user is looking for
156+
if check_against_lower.starts_with(&content_lower) {
157+
scorei32 += 20;
158+
}
159+
154160
// the scoring value isn't linear.
155161
// here are a couple of samples:
156162
// - item: bytea_string_agg_transfn, input: n, score: 15

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap

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

7070
Results:
7171
auth - auth (Schema)
72-
information_schema - information_schema (Schema)
73-
pg_catalog - pg_catalog (Schema)
74-
pg_toast - pg_toast (Schema)
7572
information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table)
73+
information_schema.applicable_roles - information_schema.applicable_roles (Table)
74+
information_schema.attributes - information_schema.attributes (Table)
75+
information_schema - information_schema (Schema)
7676

7777
--------------
7878

@@ -111,10 +111,10 @@ select u.uid, p.content from auth.users u join a|
111111

112112
Results:
113113
auth - auth (Schema)
114-
information_schema - information_schema (Schema)
115-
pg_catalog - pg_catalog (Schema)
116-
pg_toast - pg_toast (Schema)
117114
information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table)
115+
information_schema.applicable_roles - information_schema.applicable_roles (Table)
116+
information_schema.attributes - information_schema.attributes (Table)
117+
information_schema - information_schema (Schema)
118118

119119
--------------
120120

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ o.a - public.one.a (Column)
135135
select o.id, a, b, c, d| from public.one o join public.two on o.id = t.id;
136136

137137
Results:
138-
id - public.two.id (Column)
139138
d - public.two.d (Column)
140-
o.id - public.one.id (Column)
139+
id - public.two.id (Column)
141140
data - pg_catalog.pg_largeobject.data (Column)
142141
data_type - pg_catalog.pg_sequences.data_type (Column)
142+
database - pg_catalog.pg_hba_file_rules.database (Column)
143143

144144
--------------
145145

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap

Lines changed: 11 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ alter table i|
3434

3535
Results:
3636
instruments - public.instruments (Table)
37-
public - public (Schema)
3837
information_schema - information_schema (Schema)
3938
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
39+
public - public (Schema)
4040
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
4141

4242
--------------
@@ -112,87 +112,9 @@ alter table i|
112112

113113
Results:
114114
instruments - public.instruments (Table)
115-
public - public (Schema)
116115
information_schema - information_schema (Schema)
117116
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
118-
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
119-
120-
--------------
121-
122-
alter table instruments |
123-
alter table instruments d|
124-
alter table instruments drop |
125-
126-
Results:
127-
created_at - public.instruments.created_at (Column)
128-
id - public.instruments.id (Column)
129-
name - public.instruments.name (Column)
130-
z - public.instruments.z (Column)
131-
abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column)
132-
133-
--------------
134-
135-
alter table instruments drop c|
136-
137-
Results:
138-
created_at - public.instruments.created_at (Column)
139-
cache_size - pg_catalog.pg_sequences.cache_size (Column)
140-
calls - pg_catalog.pg_stat_user_functions.calls (Column)
141-
castcontext - pg_catalog.pg_cast.castcontext (Column)
142-
castfunc - pg_catalog.pg_cast.castfunc (Column)
143-
144-
--------------
145-
146-
alter table instruments drop column |
147-
148-
Results:
149-
created_at - public.instruments.created_at (Column)
150-
id - public.instruments.id (Column)
151-
name - public.instruments.name (Column)
152-
z - public.instruments.z (Column)
153-
abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column)
154-
155-
--------------
156-
157-
alter table instruments drop column n|
158-
159-
Results:
160-
name - public.instruments.name (Column)
161-
n_dead_tup - pg_catalog.pg_stat_all_tables.n_dead_tup (Column)
162-
n_distinct - pg_catalog.pg_stats.n_distinct (Column)
163-
n_ins_since_vacuum - pg_catalog.pg_stat_all_tables.n_ins_since_vacuum (Column)
164-
n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column)
165-
166-
--------------
167-
168-
alter table instruments drop column name |
169-
170-
171-
172-
173-
***Case 3:***
174-
175-
a|
176-
alter |
177-
alter t|
178-
alter table |
179-
180-
Results:
181-
instruments - public.instruments (Table)
182-
_sqlx_migrations - public._sqlx_migrations (Table)
183-
information_schema - information_schema (Schema)
184-
pg_catalog - pg_catalog (Schema)
185-
pg_toast - pg_toast (Schema)
186-
187-
--------------
188-
189-
alter table i|
190-
191-
Results:
192-
instruments - public.instruments (Table)
193117
public - public (Schema)
194-
information_schema - information_schema (Schema)
195-
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
196118
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
197119

198120
--------------
@@ -245,16 +167,6 @@ identity_increment - information_schema.columns.identity_increment (Column)
245167

246168
alter table instruments drop column if |
247169
alter table instruments drop column if e|
248-
249-
Results:
250-
created_at - public.instruments.created_at (Column)
251-
name - public.instruments.name (Column)
252-
elem_count_histogram - pg_catalog.pg_stats.elem_count_histogram (Column)
253-
encoding - pg_catalog.pg_database.encoding (Column)
254-
encrypted - pg_catalog.pg_stat_gssapi.encrypted (Column)
255-
256-
--------------
257-
258170
alter table instruments drop column if exists |
259171

260172
Results:
@@ -282,7 +194,7 @@ alter table instruments drop column if exists name |
282194

283195

284196

285-
***Case 4:***
197+
***Case 3:***
286198

287199
a|
288200
alter |
@@ -302,9 +214,9 @@ alter table i|
302214

303215
Results:
304216
instruments - public.instruments (Table)
305-
public - public (Schema)
306217
information_schema - information_schema (Schema)
307218
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
219+
public - public (Schema)
308220
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
309221

310222
--------------
@@ -374,7 +286,7 @@ instruments - public.instruments (Table)
374286

375287

376288

377-
***Case 5:***
289+
***Case 4:***
378290

379291
a|
380292
alter |
@@ -394,9 +306,9 @@ alter table i|
394306

395307
Results:
396308
instruments - public.instruments (Table)
397-
public - public (Schema)
398309
information_schema - information_schema (Schema)
399310
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
311+
public - public (Schema)
400312
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
401313

402314
--------------
@@ -444,7 +356,7 @@ instruments - public.instruments (Table)
444356

445357

446358

447-
***Case 6:***
359+
***Case 5:***
448360

449361
a|
450362
alter |
@@ -538,7 +450,7 @@ alter table public.instruments alter column name |
538450

539451

540452

541-
***Case 7:***
453+
***Case 6:***
542454

543455
a|
544456
alter |
@@ -558,9 +470,9 @@ alter table i|
558470

559471
Results:
560472
instruments - public.instruments (Table)
561-
public - public (Schema)
562473
information_schema - information_schema (Schema)
563474
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
475+
public - public (Schema)
564476
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
565477

566478
--------------
@@ -594,7 +506,7 @@ alter table instruments alter name |
594506

595507

596508

597-
***Case 8:***
509+
***Case 7:***
598510

599511
a|
600512
alter |
@@ -614,9 +526,9 @@ alter table i|
614526

615527
Results:
616528
instruments - public.instruments (Table)
617-
public - public (Schema)
618529
information_schema - information_schema (Schema)
619530
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
531+
public - public (Schema)
620532
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
621533

622534
--------------
@@ -654,7 +566,7 @@ alter table instruments rename name to new_col |
654566

655567

656568

657-
***Case 9:***
569+
***Case 8:***
658570

659571
a|
660572
alter |

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ insert into i|
3939

4040
Results:
4141
instruments - public.instruments (Table)
42-
public - public (Schema)
4342
information_schema - information_schema (Schema)
4443
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
44+
public - public (Schema)
4545
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
4646

4747
--------------
@@ -145,9 +145,9 @@ insert into i|
145145

146146
Results:
147147
instruments - public.instruments (Table)
148-
public - public (Schema)
149148
information_schema - information_schema (Schema)
150149
information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table)
150+
public - public (Schema)
151151
pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table)
152152

153153
--------------

crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ create table others (
2222

2323
select name from instruments i join others o on i.z = o.a |
2424
select name from instruments i join others o on i.z = o.a w|
25-
26-
Results:
27-
wait_event - pg_catalog.pg_stat_activity.wait_event (Column)
28-
wait_event_type - pg_catalog.pg_stat_activity.wait_event_type (Column)
29-
waitstart - pg_catalog.pg_locks.waitstart (Column)
30-
wal_buffers_full - pg_catalog.pg_stat_wal.wal_buffers_full (Column)
31-
wal_bytes - pg_catalog.pg_stat_wal.wal_bytes (Column)
32-
33-
--------------
34-
3525
select name from instruments i join others o on i.z = o.a where |
3626

3727
Results:
@@ -69,16 +59,6 @@ pg_catalog - pg_catalog (Schema)
6959
select name from instruments i join others o on i.z = o.a where o.a = i.|
7060
select name from instruments i join others o on i.z = o.a where o.a = i.z |
7161
select name from instruments i join others o on i.z = o.a where o.a = i.z a|
72-
73-
Results:
74-
information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table)
75-
information_schema.applicable_roles - information_schema.applicable_roles (Table)
76-
information_schema.attributes - information_schema.attributes (Table)
77-
information_schema.collation_character_set_applicability - information_schema.collation_character_set_applicability (Table)
78-
pg_catalog.pg_aggregate - pg_catalog.pg_aggregate (Table)
79-
80-
--------------
81-
8262
select name from instruments i join others o on i.z = o.a where o.a = i.z and |
8363
**should prioritize columns that aren't already mentioned**
8464

todo.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap
88
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_select.snap
99
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__handles_nested_queries.snap
10-
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap
11-
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_columns_of_mentioned_tables.snap
12-
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap
13-
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap
10+
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap
11+
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_columns_of_mentioned_tables.snap
12+
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap
13+
- [x] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap
1414
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap
1515
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap
1616
- [ ] crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap

0 commit comments

Comments
 (0)