11use pgls_treesitter:: WrappingClause ;
22
3- #[ derive( Debug ) ]
4- pub ( crate ) enum NodeIdentification {
5- Name ( String ) ,
6- SchemaAndName ( ( String , String ) ) ,
7- #[ allow( unused) ]
8- SchemaAndTableAndName ( ( String , String , String ) ) ,
9- }
3+ type NodeIdentification = ( Option < String > , String ) ;
104
115#[ allow( unused) ]
126#[ derive( Debug ) ]
137pub ( crate ) enum HoveredNode {
14- Schema ( NodeIdentification ) ,
8+ Schema ( String ) ,
159 Table ( NodeIdentification ) ,
1610 Function ( NodeIdentification ) ,
17- Column ( NodeIdentification ) ,
11+ Column ( ( Option < String > , Option < String > , String ) ) ,
1812 Policy ( NodeIdentification ) ,
1913 Trigger ( NodeIdentification ) ,
20- Role ( NodeIdentification ) ,
14+ Role ( String ) ,
2115 PostgresType ( NodeIdentification ) ,
2216}
2317
@@ -39,17 +33,13 @@ impl HoveredNode {
3933 {
4034 let num_sibs = ctx. num_siblings ( ) ;
4135 if ctx. node_under_cursor_is_nth_child ( 1 ) && num_sibs > 0 {
42- return Some ( HoveredNode :: Schema ( NodeIdentification :: Name ( node_content) ) ) ;
36+ return Some ( HoveredNode :: Schema ( node_content) ) ;
4337 }
4438
45- if let Some ( schema) = ctx. schema_or_alias_name . as_ref ( ) {
46- Some ( HoveredNode :: Table ( NodeIdentification :: SchemaAndName ( (
47- schema. clone ( ) ,
48- node_content,
49- ) ) ) )
50- } else {
51- Some ( HoveredNode :: Table ( NodeIdentification :: Name ( node_content) ) )
52- }
39+ Some ( HoveredNode :: Table ( (
40+ ctx. schema_or_alias_name . clone ( ) ,
41+ node_content,
42+ ) ) )
5343 }
5444
5545 "any_identifier"
@@ -63,40 +53,25 @@ impl HoveredNode {
6353 )
6454 } ) =>
6555 {
66- if let Some ( schema) = ctx. schema_or_alias_name . as_ref ( ) {
67- Some ( HoveredNode :: Table ( NodeIdentification :: SchemaAndName ( (
68- schema. clone ( ) ,
69- node_content,
70- ) ) ) )
71- } else {
72- Some ( HoveredNode :: Table ( NodeIdentification :: Name ( node_content) ) )
73- }
56+ Some ( HoveredNode :: Table ( (
57+ ctx. schema_or_alias_name . clone ( ) ,
58+ node_content,
59+ ) ) )
7460 }
7561
76- "column_identifier" => {
77- if let Some ( table_or_alias) = ctx. schema_or_alias_name . as_ref ( ) {
78- Some ( HoveredNode :: Column ( NodeIdentification :: SchemaAndName ( (
79- table_or_alias. clone ( ) ,
80- node_content,
81- ) ) ) )
82- } else {
83- Some ( HoveredNode :: Column ( NodeIdentification :: Name ( node_content) ) )
84- }
85- }
62+ "column_identifier" => Some ( HoveredNode :: Column ( (
63+ None ,
64+ ctx. schema_or_alias_name . clone ( ) ,
65+ node_content,
66+ ) ) ) ,
8667
8768 "any_identifier"
8869 if ctx. matches_ancestor_history ( & [ "invocation" , "object_reference" ] ) =>
8970 {
90- if let Some ( schema) = ctx. schema_or_alias_name . as_ref ( ) {
91- Some ( HoveredNode :: Function ( NodeIdentification :: SchemaAndName ( (
92- schema. clone ( ) ,
93- node_content,
94- ) ) ) )
95- } else {
96- Some ( HoveredNode :: Function ( NodeIdentification :: Name (
97- node_content,
98- ) ) )
99- }
71+ Some ( HoveredNode :: Function ( (
72+ ctx. schema_or_alias_name . clone ( ) ,
73+ node_content,
74+ ) ) )
10075 }
10176
10277 "any_identifier"
@@ -106,19 +81,17 @@ impl HoveredNode {
10681 "role_specification" ,
10782 ] ) || ctx. before_cursor_matches_kind ( & [ "keyword_revoke" ] ) =>
10883 {
109- Some ( HoveredNode :: Role ( NodeIdentification :: Name ( node_content) ) )
110- }
111- "grant_role" | "policy_role" => {
112- Some ( HoveredNode :: Role ( NodeIdentification :: Name ( node_content) ) )
84+ Some ( HoveredNode :: Role ( node_content) )
11385 }
86+ "grant_role" | "policy_role" => Some ( HoveredNode :: Role ( node_content) ) ,
11487
11588 "any_identifier"
11689 if (
11790 // hover over custom type in `create table` or `returns`
11891 ( ctx. matches_ancestor_history ( & [ "type" , "object_reference" ] )
11992 && ctx. node_under_cursor_is_within_field_name ( "custom_type" ) )
12093
121- // hover over type in `select` clause etc…
94+ // hover over type in `select` clause etc…
12295 || ( ctx
12396 . matches_ancestor_history ( & [ "field_qualifier" , "object_reference" ] )
12497 && ctx. before_cursor_matches_kind ( & [ "(" ] ) ) )
@@ -131,32 +104,21 @@ impl HoveredNode {
131104 . is_none ( ) =>
132105 {
133106 let sanitized = node_content. replace ( [ '(' , ')' ] , "" ) ;
134- if let Some ( schema) = ctx. schema_or_alias_name . as_ref ( ) {
135- Some ( HoveredNode :: PostgresType (
136- NodeIdentification :: SchemaAndName ( ( schema. clone ( ) , sanitized) ) ,
137- ) )
138- } else {
139- Some ( HoveredNode :: PostgresType ( NodeIdentification :: Name (
140- sanitized,
141- ) ) )
142- }
107+ Some ( HoveredNode :: PostgresType ( (
108+ ctx. schema_or_alias_name . clone ( ) ,
109+ sanitized,
110+ ) ) )
143111 }
144112
145113 // quoted columns
146114 "literal" if ctx. matches_ancestor_history ( & [ "select_expression" , "term" ] ) => {
147- Some ( HoveredNode :: Column ( NodeIdentification :: Name ( node_content) ) )
115+ Some ( HoveredNode :: Column ( ( None , None , node_content) ) )
148116 }
149117
150- "grant_table" => {
151- if let Some ( schema) = ctx. schema_or_alias_name . as_ref ( ) {
152- Some ( HoveredNode :: Table ( NodeIdentification :: SchemaAndName ( (
153- schema. clone ( ) ,
154- node_content,
155- ) ) ) )
156- } else {
157- Some ( HoveredNode :: Table ( NodeIdentification :: Name ( node_content) ) )
158- }
159- }
118+ "grant_table" => Some ( HoveredNode :: Table ( (
119+ ctx. schema_or_alias_name . clone ( ) ,
120+ node_content,
121+ ) ) ) ,
160122
161123 _ => None ,
162124 }
0 commit comments