Skip to content

Commit f6bd86c

Browse files
fix: many completion issues from snapshots (#607)
1 parent ec847a4 commit f6bd86c

File tree

30 files changed

+572
-724
lines changed

30 files changed

+572
-724
lines changed

.github/workflows/pull_request.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ jobs:
118118
path: |
119119
~/.cargo/bin/tree-sitter
120120
~/.cargo/bin/sqlx
121+
~/.cargo/bin/cargo-sqlx
121122
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
122123

123124
- name: Setup tree-sitter
124-
run: cargo install tree-sitter-cli
125+
run: command -v tree-sitter || cargo install tree-sitter-cli
125126

126127
- name: Setup sqlx-cli
127-
run: cargo install sqlx-cli
128+
run: command -v sqlx ||cargo install sqlx-cli
128129

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

188189
- name: Setup Postgres
189-
run: cargo install tree-sitter-cli
190+
run: command -v tree-sitter || cargo install tree-sitter-cli
190191

191192
- name: Run tests
192193
run: cargo test --workspace
@@ -222,24 +223,14 @@ jobs:
222223
~/.cargo/bin/tree-sitter
223224
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
224225
- name: setup tree-sitter
225-
run: cargo install tree-sitter-cli
226+
run: command -v tree-sitter || cargo install tree-sitter-cli
226227
- name: Build main binary
227228
run: cargo build -p pgls_cli --release
228229
- name: Setup Bun
229230
uses: oven-sh/setup-bun@v2
230231
- name: Install JS dependencies
231232
run: bun install
232233

233-
- name: Build backend-jsonrpc (deprecated)
234-
working-directory: packages/@postgrestools/backend-jsonrpc
235-
run: bun run build
236-
- name: Run backend-jsonrpc test (deprecated)
237-
working-directory: packages/@postgrestools/backend-jsonrpc
238-
run: bun run test
239-
- name: Run cli test (deprecated)
240-
working-directory: packages/@postgrestools/postgrestools
241-
run: bun run test
242-
243234
- name: Build backend-jsonrpc
244235
working-directory: packages/@postgres-language-server/backend-jsonrpc
245236
run: bun run build
@@ -281,7 +272,7 @@ jobs:
281272
~/.cargo/bin/tree-sitter
282273
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
283274
- name: setup tree-sitter
284-
run: cargo install tree-sitter-cli
275+
run: command -v tree-sitter || cargo install tree-sitter-cli
285276
- name: Ensure RustFMT on nightly toolchain
286277
run: rustup component add rustfmt --toolchain nightly
287278
- name: echo toolchain

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
8080

8181
- name: Setup tree-sitter
82-
run: cargo install tree-sitter-cli
82+
run: command -v tree-sitter || cargo install tree-sitter-cli
8383

8484
- name: Setup Postgres
8585
uses: ./.github/actions/setup-postgres

crates/pgls_completions/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ impl<'a> CompletionBuilder<'a> {
4242
item.score.calc_score(self.ctx);
4343
}
4444

45+
items.retain(|i| !i.score.should_skip());
46+
4547
items.sort_by(|a, b| {
4648
b.score
4749
.get_score()

crates/pgls_completions/src/providers/columns.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ mod tests {
7979
TestCompletionsCase::new()
8080
.inside_static_statement(r#"
8181
select * from (
82-
<sql>
82+
<sql> from private.audio_books
8383
) as subquery
8484
join public.users u
8585
on u.id = subquery.id;
8686
"#)
87-
.type_sql("select id, narrator_id<1> from private.audio_books")
87+
.type_sql("select id, narrator_id<1>")
8888
.comment("Should prefer the one from private.audio_audiobooks, since the other tables are out of scope.")
8989
)
9090
.snapshot("handles_nested_queries")
@@ -439,9 +439,9 @@ mod tests {
439439
"select name from instruments i join others o on i.z = o.a <sql>",
440440
)
441441
.type_sql("where o.<1>a = <2>i.z and <3>i.id > 5;")
442-
.comment("should respect alias speciifcation")
443-
.comment("should not prioritize suggest columns or schemas (right side of binary expression)")
444-
.comment("should prioritize columns that aren't already mentioned")
442+
.comment("should respect alias speciifcation")
443+
.comment("should not prioritize suggest columns or schemas (right side of binary expression)")
444+
.comment("should prioritize columns that aren't already mentioned"),
445445
)
446446
.snapshot("suggests_columns_in_where_clause")
447447
.await;
@@ -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/providers/schemas.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ mod tests {
5959
assert_complete_results(
6060
format!("select * from {}", QueryWithCursorPosition::cursor_marker()).as_str(),
6161
vec![
62-
CompletionAssertion::LabelAndKind("public".to_string(), CompletionItemKind::Schema),
62+
// users table still preferred over schemas
63+
CompletionAssertion::LabelAndKind("users".to_string(), CompletionItemKind::Table),
6364
CompletionAssertion::LabelAndKind("auth".to_string(), CompletionItemKind::Schema),
6465
CompletionAssertion::LabelAndKind(
6566
"internal".to_string(),
@@ -69,8 +70,7 @@ mod tests {
6970
"private".to_string(),
7071
CompletionItemKind::Schema,
7172
),
72-
// users table still preferred over system schemas
73-
CompletionAssertion::LabelAndKind("users".to_string(), CompletionItemKind::Table),
73+
// system schemas have lowest preference
7474
CompletionAssertion::LabelAndKind(
7575
"information_schema".to_string(),
7676
CompletionItemKind::Schema,
@@ -110,8 +110,8 @@ mod tests {
110110
)
111111
.as_str(),
112112
vec![
113-
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
114113
CompletionAssertion::LabelAndKind("ultimate".into(), CompletionItemKind::Schema),
114+
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
115115
],
116116
Some(setup),
117117
&pool,

crates/pgls_completions/src/providers/tables.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ mod tests {
273273
assert_complete_results(
274274
format!("update {}", QueryWithCursorPosition::cursor_marker()).as_str(),
275275
vec![CompletionAssertion::LabelAndKind(
276-
"public".into(),
277-
CompletionItemKind::Schema,
276+
"coos".into(),
277+
CompletionItemKind::Table,
278278
)],
279279
None,
280280
&pool,
@@ -354,10 +354,10 @@ mod tests {
354354

355355
assert_complete_results(
356356
format!("delete from {}", QueryWithCursorPosition::cursor_marker()).as_str(),
357-
vec![
358-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
359-
CompletionAssertion::LabelAndKind("coos".into(), CompletionItemKind::Table),
360-
],
357+
vec![CompletionAssertion::LabelAndKind(
358+
"coos".into(),
359+
CompletionItemKind::Table,
360+
)],
361361
None,
362362
&pool,
363363
)
@@ -418,8 +418,13 @@ mod tests {
418418
)
419419
.as_str(),
420420
vec![
421-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
422421
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
422+
CompletionAssertion::LabelAndKind(
423+
"information_schema".into(),
424+
CompletionItemKind::Schema,
425+
),
426+
CompletionAssertion::LabelAndKind("pg_catalog".into(), CompletionItemKind::Schema),
427+
CompletionAssertion::LabelAndKind("pg_toast".into(), CompletionItemKind::Schema),
423428
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join
424429
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
425430
],
@@ -454,7 +459,6 @@ mod tests {
454459
assert_complete_results(
455460
format!("alter table {}", QueryWithCursorPosition::cursor_marker()).as_str(),
456461
vec![
457-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
458462
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
459463
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
460464
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
@@ -471,7 +475,6 @@ mod tests {
471475
)
472476
.as_str(),
473477
vec![
474-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
475478
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
476479
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
477480
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
@@ -484,7 +487,6 @@ mod tests {
484487
assert_complete_results(
485488
format!("drop table {}", QueryWithCursorPosition::cursor_marker()).as_str(),
486489
vec![
487-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
488490
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
489491
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table),
490492
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
@@ -501,7 +503,6 @@ mod tests {
501503
)
502504
.as_str(),
503505
vec![
504-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
505506
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
506507
CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join
507508
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
@@ -529,7 +530,6 @@ mod tests {
529530
assert_complete_results(
530531
format!("insert into {}", QueryWithCursorPosition::cursor_marker()).as_str(),
531532
vec![
532-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
533533
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
534534
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
535535
],
@@ -561,7 +561,6 @@ mod tests {
561561
)
562562
.as_str(),
563563
vec![
564-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
565564
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
566565
CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table),
567566
],
@@ -686,8 +685,14 @@ mod tests {
686685
)
687686
.as_str(),
688687
vec![
689-
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
690688
CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema),
689+
CompletionAssertion::LabelAndKind(
690+
"information_schema".into(),
691+
CompletionItemKind::Schema,
692+
),
693+
CompletionAssertion::LabelAndKind("pg_catalog".into(), CompletionItemKind::Schema),
694+
CompletionAssertion::LabelAndKind("pg_toast".into(), CompletionItemKind::Schema),
695+
CompletionAssertion::LabelAndKind("public".into(), CompletionItemKind::Schema),
691696
],
692697
None,
693698
&pool,

crates/pgls_completions/src/relevance/filtering.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl CompletionFilter<'_> {
4343
return None;
4444
}
4545

46+
if ctx.before_cursor_matches_kind(&["ERROR"]) {
47+
return None;
48+
}
49+
4650
// "literal" nodes can be identfiers wrapped in quotes:
4751
// `select "email" from auth.users;`
4852
// Here, "email" is a literal node.
@@ -111,7 +115,8 @@ impl CompletionFilter<'_> {
111115
"column_reference_1of1",
112116
"column_reference_2of2",
113117
"column_reference_3of3",
114-
]) && !ctx.node_under_cursor_is_within_field(&["binary_expr_right"])
118+
]) && (!ctx.node_under_cursor_is_within_field(&["binary_expr_right"])
119+
|| ctx.has_any_qualifier())
115120
}
116121

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

141-
CompletionRelevanceData::Table(_) => ctx.node_under_cursor_is_within_field(&[
142-
"object_reference_1of1",
143-
"object_reference_1of2",
144-
"object_reference_2of2",
145-
"object_reference_2of3",
146-
"table_reference_1of1",
147-
"column_reference_1of1",
148-
"column_reference_1of2",
149-
"column_reference_2of2",
150-
]),
151-
146+
CompletionRelevanceData::Table(_) => {
147+
ctx.node_under_cursor_is_within_field(&[
148+
"object_reference_1of1",
149+
"object_reference_1of2",
150+
"object_reference_2of2",
151+
"object_reference_2of3",
152+
"table_reference_1of1",
153+
"column_reference_1of1",
154+
"column_reference_1of2",
155+
"column_reference_2of2",
156+
]) && !ctx.history_ends_with(&[
157+
"update",
158+
"assignment",
159+
"column_reference",
160+
"any_identifier",
161+
])
162+
}
152163
_ => false,
153164
},
154165

@@ -164,7 +175,12 @@ impl CompletionFilter<'_> {
164175
.map(|clause| {
165176
match self.data {
166177
CompletionRelevanceData::Table(_) => match clause {
167-
WrappingClause::From | WrappingClause::Update => true,
178+
WrappingClause::From => true,
179+
180+
WrappingClause::Update => ctx
181+
.wrapping_node_kind
182+
.as_ref()
183+
.is_none_or(|n| n != &WrappingNode::Assignment),
168184

169185
WrappingClause::RevokeStatement | WrappingClause::GrantStatement => ctx
170186
.history_ends_with(&[

0 commit comments

Comments
 (0)