Skip to content

Commit a3df7b7

Browse files
Merge branch 'fix/eof-handling' of https://github.com/supabase-community/postgres_lsp into fix/eof-handling
2 parents 1b40f62 + dec0555 commit a3df7b7

26 files changed

+513
-162
lines changed

.sqlx/query-b0163e58e9c646e3af524174081b74ab7e7938e9516ea21513265c49d304b6ea.json renamed to .sqlx/query-1cc58ddce2b52b5d6f6519cde339f258bce50342c2d5cce036dba4f9062cf811.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 10 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ biome_js_syntax = "0.5.7"
2323
biome_rowan = "0.5.7"
2424
biome_string_case = "0.5.8"
2525
bpaf = { version = "0.9.15", features = ["derive"] }
26+
criterion = "0.5"
2627
crossbeam = "0.8.4"
2728
enumflags2 = "0.7.11"
2829
ignore = "0.4.23"

crates/pgt_completions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sqlx.workspace = true
3131
tokio = { version = "1.41.1", features = ["full"] }
3232

3333
[dev-dependencies]
34-
criterion = "0.5.1"
34+
criterion.workspace = true
3535
pgt_test_utils.workspace = true
3636

3737
[lib]

crates/pgt_hover/src/hovered_node.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl HoveredNode {
2424
pub(crate) fn get(ctx: &pgt_treesitter::context::TreesitterContext) -> Option<Self> {
2525
let node_content = ctx.get_node_under_cursor_content()?;
2626

27+
if looks_like_sql_param(node_content.as_str()) {
28+
return None;
29+
}
30+
2731
let under_cursor = ctx.node_under_cursor.as_ref()?;
2832

2933
match under_cursor.kind() {
@@ -114,3 +118,10 @@ impl HoveredNode {
114118
}
115119
}
116120
}
121+
122+
fn looks_like_sql_param(content: &str) -> bool {
123+
(content.starts_with("$") && !content.starts_with("$$"))
124+
|| (content.starts_with(":") && !content.starts_with("::"))
125+
|| (content.starts_with("@"))
126+
|| content.starts_with("?")
127+
}

crates/pgt_hover/tests/hover_integration_tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,44 @@ async fn test_grant_table_hover(test_db: PgPool) {
518518

519519
test_hover_at_cursor("grant_select", query, None, &test_db).await;
520520
}
521+
522+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
523+
async fn no_hover_results_over_params(test_db: PgPool) {
524+
let setup = r#"
525+
create table users (
526+
id serial primary key,
527+
name text
528+
);
529+
"#;
530+
531+
test_db.execute(setup).await.unwrap();
532+
533+
{
534+
let query = format!(
535+
"select * from users where name = $n{}ame;",
536+
QueryWithCursorPosition::cursor_marker()
537+
);
538+
test_hover_at_cursor("dollar-param", query, None, &test_db).await;
539+
}
540+
{
541+
let query = format!(
542+
"select * from users where name = :n{}ame;",
543+
QueryWithCursorPosition::cursor_marker()
544+
);
545+
test_hover_at_cursor("colon-param", query, None, &test_db).await;
546+
}
547+
{
548+
let query = format!(
549+
"select * from users where name = @n{}ame;",
550+
QueryWithCursorPosition::cursor_marker()
551+
);
552+
test_hover_at_cursor("at-param", query, None, &test_db).await;
553+
}
554+
{
555+
let query = format!(
556+
"select * from users where name = ?n{}ame;",
557+
QueryWithCursorPosition::cursor_marker()
558+
);
559+
test_hover_at_cursor("questionmark-param", query, None, &test_db).await;
560+
}
561+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/pgt_hover/tests/hover_integration_tests.rs
3+
expression: snapshot
4+
---
5+
# Input
6+
```sql
7+
select * from users where name = @name;
8+
↑ hovered here
9+
```
10+
11+
# Hover Results
12+
No hover information found.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/pgt_hover/tests/hover_integration_tests.rs
3+
expression: snapshot
4+
---
5+
# Input
6+
```sql
7+
select * from users where name = :name;
8+
↑ hovered here
9+
```
10+
11+
# Hover Results
12+
No hover information found.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/pgt_hover/tests/hover_integration_tests.rs
3+
expression: snapshot
4+
---
5+
# Input
6+
```sql
7+
select * from users where name = $name;
8+
↑ hovered here
9+
```
10+
11+
# Hover Results
12+
No hover information found.

0 commit comments

Comments
 (0)