1
1
use pgt_schema_cache:: ProcKind ;
2
-
3
2
use pgt_treesitter:: context:: { NodeUnderCursor , TreesitterContext , WrappingClause , WrappingNode } ;
4
3
5
4
use super :: CompletionRelevanceData ;
@@ -58,8 +57,7 @@ impl CompletionFilter<'_> {
58
57
| Some ( WrappingClause :: Insert )
59
58
| Some ( WrappingClause :: DropColumn )
60
59
| Some ( WrappingClause :: AlterColumn )
61
- | Some ( WrappingClause :: RenameColumn )
62
- | Some ( WrappingClause :: PolicyCheck ) => {
60
+ | Some ( WrappingClause :: RenameColumn ) => {
63
61
// the literal is probably a column
64
62
}
65
63
_ => return None ,
@@ -123,6 +121,13 @@ impl CompletionFilter<'_> {
123
121
"keyword_table" ,
124
122
] ) ,
125
123
124
+ WrappingClause :: CreatePolicy
125
+ | WrappingClause :: AlterPolicy
126
+ | WrappingClause :: DropPolicy => {
127
+ ctx. matches_ancestor_history ( & [ "object_reference" ] )
128
+ && ctx. before_cursor_matches_kind ( & [ "keyword_on" , "." ] )
129
+ }
130
+
126
131
_ => false ,
127
132
} ,
128
133
@@ -162,8 +167,11 @@ impl CompletionFilter<'_> {
162
167
&& ctx. matches_ancestor_history ( & [ "field" ] ) )
163
168
}
164
169
165
- WrappingClause :: PolicyCheck => {
166
- ctx. before_cursor_matches_kind ( & [ "keyword_and" , "(" ] )
170
+ WrappingClause :: CheckOrUsingClause => {
171
+ ctx. before_cursor_matches_kind ( & [ "(" , "keyword_and" ] )
172
+ || ctx. wrapping_node_kind . as_ref ( ) . is_some_and ( |nk| {
173
+ matches ! ( nk, WrappingNode :: BinaryExpression )
174
+ } )
167
175
}
168
176
169
177
_ => false ,
@@ -176,9 +184,12 @@ impl CompletionFilter<'_> {
176
184
| WrappingClause :: Where
177
185
| WrappingClause :: Join { .. } => true ,
178
186
179
- WrappingClause :: PolicyCheck => {
180
- ctx. before_cursor_matches_kind ( & [ "=" ] )
181
- && matches ! ( f. kind, ProcKind :: Function | ProcKind :: Procedure )
187
+ WrappingClause :: CheckOrUsingClause => {
188
+ !matches ! ( f. kind, ProcKind :: Aggregate )
189
+ && ( ctx. before_cursor_matches_kind ( & [ "(" , "keyword_and" ] )
190
+ || ctx. wrapping_node_kind . as_ref ( ) . is_some_and ( |nk| {
191
+ matches ! ( nk, WrappingNode :: BinaryExpression )
192
+ } ) )
182
193
}
183
194
184
195
_ => false ,
@@ -209,11 +220,21 @@ impl CompletionFilter<'_> {
209
220
&& ctx. before_cursor_matches_kind ( & [ "keyword_into" ] )
210
221
}
211
222
223
+ WrappingClause :: CreatePolicy
224
+ | WrappingClause :: AlterPolicy
225
+ | WrappingClause :: DropPolicy => {
226
+ ctx. before_cursor_matches_kind ( & [ "keyword_on" ] )
227
+ }
228
+
212
229
_ => false ,
213
230
} ,
214
231
215
232
CompletionRelevanceData :: Policy ( _) => {
216
- matches ! ( clause, WrappingClause :: PolicyName )
233
+ matches ! (
234
+ clause,
235
+ // not CREATE – there can't be existing policies.
236
+ WrappingClause :: AlterPolicy | WrappingClause :: DropPolicy
237
+ ) && ctx. before_cursor_matches_kind ( & [ "keyword_policy" , "keyword_exists" ] )
217
238
}
218
239
219
240
CompletionRelevanceData :: Role ( _) => match clause {
@@ -224,6 +245,11 @@ impl CompletionFilter<'_> {
224
245
WrappingClause :: SetStatement => ctx
225
246
. before_cursor_matches_kind ( & [ "keyword_role" , "keyword_authorization" ] ) ,
226
247
248
+ WrappingClause :: AlterPolicy | WrappingClause :: CreatePolicy => {
249
+ ctx. before_cursor_matches_kind ( & [ "keyword_to" ] )
250
+ && ctx. matches_ancestor_history ( & [ "policy_to_role" ] )
251
+ }
252
+
227
253
_ => false ,
228
254
} ,
229
255
}
0 commit comments