1- use std:: {
2- collections:: { HashMap , HashSet } ,
3- hash:: Hash ,
4- ops:: Range ,
5- } ;
1+ use std:: collections:: { HashMap , HashSet } ;
62
73use pg_schema_cache:: SchemaCache ;
84use pg_treesitter_queries:: {
@@ -62,7 +58,7 @@ pub(crate) struct CompletionContext<'a> {
6258 pub schema_name : Option < String > ,
6359 pub wrapping_clause_type : Option < ClauseType > ,
6460 pub is_invocation : bool ,
65- pub wrapping_statement_range : Option < Range < usize > > ,
61+ pub wrapping_statement_range : Option < tree_sitter :: Range > ,
6662
6763 pub mentioned_relations : HashMap < Option < String > , HashSet < String > > ,
6864}
@@ -74,7 +70,6 @@ impl<'a> CompletionContext<'a> {
7470 text : & params. text ,
7571 schema_cache : params. schema ,
7672 position : usize:: from ( params. position ) ,
77-
7873 ts_node : None ,
7974 schema_name : None ,
8075 wrapping_clause_type : None ,
@@ -86,6 +81,8 @@ impl<'a> CompletionContext<'a> {
8681 ctx. gather_tree_context ( ) ;
8782 ctx. gather_info_from_ts_queries ( ) ;
8883
84+ dbg ! ( ctx. wrapping_statement_range) ;
85+
8986 ctx
9087 }
9188
@@ -98,6 +95,8 @@ impl<'a> CompletionContext<'a> {
9895 let stmt_range = self . wrapping_statement_range . as_ref ( ) ;
9996 let sql = self . text ;
10097
98+ dbg ! ( sql) ;
99+
101100 let mut executor = TreeSitterQueriesExecutor :: new ( tree. root_node ( ) , self . text ) ;
102101
103102 executor. add_query_results :: < queries:: RelationMatch > ( ) ;
@@ -174,9 +173,9 @@ impl<'a> CompletionContext<'a> {
174173 }
175174
176175 match previous_node. kind ( ) {
177- "statement" => {
176+ "statement" | "subquery" => {
178177 self . wrapping_clause_type = current_node. kind ( ) . try_into ( ) . ok ( ) ;
179- self . wrapping_statement_range = Some ( previous_node. byte_range ( ) ) ;
178+ self . wrapping_statement_range = Some ( previous_node. range ( ) ) ;
180179 }
181180 "invocation" => self . is_invocation = true ,
182181
@@ -263,7 +262,7 @@ mod tests {
263262 ] ;
264263
265264 for ( query, expected_clause) in test_cases {
266- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
265+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
267266
268267 let tree = get_tree ( text. as_str ( ) ) ;
269268
@@ -296,7 +295,7 @@ mod tests {
296295 ] ;
297296
298297 for ( query, expected_schema) in test_cases {
299- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
298+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
300299
301300 let tree = get_tree ( text. as_str ( ) ) ;
302301 let params = crate :: CompletionParams {
@@ -330,7 +329,7 @@ mod tests {
330329 ] ;
331330
332331 for ( query, is_invocation) in test_cases {
333- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
332+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
334333
335334 let tree = get_tree ( text. as_str ( ) ) ;
336335 let params = crate :: CompletionParams {
@@ -354,7 +353,7 @@ mod tests {
354353 ] ;
355354
356355 for query in cases {
357- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
356+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
358357
359358 let tree = get_tree ( text. as_str ( ) ) ;
360359
@@ -382,7 +381,7 @@ mod tests {
382381 fn does_not_fail_on_trailing_whitespace ( ) {
383382 let query = format ! ( "select * from {}" , CURSOR_POS ) ;
384383
385- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
384+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
386385
387386 let tree = get_tree ( text. as_str ( ) ) ;
388387
@@ -408,7 +407,7 @@ mod tests {
408407 fn does_not_fail_with_empty_statements ( ) {
409408 let query = format ! ( "{}" , CURSOR_POS ) ;
410409
411- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
410+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
412411
413412 let tree = get_tree ( text. as_str ( ) ) ;
414413
@@ -433,7 +432,7 @@ mod tests {
433432 // is selecting a certain column name, such as `frozen_account`.
434433 let query = format ! ( "select * fro{}" , CURSOR_POS ) ;
435434
436- let ( position, text) = get_text_and_position ( query. as_str ( ) ) ;
435+ let ( position, text) = get_text_and_position ( query. as_str ( ) . into ( ) ) ;
437436
438437 let tree = get_tree ( text. as_str ( ) ) ;
439438
0 commit comments