Skip to content

Commit 341a0d6

Browse files
ok
1 parent 8fcf50e commit 341a0d6

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

crates/pgt_hover/src/hoverables/postgres_type.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ use pgt_treesitter::TreesitterContext;
66
use crate::{contextual_priority::ContextualPriority, to_markdown::ToHoverMarkdown};
77

88
impl ToHoverMarkdown for PostgresType {
9-
fn hover_headline<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<(), std::fmt::Error> {
9+
fn hover_headline<W: Write>(
10+
&self,
11+
writer: &mut W,
12+
_schema_cache: &SchemaCache,
13+
) -> Result<(), std::fmt::Error> {
1014
write!(writer, "`{}.{}` (Custom Type)", self.schema, self.name)?;
1115
Ok(())
1216
}
1317

14-
fn hover_body<W: Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
18+
fn hover_body<W: Write>(
19+
&self,
20+
writer: &mut W,
21+
schema_cache: &SchemaCache,
22+
) -> Result<bool, std::fmt::Error> {
1523
if let Some(comment) = &self.comment {
1624
write!(writer, "Comment: '{}'", comment)?;
1725
writeln!(writer)?;
@@ -26,7 +34,13 @@ impl ToHoverMarkdown for PostgresType {
2634
write!(writer, "- {}", attribute.name)?;
2735

2836
if let Some(type_info) = schema_cache.find_type_by_id(attribute.type_id) {
29-
write!(writer, ": {}.{}", type_info.schema, type_info.name)?;
37+
write!(writer, ": ")?;
38+
39+
if type_info.schema != "pg_catalog" {
40+
write!(writer, "{}.", type_info.schema)?;
41+
}
42+
43+
write!(writer, "{}", type_info.name)?;
3044
} else {
3145
write!(writer, " (type_id: {})", attribute.type_id)?;
3246
}
@@ -52,7 +66,11 @@ impl ToHoverMarkdown for PostgresType {
5266
Ok(true)
5367
}
5468

55-
fn hover_footer<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
69+
fn hover_footer<W: Write>(
70+
&self,
71+
writer: &mut W,
72+
_schema_cache: &SchemaCache,
73+
) -> Result<bool, std::fmt::Error> {
5674
writeln!(writer)?;
5775
Ok(true)
5876
}

crates/pgt_hover/tests/hover_integration_tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,21 @@ 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 hover_on_types(test_db: PgPool) {
524+
let setup = r#"create type compfoo as (f1 int, f2 text);"#;
525+
526+
let query = format!(
527+
"create function getfoo() returns setof comp{}foo as $$ select fooid, fooname from foo $$ language sql;",
528+
QueryWithCursorPosition::cursor_marker()
529+
);
530+
531+
test_hover_at_cursor(
532+
"hover_custom_type_with_properties",
533+
query,
534+
Some(setup),
535+
&test_db,
536+
)
537+
.await;
538+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: crates/pgt_hover/tests/hover_integration_tests.rs
3+
expression: snapshot
4+
---
5+
# Input
6+
```sql
7+
create function getfoo() returns setof compfoo as $$ select fooid, fooname from foo $$ language sql;
8+
↑ hovered here
9+
```
10+
11+
# Hover Results
12+
### `public.compfoo` (Custom Type)
13+
```plain
14+
Attributes:
15+
- f1: int4
16+
- f2: text
17+
18+
19+
```
20+
---
21+
```plain
22+
23+
24+
```

0 commit comments

Comments
 (0)