@@ -173,47 +173,46 @@ impl<'a> CompletionContext<'a> {
173
173
// policy handling is important to Supabase, but they are a PostgreSQL specific extension,
174
174
// so the tree_sitter_sql language does not support it.
175
175
// We infer the context manually.
176
- if params. text . to_lowercase ( ) . starts_with ( "create policy" )
177
- || params. text . to_lowercase ( ) . starts_with ( "alter policy" )
178
- || params. text . to_lowercase ( ) . starts_with ( "drop policy" )
179
- {
180
- let policy_context = PolicyParser :: get_context ( & ctx. text , ctx. position ) ;
181
-
182
- ctx. node_under_cursor = Some ( NodeUnderCursor :: CustomNode {
183
- text : policy_context. node_text . into ( ) ,
184
- range : policy_context. node_range ,
185
- kind : policy_context. node_kind . clone ( ) ,
186
- } ) ;
187
-
188
- if policy_context. node_kind == "policy_table" {
189
- ctx. schema_or_alias_name = policy_context. schema_name . clone ( ) ;
190
- }
191
-
192
- if policy_context. table_name . is_some ( ) {
193
- let mut new = HashSet :: new ( ) ;
194
- new. insert ( policy_context. table_name . unwrap ( ) ) ;
195
- ctx. mentioned_relations
196
- . insert ( policy_context. schema_name , new) ;
197
- }
198
-
199
- ctx. wrapping_clause_type = match policy_context. node_kind . as_str ( ) {
200
- "policy_name" if policy_context. statement_kind != PolicyStmtKind :: Create => {
201
- Some ( WrappingClause :: PolicyName )
202
- }
203
- "policy_role" => Some ( WrappingClause :: ToRoleAssignment ) ,
204
- "policy_table" => Some ( WrappingClause :: From ) ,
205
- _ => None ,
206
- } ;
176
+ if PolicyParser :: looks_like_policy_stmt ( & params. text ) {
177
+ ctx. gather_policy_context ( ) ;
207
178
} else {
208
179
ctx. gather_tree_context ( ) ;
209
180
ctx. gather_info_from_ts_queries ( ) ;
210
181
}
211
182
212
- tracing:: warn!( "{:#?}" , ctx. get_node_under_cursor_content( ) ) ;
213
-
214
183
ctx
215
184
}
216
185
186
+ fn gather_policy_context ( & mut self ) {
187
+ let policy_context = PolicyParser :: get_context ( & self . text , self . position ) ;
188
+
189
+ self . node_under_cursor = Some ( NodeUnderCursor :: CustomNode {
190
+ text : policy_context. node_text . into ( ) ,
191
+ range : policy_context. node_range ,
192
+ kind : policy_context. node_kind . clone ( ) ,
193
+ } ) ;
194
+
195
+ if policy_context. node_kind == "policy_table" {
196
+ self . schema_or_alias_name = policy_context. schema_name . clone ( ) ;
197
+ }
198
+
199
+ if policy_context. table_name . is_some ( ) {
200
+ let mut new = HashSet :: new ( ) ;
201
+ new. insert ( policy_context. table_name . unwrap ( ) ) ;
202
+ self . mentioned_relations
203
+ . insert ( policy_context. schema_name , new) ;
204
+ }
205
+
206
+ self . wrapping_clause_type = match policy_context. node_kind . as_str ( ) {
207
+ "policy_name" if policy_context. statement_kind != PolicyStmtKind :: Create => {
208
+ Some ( WrappingClause :: PolicyName )
209
+ }
210
+ "policy_role" => Some ( WrappingClause :: ToRoleAssignment ) ,
211
+ "policy_table" => Some ( WrappingClause :: From ) ,
212
+ _ => None ,
213
+ } ;
214
+ }
215
+
217
216
fn gather_info_from_ts_queries ( & mut self ) {
218
217
let stmt_range = self . wrapping_statement_range . as_ref ( ) ;
219
218
let sql = self . text ;
0 commit comments