Skip to content

Commit e832177

Browse files
just readied again
1 parent 60fde76 commit e832177

File tree

9 files changed

+141
-35
lines changed

9 files changed

+141
-35
lines changed

crates/pgt_hover/src/hoverables/column.rs

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

88
impl ToHoverMarkdown for pgt_schema_cache::Column {
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!(
1115
writer,
1216
"`{}.{}.{}`",
1317
self.schema_name, self.table_name, self.name
1418
)
1519
}
1620

17-
fn hover_body<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
21+
fn hover_body<W: Write>(
22+
&self,
23+
writer: &mut W,
24+
_schema_cache: &SchemaCache,
25+
) -> Result<bool, std::fmt::Error> {
1826
if let Some(comment) = &self.comment {
1927
write!(writer, "Comment: '{}'", comment)?;
2028
writeln!(writer)?;
@@ -46,7 +54,11 @@ impl ToHoverMarkdown for pgt_schema_cache::Column {
4654
Ok(true)
4755
}
4856

49-
fn hover_footer<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
57+
fn hover_footer<W: Write>(
58+
&self,
59+
writer: &mut W,
60+
_schema_cache: &SchemaCache,
61+
) -> Result<bool, std::fmt::Error> {
5062
if let Some(default) = &self.default_expr {
5163
writeln!(writer)?;
5264
write!(writer, "Default: {}", default)?;

crates/pgt_hover/src/hoverables/function.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ impl ToHoverMarkdown for Function {
1010
"sql"
1111
}
1212

13-
fn hover_headline<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<(), std::fmt::Error> {
13+
fn hover_headline<W: Write>(
14+
&self,
15+
writer: &mut W,
16+
_schema_cache: &SchemaCache,
17+
) -> Result<(), std::fmt::Error> {
1418
write!(writer, "`{}.{}", self.schema, self.name)?;
1519

1620
if let Some(args) = &self.argument_types {
@@ -28,7 +32,11 @@ impl ToHoverMarkdown for Function {
2832
Ok(())
2933
}
3034

31-
fn hover_body<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
35+
fn hover_body<W: Write>(
36+
&self,
37+
writer: &mut W,
38+
_schema_cache: &SchemaCache,
39+
) -> Result<bool, std::fmt::Error> {
3240
let kind_text = match self.kind {
3341
pgt_schema_cache::ProcKind::Function => "Function",
3442
pgt_schema_cache::ProcKind::Procedure => "Procedure",
@@ -55,7 +63,11 @@ impl ToHoverMarkdown for Function {
5563
Ok(true)
5664
}
5765

58-
fn hover_footer<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
66+
fn hover_footer<W: Write>(
67+
&self,
68+
writer: &mut W,
69+
_schema_cache: &SchemaCache,
70+
) -> Result<bool, std::fmt::Error> {
5971
if let Some(def) = self.definition.as_ref() {
6072
/*
6173
* We don't want to show 250 lines of functions to the user.

crates/pgt_hover/src/hoverables/mod.rs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,70 @@ impl ContextualPriority for Hoverable<'_> {
7272
}
7373

7474
impl ToHoverMarkdown for Hoverable<'_> {
75-
fn hover_headline<W: std::fmt::Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<(), std::fmt::Error> {
75+
fn hover_headline<W: std::fmt::Write>(
76+
&self,
77+
writer: &mut W,
78+
schema_cache: &SchemaCache,
79+
) -> Result<(), std::fmt::Error> {
7680
match self {
77-
Hoverable::Table(table) => ToHoverMarkdown::hover_headline(*table, writer, schema_cache),
78-
Hoverable::Column(column) => ToHoverMarkdown::hover_headline(*column, writer, schema_cache),
79-
Hoverable::Function(function) => ToHoverMarkdown::hover_headline(*function, writer, schema_cache),
81+
Hoverable::Table(table) => {
82+
ToHoverMarkdown::hover_headline(*table, writer, schema_cache)
83+
}
84+
Hoverable::Column(column) => {
85+
ToHoverMarkdown::hover_headline(*column, writer, schema_cache)
86+
}
87+
Hoverable::Function(function) => {
88+
ToHoverMarkdown::hover_headline(*function, writer, schema_cache)
89+
}
8090
Hoverable::Role(role) => ToHoverMarkdown::hover_headline(*role, writer, schema_cache),
81-
Hoverable::Schema(schema) => ToHoverMarkdown::hover_headline(*schema, writer, schema_cache),
82-
Hoverable::PostgresType(type_) => ToHoverMarkdown::hover_headline(*type_, writer, schema_cache),
91+
Hoverable::Schema(schema) => {
92+
ToHoverMarkdown::hover_headline(*schema, writer, schema_cache)
93+
}
94+
Hoverable::PostgresType(type_) => {
95+
ToHoverMarkdown::hover_headline(*type_, writer, schema_cache)
96+
}
8397
}
8498
}
8599

86-
fn hover_body<W: std::fmt::Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
100+
fn hover_body<W: std::fmt::Write>(
101+
&self,
102+
writer: &mut W,
103+
schema_cache: &SchemaCache,
104+
) -> Result<bool, std::fmt::Error> {
87105
match self {
88106
Hoverable::Table(table) => ToHoverMarkdown::hover_body(*table, writer, schema_cache),
89107
Hoverable::Column(column) => ToHoverMarkdown::hover_body(*column, writer, schema_cache),
90-
Hoverable::Function(function) => ToHoverMarkdown::hover_body(*function, writer, schema_cache),
108+
Hoverable::Function(function) => {
109+
ToHoverMarkdown::hover_body(*function, writer, schema_cache)
110+
}
91111
Hoverable::Role(role) => ToHoverMarkdown::hover_body(*role, writer, schema_cache),
92112
Hoverable::Schema(schema) => ToHoverMarkdown::hover_body(*schema, writer, schema_cache),
93-
Hoverable::PostgresType(type_) => ToHoverMarkdown::hover_body(*type_, writer, schema_cache),
113+
Hoverable::PostgresType(type_) => {
114+
ToHoverMarkdown::hover_body(*type_, writer, schema_cache)
115+
}
94116
}
95117
}
96118

97-
fn hover_footer<W: std::fmt::Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
119+
fn hover_footer<W: std::fmt::Write>(
120+
&self,
121+
writer: &mut W,
122+
schema_cache: &SchemaCache,
123+
) -> Result<bool, std::fmt::Error> {
98124
match self {
99125
Hoverable::Table(table) => ToHoverMarkdown::hover_footer(*table, writer, schema_cache),
100-
Hoverable::Column(column) => ToHoverMarkdown::hover_footer(*column, writer, schema_cache),
101-
Hoverable::Function(function) => ToHoverMarkdown::hover_footer(*function, writer, schema_cache),
126+
Hoverable::Column(column) => {
127+
ToHoverMarkdown::hover_footer(*column, writer, schema_cache)
128+
}
129+
Hoverable::Function(function) => {
130+
ToHoverMarkdown::hover_footer(*function, writer, schema_cache)
131+
}
102132
Hoverable::Role(role) => ToHoverMarkdown::hover_footer(*role, writer, schema_cache),
103-
Hoverable::Schema(schema) => ToHoverMarkdown::hover_footer(*schema, writer, schema_cache),
104-
Hoverable::PostgresType(type_) => ToHoverMarkdown::hover_footer(*type_, writer, schema_cache),
133+
Hoverable::Schema(schema) => {
134+
ToHoverMarkdown::hover_footer(*schema, writer, schema_cache)
135+
}
136+
Hoverable::PostgresType(type_) => {
137+
ToHoverMarkdown::hover_footer(*type_, writer, schema_cache)
138+
}
105139
}
106140
}
107141

crates/pgt_hover/src/hoverables/role.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ use pgt_treesitter::TreesitterContext;
66
use crate::{contextual_priority::ContextualPriority, to_markdown::ToHoverMarkdown};
77

88
impl ToHoverMarkdown for pgt_schema_cache::Role {
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, "`{}`", self.name)?;
1115

1216
Ok(())
1317
}
1418

15-
fn hover_body<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
19+
fn hover_body<W: Write>(
20+
&self,
21+
writer: &mut W,
22+
_schema_cache: &SchemaCache,
23+
) -> Result<bool, std::fmt::Error> {
1624
if let Some(comm) = self.comment.as_ref() {
1725
write!(writer, "Comment: '{}'", comm)?;
1826
writeln!(writer)?;
@@ -81,7 +89,11 @@ impl ToHoverMarkdown for pgt_schema_cache::Role {
8189
Ok(true)
8290
}
8391

84-
fn hover_footer<W: Write>(&self, _writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
92+
fn hover_footer<W: Write>(
93+
&self,
94+
_writer: &mut W,
95+
_schema_cache: &SchemaCache,
96+
) -> Result<bool, std::fmt::Error> {
8597
Ok(false)
8698
}
8799
}

crates/pgt_hover/src/hoverables/schema.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ use pgt_treesitter::TreesitterContext;
66
use crate::{contextual_priority::ContextualPriority, to_markdown::ToHoverMarkdown};
77

88
impl ToHoverMarkdown for Schema {
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, "`{}` - owned by {}", self.name, self.owner)?;
1115

1216
Ok(())
1317
}
1418

15-
fn hover_body<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
19+
fn hover_body<W: Write>(
20+
&self,
21+
writer: &mut W,
22+
_schema_cache: &SchemaCache,
23+
) -> Result<bool, std::fmt::Error> {
1624
if let Some(comment) = &self.comment {
1725
write!(writer, "Comment: '{}'", comment)?;
1826
writeln!(writer)?;
@@ -46,7 +54,11 @@ impl ToHoverMarkdown for Schema {
4654
Ok(true)
4755
}
4856

49-
fn hover_footer<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
57+
fn hover_footer<W: Write>(
58+
&self,
59+
writer: &mut W,
60+
_schema_cache: &SchemaCache,
61+
) -> Result<bool, std::fmt::Error> {
5062
writeln!(writer)?;
5163
write!(
5264
writer,

crates/pgt_hover/src/hoverables/table.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use pgt_treesitter::TreesitterContext;
77
use crate::{contextual_priority::ContextualPriority, to_markdown::ToHoverMarkdown};
88

99
impl ToHoverMarkdown for Table {
10-
fn hover_headline<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<(), std::fmt::Error> {
10+
fn hover_headline<W: Write>(
11+
&self,
12+
writer: &mut W,
13+
_schema_cache: &SchemaCache,
14+
) -> Result<(), std::fmt::Error> {
1115
write!(writer, "`{}.{}`", self.schema, self.name)?;
1216

1317
let table_kind = match self.table_kind {
@@ -30,7 +34,11 @@ impl ToHoverMarkdown for Table {
3034
Ok(())
3135
}
3236

33-
fn hover_body<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
37+
fn hover_body<W: Write>(
38+
&self,
39+
writer: &mut W,
40+
_schema_cache: &SchemaCache,
41+
) -> Result<bool, std::fmt::Error> {
3442
if let Some(comment) = &self.comment {
3543
write!(writer, "Comment: '{}'", comment)?;
3644
writeln!(writer)?;
@@ -40,7 +48,11 @@ impl ToHoverMarkdown for Table {
4048
}
4149
}
4250

43-
fn hover_footer<W: Write>(&self, writer: &mut W, _schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error> {
51+
fn hover_footer<W: Write>(
52+
&self,
53+
writer: &mut W,
54+
_schema_cache: &SchemaCache,
55+
) -> Result<bool, std::fmt::Error> {
4456
writeln!(writer)?;
4557
write!(
4658
writer,

crates/pgt_hover/src/hovered_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ impl HoveredNode {
111111
// make sure we're not checking against an alias
112112
&& ctx
113113
.get_mentioned_table_for_alias(
114-
node_content.replace('(', "").replace(')', "").as_str(),
114+
node_content.replace(['(', ')'], "").as_str(),
115115
)
116116
.is_none() =>
117117
{
118-
let sanitized = node_content.replace('(', "").replace(')', "");
118+
let sanitized = node_content.replace(['(', ')'], "");
119119
if let Some(schema) = ctx.schema_or_alias_name.as_ref() {
120120
Some(HoveredNode::PostgresType(
121121
NodeIdentification::SchemaAndName((schema.clone(), sanitized)),

crates/pgt_hover/src/to_markdown.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ pub(crate) trait ToHoverMarkdown {
1111
"plain"
1212
}
1313

14-
fn hover_headline<W: Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<(), std::fmt::Error>;
14+
fn hover_headline<W: Write>(
15+
&self,
16+
writer: &mut W,
17+
schema_cache: &SchemaCache,
18+
) -> Result<(), std::fmt::Error>;
1519

16-
fn hover_body<W: Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error>; // returns true if something was written
20+
fn hover_body<W: Write>(
21+
&self,
22+
writer: &mut W,
23+
schema_cache: &SchemaCache,
24+
) -> Result<bool, std::fmt::Error>; // returns true if something was written
1725

18-
fn hover_footer<W: Write>(&self, writer: &mut W, schema_cache: &SchemaCache) -> Result<bool, std::fmt::Error>; // returns true if something was written
26+
fn hover_footer<W: Write>(
27+
&self,
28+
writer: &mut W,
29+
schema_cache: &SchemaCache,
30+
) -> Result<bool, std::fmt::Error>; // returns true if something was written
1931
}
2032

2133
pub(crate) fn format_hover_markdown<T: ToHoverMarkdown>(

crates/pgt_treesitter/src/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ impl<'a> TreesitterContext<'a> {
862862
}
863863
}
864864

865-
return false;
865+
false
866866
}
867867
NodeUnderCursor::CustomNode { .. } => false,
868868
})

0 commit comments

Comments
 (0)