@@ -17,6 +17,28 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
17
17
. is_some_and ( |c| c. starts_with ( '"' ) && c. ends_with ( '"' ) && c != "\" \" " ) ;
18
18
19
19
for pol in available_policies {
20
+ let completion_text = if surrounded_by_quotes {
21
+ // If we're within quotes, we want to change the content
22
+ // *within* the quotes.
23
+ // If we attempt to replace outside the quotes, the VSCode
24
+ // client won't show the suggestions.
25
+ let range = get_range_to_replace ( ctx) ;
26
+ Some ( CompletionText {
27
+ text : pol. name . clone ( ) ,
28
+ range : TextRange :: new (
29
+ range. start ( ) + TextSize :: new ( 1 ) ,
30
+ range. end ( ) - TextSize :: new ( 1 ) ,
31
+ ) ,
32
+ } )
33
+ } else {
34
+ // If we aren't within quotes, we want to complete the
35
+ // full policy including quotation marks.
36
+ Some ( CompletionText {
37
+ text : format ! ( "\" {}\" " , pol. name) ,
38
+ range : get_range_to_replace ( ctx) ,
39
+ } )
40
+ } ;
41
+
20
42
let relevance = CompletionRelevanceData :: Policy ( pol) ;
21
43
22
44
let item = PossibleCompletionItem {
@@ -25,23 +47,7 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
25
47
filter : CompletionFilter :: from ( relevance) ,
26
48
description : format ! ( "{}" , pol. table_name) ,
27
49
kind : CompletionItemKind :: Policy ,
28
- completion_text : if !surrounded_by_quotes {
29
- Some ( CompletionText {
30
- text : format ! ( "\" {}\" " , pol. name) ,
31
- range : get_range_to_replace ( ctx) ,
32
- } )
33
- } else {
34
- let range = get_range_to_replace ( ctx) ;
35
- Some ( CompletionText {
36
- text : pol. name . clone ( ) ,
37
-
38
- // trim the quotes.
39
- range : TextRange :: new (
40
- range. start ( ) + TextSize :: new ( 1 ) ,
41
- range. end ( ) - TextSize :: new ( 1 ) ,
42
- ) ,
43
- } )
44
- } ,
50
+ completion_text,
45
51
} ;
46
52
47
53
builder. add_item ( item) ;
@@ -50,13 +56,7 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
50
56
51
57
#[ cfg( test) ]
52
58
mod tests {
53
- use crate :: {
54
- complete,
55
- test_helper:: {
56
- CURSOR_POS , CompletionAssertion , assert_complete_results, get_test_params,
57
- test_against_connection_string,
58
- } ,
59
- } ;
59
+ use crate :: test_helper:: { CURSOR_POS , CompletionAssertion , assert_complete_results} ;
60
60
61
61
#[ tokio:: test]
62
62
async fn completes_within_quotation_marks ( ) {
@@ -100,19 +100,4 @@ mod tests {
100
100
)
101
101
. await ;
102
102
}
103
-
104
- #[ tokio:: test]
105
- async fn sb_test ( ) {
106
- let input = format ! ( "alter policy \" u{}\" on public.fcm_tokens;" , CURSOR_POS ) ;
107
-
108
- let ( tree, cache) = test_against_connection_string (
109
- "postgresql://postgres:[email protected] :54322/postgres" ,
110
- input. as_str ( ) . into ( ) ,
111
- )
112
- . await ;
113
-
114
- let result = complete ( get_test_params ( & tree, & cache, input. as_str ( ) . into ( ) ) ) ;
115
-
116
- println ! ( "{:#?}" , result) ;
117
- }
118
103
}
0 commit comments