Skip to content

Commit 68e958e

Browse files
fix: do not shower hover info on sql params
1 parent b85c068 commit 68e958e

File tree

7 files changed

+95
-2
lines changed

7 files changed

+95
-2
lines changed

crates/pgt_hover/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ pub struct OnHoverParams<'a> {
2525
position = params.position.to_string()
2626
))]
2727
pub fn on_hover(params: OnHoverParams) -> Vec<String> {
28+
println!("on hover!");
29+
2830
let ctx = pgt_treesitter::context::TreesitterContext::new(TreeSitterContextParams {
2931
position: params.position,
3032
text: params.stmt_sql,
3133
tree: params.ts_tree,
3234
});
3335

36+
println!("ctx {:#?}", ctx);
37+
3438
if let Some(hovered_node) = HoveredNode::get(&ctx) {
3539
let items: Vec<Hoverable> = match hovered_node {
3640
HoveredNode::Table(node_identification) => match node_identification {

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("$-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(":-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("@-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("?-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.
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.

crates/pgt_treesitter_grammar/grammar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,10 +3378,10 @@ module.exports = grammar({
33783378
choice(
33793379
$._identifier,
33803380
$._double_quote_string,
3381-
$._tsql_parameter,
3381+
$._sql_parameter,
33823382
seq("`", $._identifier, "`")
33833383
),
3384-
_tsql_parameter: ($) => seq("@", $._identifier),
3384+
_sql_parameter: (_) => /[:$@?][a-zA-Z_][0-9a-zA-Z_]*/,
33853385
_identifier: (_) => /[a-zA-Z_][0-9a-zA-Z_]*/,
33863386
},
33873387
});

0 commit comments

Comments
 (0)