From b85c068e5d5a20a6ec494fc76eaef7f7c2c47b1e Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 10 Oct 2025 18:26:34 +0200 Subject: [PATCH 1/4] fixie fixie --- crates/pgt_hover/src/hovered_node.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/pgt_hover/src/hovered_node.rs b/crates/pgt_hover/src/hovered_node.rs index c67cb8d06..7f1b54c88 100644 --- a/crates/pgt_hover/src/hovered_node.rs +++ b/crates/pgt_hover/src/hovered_node.rs @@ -24,6 +24,10 @@ impl HoveredNode { pub(crate) fn get(ctx: &pgt_treesitter::context::TreesitterContext) -> Option { let node_content = ctx.get_node_under_cursor_content()?; + if looks_like_sql_param(node_content.as_str()) { + return None; + } + let under_cursor = ctx.node_under_cursor.as_ref()?; match under_cursor.kind() { @@ -114,3 +118,10 @@ impl HoveredNode { } } } + +fn looks_like_sql_param(content: &str) -> bool { + (content.starts_with("$") && !content.starts_with("$$")) + || (content.starts_with(":") && !content.starts_with("::")) + || (content.starts_with("@")) + || content.starts_with("?") +} From 68e958ec27ad58f6318d7ac2e8708c88cfbabb0b Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 10 Oct 2025 18:47:54 +0200 Subject: [PATCH 2/4] fix: do not shower hover info on sql params --- crates/pgt_hover/src/lib.rs | 4 ++ .../tests/hover_integration_tests.rs | 41 +++++++++++++++++++ crates/pgt_hover/tests/snapshots/$-param.snap | 12 ++++++ crates/pgt_hover/tests/snapshots/:-param.snap | 12 ++++++ crates/pgt_hover/tests/snapshots/?-param.snap | 12 ++++++ crates/pgt_hover/tests/snapshots/@-param.snap | 12 ++++++ crates/pgt_treesitter_grammar/grammar.js | 4 +- 7 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 crates/pgt_hover/tests/snapshots/$-param.snap create mode 100644 crates/pgt_hover/tests/snapshots/:-param.snap create mode 100644 crates/pgt_hover/tests/snapshots/?-param.snap create mode 100644 crates/pgt_hover/tests/snapshots/@-param.snap diff --git a/crates/pgt_hover/src/lib.rs b/crates/pgt_hover/src/lib.rs index b690d7f05..e2fbd560d 100644 --- a/crates/pgt_hover/src/lib.rs +++ b/crates/pgt_hover/src/lib.rs @@ -25,12 +25,16 @@ pub struct OnHoverParams<'a> { position = params.position.to_string() ))] pub fn on_hover(params: OnHoverParams) -> Vec { + println!("on hover!"); + let ctx = pgt_treesitter::context::TreesitterContext::new(TreeSitterContextParams { position: params.position, text: params.stmt_sql, tree: params.ts_tree, }); + println!("ctx {:#?}", ctx); + if let Some(hovered_node) = HoveredNode::get(&ctx) { let items: Vec = match hovered_node { HoveredNode::Table(node_identification) => match node_identification { diff --git a/crates/pgt_hover/tests/hover_integration_tests.rs b/crates/pgt_hover/tests/hover_integration_tests.rs index 58ffdc3e3..fc0c6f330 100644 --- a/crates/pgt_hover/tests/hover_integration_tests.rs +++ b/crates/pgt_hover/tests/hover_integration_tests.rs @@ -518,3 +518,44 @@ async fn test_grant_table_hover(test_db: PgPool) { test_hover_at_cursor("grant_select", query, None, &test_db).await; } + +#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")] +async fn no_hover_results_over_params(test_db: PgPool) { + let setup = r#" + create table users ( + id serial primary key, + name text + ); + "#; + + test_db.execute(setup).await.unwrap(); + + { + let query = format!( + "select * from users where name = $n{}ame;", + QueryWithCursorPosition::cursor_marker() + ); + test_hover_at_cursor("$-param", query, None, &test_db).await; + } + { + let query = format!( + "select * from users where name = :n{}ame;", + QueryWithCursorPosition::cursor_marker() + ); + test_hover_at_cursor(":-param", query, None, &test_db).await; + } + { + let query = format!( + "select * from users where name = @n{}ame;", + QueryWithCursorPosition::cursor_marker() + ); + test_hover_at_cursor("@-param", query, None, &test_db).await; + } + { + let query = format!( + "select * from users where name = ?n{}ame;", + QueryWithCursorPosition::cursor_marker() + ); + test_hover_at_cursor("?-param", query, None, &test_db).await; + } +} diff --git a/crates/pgt_hover/tests/snapshots/$-param.snap b/crates/pgt_hover/tests/snapshots/$-param.snap new file mode 100644 index 000000000..aab4f1c15 --- /dev/null +++ b/crates/pgt_hover/tests/snapshots/$-param.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgt_hover/tests/hover_integration_tests.rs +expression: snapshot +--- +# Input +```sql +select * from users where name = $name; + ↑ hovered here +``` + +# Hover Results +No hover information found. diff --git a/crates/pgt_hover/tests/snapshots/:-param.snap b/crates/pgt_hover/tests/snapshots/:-param.snap new file mode 100644 index 000000000..db9ef7fb1 --- /dev/null +++ b/crates/pgt_hover/tests/snapshots/:-param.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgt_hover/tests/hover_integration_tests.rs +expression: snapshot +--- +# Input +```sql +select * from users where name = :name; + ↑ hovered here +``` + +# Hover Results +No hover information found. diff --git a/crates/pgt_hover/tests/snapshots/?-param.snap b/crates/pgt_hover/tests/snapshots/?-param.snap new file mode 100644 index 000000000..1f69294f6 --- /dev/null +++ b/crates/pgt_hover/tests/snapshots/?-param.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgt_hover/tests/hover_integration_tests.rs +expression: snapshot +--- +# Input +```sql +select * from users where name = ?name; + ↑ hovered here +``` + +# Hover Results +No hover information found. diff --git a/crates/pgt_hover/tests/snapshots/@-param.snap b/crates/pgt_hover/tests/snapshots/@-param.snap new file mode 100644 index 000000000..17f898d6d --- /dev/null +++ b/crates/pgt_hover/tests/snapshots/@-param.snap @@ -0,0 +1,12 @@ +--- +source: crates/pgt_hover/tests/hover_integration_tests.rs +expression: snapshot +--- +# Input +```sql +select * from users where name = @name; + ↑ hovered here +``` + +# Hover Results +No hover information found. diff --git a/crates/pgt_treesitter_grammar/grammar.js b/crates/pgt_treesitter_grammar/grammar.js index 670c33442..6fc29ac95 100644 --- a/crates/pgt_treesitter_grammar/grammar.js +++ b/crates/pgt_treesitter_grammar/grammar.js @@ -3378,10 +3378,10 @@ module.exports = grammar({ choice( $._identifier, $._double_quote_string, - $._tsql_parameter, + $._sql_parameter, seq("`", $._identifier, "`") ), - _tsql_parameter: ($) => seq("@", $._identifier), + _sql_parameter: (_) => /[:$@?][a-zA-Z_][0-9a-zA-Z_]*/, _identifier: (_) => /[a-zA-Z_][0-9a-zA-Z_]*/, }, }); From 308e34f55d48a45dc38fd65efeab422a9ae762d2 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 10 Oct 2025 18:51:05 +0200 Subject: [PATCH 3/4] ok ok --- crates/pgt_hover/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/pgt_hover/src/lib.rs b/crates/pgt_hover/src/lib.rs index e2fbd560d..b690d7f05 100644 --- a/crates/pgt_hover/src/lib.rs +++ b/crates/pgt_hover/src/lib.rs @@ -25,16 +25,12 @@ pub struct OnHoverParams<'a> { position = params.position.to_string() ))] pub fn on_hover(params: OnHoverParams) -> Vec { - println!("on hover!"); - let ctx = pgt_treesitter::context::TreesitterContext::new(TreeSitterContextParams { position: params.position, text: params.stmt_sql, tree: params.ts_tree, }); - println!("ctx {:#?}", ctx); - if let Some(hovered_node) = HoveredNode::get(&ctx) { let items: Vec = match hovered_node { HoveredNode::Table(node_identification) => match node_identification { From f8ff42be2dd461dfe8399a3f2a4e9528699094f6 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 10 Oct 2025 18:56:29 +0200 Subject: [PATCH 4/4] those were invalid filenames --- crates/pgt_hover/tests/hover_integration_tests.rs | 8 ++++---- .../tests/snapshots/{@-param.snap => at-param.snap} | 0 .../tests/snapshots/{:-param.snap => colon-param.snap} | 0 .../tests/snapshots/{$-param.snap => dollar-param.snap} | 0 .../snapshots/{?-param.snap => questionmark-param.snap} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename crates/pgt_hover/tests/snapshots/{@-param.snap => at-param.snap} (100%) rename crates/pgt_hover/tests/snapshots/{:-param.snap => colon-param.snap} (100%) rename crates/pgt_hover/tests/snapshots/{$-param.snap => dollar-param.snap} (100%) rename crates/pgt_hover/tests/snapshots/{?-param.snap => questionmark-param.snap} (100%) diff --git a/crates/pgt_hover/tests/hover_integration_tests.rs b/crates/pgt_hover/tests/hover_integration_tests.rs index fc0c6f330..e9c8f0c11 100644 --- a/crates/pgt_hover/tests/hover_integration_tests.rs +++ b/crates/pgt_hover/tests/hover_integration_tests.rs @@ -535,27 +535,27 @@ async fn no_hover_results_over_params(test_db: PgPool) { "select * from users where name = $n{}ame;", QueryWithCursorPosition::cursor_marker() ); - test_hover_at_cursor("$-param", query, None, &test_db).await; + test_hover_at_cursor("dollar-param", query, None, &test_db).await; } { let query = format!( "select * from users where name = :n{}ame;", QueryWithCursorPosition::cursor_marker() ); - test_hover_at_cursor(":-param", query, None, &test_db).await; + test_hover_at_cursor("colon-param", query, None, &test_db).await; } { let query = format!( "select * from users where name = @n{}ame;", QueryWithCursorPosition::cursor_marker() ); - test_hover_at_cursor("@-param", query, None, &test_db).await; + test_hover_at_cursor("at-param", query, None, &test_db).await; } { let query = format!( "select * from users where name = ?n{}ame;", QueryWithCursorPosition::cursor_marker() ); - test_hover_at_cursor("?-param", query, None, &test_db).await; + test_hover_at_cursor("questionmark-param", query, None, &test_db).await; } } diff --git a/crates/pgt_hover/tests/snapshots/@-param.snap b/crates/pgt_hover/tests/snapshots/at-param.snap similarity index 100% rename from crates/pgt_hover/tests/snapshots/@-param.snap rename to crates/pgt_hover/tests/snapshots/at-param.snap diff --git a/crates/pgt_hover/tests/snapshots/:-param.snap b/crates/pgt_hover/tests/snapshots/colon-param.snap similarity index 100% rename from crates/pgt_hover/tests/snapshots/:-param.snap rename to crates/pgt_hover/tests/snapshots/colon-param.snap diff --git a/crates/pgt_hover/tests/snapshots/$-param.snap b/crates/pgt_hover/tests/snapshots/dollar-param.snap similarity index 100% rename from crates/pgt_hover/tests/snapshots/$-param.snap rename to crates/pgt_hover/tests/snapshots/dollar-param.snap diff --git a/crates/pgt_hover/tests/snapshots/?-param.snap b/crates/pgt_hover/tests/snapshots/questionmark-param.snap similarity index 100% rename from crates/pgt_hover/tests/snapshots/?-param.snap rename to crates/pgt_hover/tests/snapshots/questionmark-param.snap